-
Notifications
You must be signed in to change notification settings - Fork 465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sstable: order range keys consistently in colblk and rowblk encodings #4160
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Motivated by test failures on cockroachdb/cockroach#134671 where iterating over a sstable's range keys directly results in nondeterministic ordering dependent on whether columnar blocks are enabled.
Reviewable status: 0 of 4 files reviewed, all discussions resolved (waiting on @itsbilal)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 4 files reviewed, 1 unresolved discussion (waiting on @itsbilal and @jbowens)
internal/keyspan/span.go
line 478 at r1 (raw file):
slices.SortFunc(keys, func(a, b Key) int { // Trailer are ordered in decreasing number order. if v := -cmp.Compare(a.Trailer, b.Trailer); v != 0 {
[nit] can be cmp.Compare(b.Trailer, a.Trailer)
Previously the ordering of range keys within a range key block was a bit muddled and undefined. Before encoding a Span of range keys to the underlying RawWriter, the sstable.Writer type previously sorted the span's keys by suffix. However, the row-based sstable writer always serializes RANGEKEYSETs of a Span first, followed by RANGEKEYUNSETs and then RANGEKEYDELs. Confusingly, the rowblk fragment iterator also sorted keys by trailer when iterating backwards, but not forwards. The columnar RawWriter preserved the order of keys in the span passed to EncodeSpan, and this order was preserved during iteration. This commit adapts the sstable.Writer type to sort a range key Span's keys by trailer and then suffix before encoding. This provides determinism and matches the ordering of keys produced by compactions which sort the keys by trailer. Additionally, the rowblk fragment iterator is updated to always sort the returned keys by trailer.
433b7cb
to
14405a6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TFTR!
Reviewable status: 0 of 4 files reviewed, all discussions resolved (waiting on @itsbilal)
internal/keyspan/span.go
line 478 at r1 (raw file):
Previously, RaduBerinde wrote…
[nit] can be
cmp.Compare(b.Trailer, a.Trailer)
Done
Previously the ordering of range keys within a range key block was a bit muddled and undefined. Before encoding a Span of range keys to the underlying RawWriter, the sstable.Writer type previously sorted the span's keys by suffix. However, the row-based sstable writer always serializes RANGEKEYSETs of a Span first, followed by RANGEKEYUNSETs and then RANGEKEYDELs.
Confusingly, the rowblk fragment iterator also sorted keys by trailer when iterating backwards, but not forwards. The columnar RawWriter preserved the order of keys in the span passed to EncodeSpan, and this order was preserved during iteration.
This commit adapts the sstable.Writer type to sort a range key Span's keys by trailer and then suffix before encoding. This provides determinism and matches the ordering of keys produced by compactions which sort the keys by trailer. Additionally, the rowblk fragment iterator is updated to always sort the returned keys by trailer.