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

internal/rangekey: fix invariant check with onlySets=false #3054

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

itsbilal
Copy link
Contributor

In the invariants build, with onlySets set to false (i.e. in ScanInternal), we would see RangeKeyDels in the coalescer that would sort to the end of the span.Keys when in BySuffixAsc order. This is expected and should not trip up the invariant panic, but it was.

@itsbilal itsbilal requested review from a team and aadityasondhi November 10, 2023 02:18
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@itsbilal
Copy link
Contributor Author

Found with #3044 .

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @aadityasondhi and @itsbilal)


internal/rangekey/coalesce.go line 216 at r1 (raw file):

			}
			// Don't do a comparison with RangeKeyDeletes, as those will always sort
			// to the end and have no prefix.

s/prefix/suffix?

In the invariants build, with onlySets set to false (i.e. in
ScanInternal), we would see RangeKeyDels in the coalescer that
would sort to the end of the span.Keys when in BySuffixAsc order.
This is expected and should not trip up the invariant panic,
but it was.
@itsbilal itsbilal force-pushed the rangekey-coalesce-invariant branch from ceb577b to 586c165 Compare November 10, 2023 15:29
Copy link
Contributor Author

@itsbilal itsbilal left a 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 1 files reviewed, all discussions resolved (waiting on @aadityasondhi)


internal/rangekey/coalesce.go line 216 at r1 (raw file):

Previously, RaduBerinde wrote…

s/prefix/suffix?

Done. Oops!

Copy link
Collaborator

@jbowens jbowens left a 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 1 files reviewed, 1 unresolved discussion (waiting on @aadityasondhi and @itsbilal)


internal/rangekey/coalesce.go line 218 at r1 (raw file):

			// to the end and have no prefix.
			if i > 0 && ((a.Keys[i].Kind() != base.InternalKeyKindRangeKeyDelete && ui.comparer.Compare(a.Keys[i].Suffix, a.Keys[i-1].Suffix) < 0) ||
				(b.Keys[i].Kind() != base.InternalKeyKindRangeKeyDelete && ui.comparer.Compare(b.Keys[i].Suffix, b.Keys[i-1].Suffix) < 0)) {

Shouldn't RangeKeyDeletes have already been removed by UserIteratorConfig.Transform?

@itsbilal
Copy link
Contributor Author

internal/rangekey/coalesce.go line 218 at r1 (raw file):

Previously, jbowens (Jackson Owens) wrote…

Shouldn't RangeKeyDeletes have already been removed by UserIteratorConfig.Transform?

Not if onlySets=false. See the above invariant conditional.

@itsbilal itsbilal dismissed jbowens’s stale review November 10, 2023 15:50

Merging for now. Let me know if something else doesn't make sense.

@itsbilal itsbilal merged commit dfe1b00 into cockroachdb:master Nov 10, 2023
11 checks passed
Copy link
Collaborator

@jbowens jbowens left a 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 1 files reviewed, 1 unresolved discussion


internal/rangekey/coalesce.go line 218 at r1 (raw file):

Previously, itsbilal (Bilal Akhtar) wrote…

Not if onlySets=false. See the above invariant conditional.

I see — can we update the comment at the beginning of ShouldDefragment and above it, and the comment above UserIteratorConfig.Transform?

I believe there's a bug with !onlySets: This function relies on the absence of RangeKeyUnsets and RangeKeyDeletes below (hence the original invariant above): If you have a span a-b:{(#2,RANGEKEYSET,@5)} and a span b-c:{(#2,RANGEKEYUNSET,@5)}, these two spans cannot be defragmented without losing information. If we defragment in the forward direction, we'll replace the second span's unset with a set. We should add a unit test for this case too.

Instead of using UserIteratorConfig.ShouldDefragment during scan internal, I think we should use a custom DefragmentMethod that includes a key kind comparison.

@itsbilal
Copy link
Contributor Author

internal/rangekey/coalesce.go line 218 at r1 (raw file):

Previously, jbowens (Jackson Owens) wrote…

I see — can we update the comment at the beginning of ShouldDefragment and above it, and the comment above UserIteratorConfig.Transform?

I believe there's a bug with !onlySets: This function relies on the absence of RangeKeyUnsets and RangeKeyDeletes below (hence the original invariant above): If you have a span a-b:{(#2,RANGEKEYSET,@5)} and a span b-c:{(#2,RANGEKEYUNSET,@5)}, these two spans cannot be defragmented without losing information. If we defragment in the forward direction, we'll replace the second span's unset with a set. We should add a unit test for this case too.

Instead of using UserIteratorConfig.ShouldDefragment during scan internal, I think we should use a custom DefragmentMethod that includes a key kind comparison.

Good catch, this is problematic even though we haven't run into it yet. Filed #3058 so we get to it asap.

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.

4 participants