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

release-22.2: storage: fix point synthesis activation during reverse scans #91028

Merged

Conversation

erikgrinaker
Copy link
Contributor

Backport:

Please see individual PRs for details.

/cc @cockroachdb/release

Release justification: fixes correctness issue with MVCC range tombstones during reverse scans.

@erikgrinaker erikgrinaker requested a review from jbowens October 31, 2022 21:49
@erikgrinaker erikgrinaker requested a review from a team as a code owner October 31, 2022 21:49
@erikgrinaker erikgrinaker self-assigned this Oct 31, 2022
@blathers-crl
Copy link

blathers-crl bot commented Oct 31, 2022

Thanks for opening a backport.

Please check the backport criteria before merging:

  • Patches should only be created for serious issues or test-only changes.
  • Patches should not break backwards-compatibility.
  • Patches should change as little code as possible.
  • Patches should not change on-disk formats or node communication protocols.
  • Patches should not add new functionality.
  • Patches must not add, edit, or otherwise modify cluster versions; or add version gates.
If some of the basic criteria cannot be satisfied, ensure that the exceptional criteria are satisfied within.
  • There is a high priority need for the functionality that cannot wait until the next release and is difficult to address in another way.
  • The new functionality is additive-only and only runs for clusters which have specifically “opted in” to it (e.g. by a cluster setting).
  • New code is protected by a conditional check that is trivial to verify and ensures that it only runs for opt-in clusters.
  • The PM and TL on the team that owns the changed code have signed off that the change obeys the above rules.

Add a brief release justification to the body of your PR to justify this backport.

Some other things to consider:

  • What did we do to ensure that a user that doesn’t know & care about this backport, has no idea that it happened?
  • Will this work in a cluster of mixed patch versions? Did we test that?
  • If a user upgrades a patch version, uses this feature, and then downgrades, what happens?

@cockroach-teamcity
Copy link
Member

This change is Reviewable

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.

lgtm

@erikgrinaker erikgrinaker force-pushed the backport22.2-90899-90953 branch 2 times, most recently from dbab539 to b93816a Compare November 2, 2022 18:44
This patch fixes a bug where `pointSynthesizingIter` could appear to
have skipped a synthetic point tombstone in the reverse direction when
enabled dynamically by `pebbleMVCCScanner`.

Consider the following case:

```
REAL DATASET          SYNTHETIC DATASET
3       [b3]          3      [b3]
2    a2               2   a2
1    [---)            1   x
     a   b                a   b
```

Recall that `pebbleMVCCScanner` only enables `pointSynthesizingIter`
when it encounters a range key. In the case above, during a reverse
scan, the `[a-b)@1` range key will first become visible to
`pebbleMVCCScanner` when it lands on `a@2`, so it enabled point
synthesis positioned at the `a@2` point key. Notice how the iterator has
now skipped over the synthetic point tombstone `a@1`.

This is particularly problematic when combined with `pebbleMVCCScanner`
peeking, which assumes that following a `iterPeekPrev()` call, an
`iterNext()` call can step the parent iterator forward once to get back
to the original position.  With the above bug, that is no longer true,
as it instead lands on the synthetic point tombstone which was skipped
during reverse iteration. During intent processing for `b@3`, such an
`iterNext()` call is expected to land on the intent's provisional value
at `b@3`, but it instead lands on the intent itself at `b@0`. This in
turn caused a value checksum or decoding failure, where it was expecting
the current key to be `b@3`, but the actual key was `b@0`.

This patch fixes the bug by keeping track of the direction of the
previous positioning operation in `pebbleMVCCScanner`, and then
repositioning the `pointSynthesizingIter` as appropriate during dynamic
activation in the reverse direction. This doesn't have a significant
effect on performance (in particular, the point get path is never in
reverse).

Several alternative approaches were attempted but abandoned:

* Don't synthesize points at a range key's start bound. While compelling
  for a range of reasons (complexity, performance, etc) this has two
  flaws: on a bare range key, the iterator still needs to know which
  direction to skip in, and we also need to know the timestamps of bare
  range keys for `FailOnMoreRecent` handling.

* Only synthesize a single point at a range key's start bound. This
  would solve the problem at hand, but has rather strange semantics.

Longer-term, it may be better to merge range key logic into
`pebbleMVCCScanner` itself -- `pointSynthesizingIter` was intended to
reduce complexity, but it's not clear that the overall complexity is
actually reduced.

Release note: None
@erikgrinaker erikgrinaker force-pushed the backport22.2-90899-90953 branch from b93816a to ffd1485 Compare November 3, 2022 15:56
@erikgrinaker erikgrinaker merged commit 3d34142 into cockroachdb:release-22.2 Nov 3, 2022
@erikgrinaker erikgrinaker deleted the backport22.2-90899-90953 branch December 28, 2022 11:21
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