Skip to content
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

crl-release-24.3: sstable: order range keys consistently in colblk and rowblk encodings #4165

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

jbowens
Copy link
Collaborator

@jbowens jbowens commented Nov 13, 2024

24.3 backport of #4160.


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.

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.
@jbowens jbowens requested a review from a team as a code owner November 13, 2024 19:55
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jbowens jbowens requested a review from RaduBerinde November 13, 2024 21:19
@jbowens jbowens merged commit dddf880 into cockroachdb:crl-release-24.3 Nov 14, 2024
22 checks passed
@jbowens jbowens deleted the 24.3-8e01ef310 branch November 14, 2024 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants