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/keyspan: prohibit NextPrefix at span boundary #3588

Merged
merged 1 commit into from
May 6, 2024

Conversation

jbowens
Copy link
Collaborator

@jbowens jbowens commented May 6, 2024

Previously when the interleaving iterator interleaved a span boundary, the semantics of calling NextPrefix were undefined. Ordinarily NextPrefix guarantees that it advances to a key with a new prefix. The existing interleaving iterator implementation didn't guarantee this when positioned on a span boundary. Guaranteeing it would require otherwise unnecessary key comparisons.

In existing use cases (for range keys, which always begin and end at prefix keys), we never call NextPrefix while positioned at a span boundary. With the planned refactor of #2863, we'll begin to use the interleaving iterator to interleave range deletions which may have bounds within the keys of a prefix. This assertion will ensure we don't unintentionally rely on currently undefined behavior of calling NextPrefix on a span boundary.

Previously when the interleaving iterator interleaved a span boundary, the
semantics of calling NextPrefix were indeterminate. Ordinarily NextPrefix
guarantees that it advances to a key with a new prefix. The existing
interleaving iterator implementation didn't guarantee this when positioned on a
span boundary. Guaranteeing it would require otherwise unnecessary key
comparisons.

In existing use cases (for range keys, which always begin and end at prefix
keys), we never call NextPrefix while positioned at a span boundary. With the
planned refactor of cockroachdb#2863, we'll begin to use the interleaving iterator to
interleave range deletions which may have bounds within the keys of a prefix.
This assertion will ensure we don't unintentionally rely on currently undefined
behavior of calling NextPrefix on a span boundary.
@jbowens jbowens requested a review from a team as a code owner May 6, 2024 14:34
@jbowens jbowens requested a review from sumeerbhola May 6, 2024 14:34
@cockroach-teamcity
Copy link
Member

This change is Reviewable

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.

Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @jbowens and @sumeerbhola)


internal/keyspan/interleaving_iter.go line 504 at r1 (raw file):

		}
	case posKeyspanStart, posKeyspanEnd:
		panic(errors.AssertionFailedf("NextPrefix called while positioned on a span boundary"))

[nit] I think we should do i.err = base.AssertionFailedf() so we still panic in invariants mode but not in production

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 2 files reviewed, 1 unresolved discussion (waiting on @jbowens and @sumeerbhola)

@jbowens
Copy link
Collaborator Author

jbowens commented May 6, 2024

TFTR!

@jbowens jbowens merged commit c58ac88 into cockroachdb:master May 6, 2024
11 checks passed
@jbowens jbowens deleted the interleaving-iter-next-prefix branch May 6, 2024 18:05
@RaduBerinde
Copy link
Member

We hit this panic in TestIteratorErrors: #3592 (comment)

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