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: introduce test-build assertion iterator #97572

Merged
merged 4 commits into from
Feb 27, 2023

Conversation

jbowens
Copy link
Collaborator

@jbowens jbowens commented Feb 23, 2023

Backport #90859, #96685 and #97222 to mangle the buffers returned by Pebble
iterators to ensure MVCC and Cockroach code respects the Pebble iterator memory
lifetimes.

The RangeBounds() and RangeKeys() validity assertions are omitted, since 22.2
allowed these methods to be invoked on an invalid iterator or an iterator
positioned at a point key.

Epic: None
Release note: None
Release justification: Non-production code changes and fix to high-severity MVCC iterator bug.

@blathers-crl
Copy link

blathers-crl bot commented Feb 23, 2023

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

@jbowens jbowens marked this pull request as ready for review February 23, 2023 16:34
@jbowens jbowens requested review from a team as code owners February 23, 2023 16:34
@jbowens jbowens force-pushed the 22.2-mangle branch 2 times, most recently from bfb5442 to 05f7c76 Compare February 23, 2023 19:04
Copy link
Contributor

@erikgrinaker erikgrinaker left a comment

Choose a reason for hiding this comment

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

Thanks for catching this, pointSynthesizingIter changes LGTM. Mind running a quick MVCCGet benchmark to see the impact?

Reviewed 19 of 19 files at r1, 1 of 1 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @jbowens and @RaduBerinde)


pkg/storage/sst.go line 615 at r1 (raw file):

				// Re-retrieve the buffers.
				if extHasRange {
					extRangeKeys = extIter.RangeKeys()

Consider pulling this out to a separate commit for visibility.


pkg/storage/pebbleiter/crdb_test_off.go line 19 at r1 (raw file):

// Iterator redefines *pebble.Iterator.
type Iterator = *pebble.Iterator

Nice trick to avoid dynamic dispatch here.

Backport cockroachdb#90859, cockroachdb#96685 and cockroachdb#97222 to mangle the buffers returned by Pebble
iterators to ensure MVCC and Cockroach code respects the Pebble iterator memory
lifetimes.

The RangeBounds() and RangeKeys() validity assertions are omitted, since 22.2
allowed these methods to be invoked on an invalid iterator or an iterator
positioned at a point key.

Release note: None
Release justification: Non-production code changes
Fix a bug whereby CheckSSTConflicts could seek the engine iterator and seek
back, assuming that the originally returned buffers were still valid. This is
only true if RangeKeyChanged()=false after both seeks.

Backport of part of cockroachdb#97222.

Epic: None
Release note: None
Previously, the spanset.MVCCIterator implementation would retrieve the
contained iterator's UsafeKey() on an invalid iterator in Next, NextKey and
Prev. This retrieval was harmless because it always checked the validity of the
iterator before using it, but recent assertions in test builds prevent this
usage.

Release note: None
Update the point-synthesizing iterator to save range key state even when in
prefix iteration mode. Previously the point-synthesizing iterator avoided
copying the range key state when used within prefix iteration mode. This led to
a bug where an iterator could be moved into an exhausted position, at which the
previous range key buffers are no longer valid.

Release note: None
Copy link
Collaborator Author

@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.

TFTR!

Mind running a quick MVCCGet benchmark to see the impact?

For sure. running them on my gceworker now

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @erikgrinaker and @RaduBerinde)


pkg/storage/sst.go line 615 at r1 (raw file):

Previously, erikgrinaker (Erik Grinaker) wrote…

Consider pulling this out to a separate commit for visibility.

Good call, done.

Copy link
Collaborator Author

@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.

Impact looks not horrible:

name                                                                     old time/op    new time/op    delta
MVCCGet_Pebble/batch=false/versions=1/valueSize=8/numRangeKeys=0-24        6.29µs ± 1%    6.32µs ± 1%    ~     (p=0.310 n=5+5)
MVCCGet_Pebble/batch=false/versions=1/valueSize=8/numRangeKeys=1-24        11.5µs ± 1%    11.7µs ± 1%    ~     (p=0.056 n=5+5)
MVCCGet_Pebble/batch=false/versions=1/valueSize=8/numRangeKeys=100-24       133µs ± 1%     129µs ± 1%  -3.01%  (p=0.008 n=5+5)
MVCCGet_Pebble/batch=false/versions=10/valueSize=8/numRangeKeys=0-24       25.8µs ± 0%    25.7µs ± 1%    ~     (p=0.421 n=5+5)
MVCCGet_Pebble/batch=false/versions=10/valueSize=8/numRangeKeys=1-24       33.5µs ± 2%    34.0µs ± 2%  +1.38%  (p=0.032 n=5+5)
MVCCGet_Pebble/batch=false/versions=10/valueSize=8/numRangeKeys=100-24      115µs ± 1%     115µs ± 1%    ~     (p=0.690 n=5+5)
MVCCGet_Pebble/batch=false/versions=100/valueSize=8/numRangeKeys=0-24       107µs ± 2%     107µs ± 1%    ~     (p=0.421 n=5+5)
MVCCGet_Pebble/batch=false/versions=100/valueSize=8/numRangeKeys=1-24       117µs ± 1%     118µs ± 1%    ~     (p=0.222 n=5+5)
MVCCGet_Pebble/batch=false/versions=100/valueSize=8/numRangeKeys=100-24     209µs ± 4%     208µs ± 1%    ~     (p=1.000 n=5+5)
MVCCGet_Pebble/batch=true/versions=1/valueSize=8/numRangeKeys=0-24         3.82µs ± 1%    3.81µs ± 1%    ~     (p=0.571 n=5+5)
MVCCGet_Pebble/batch=true/versions=1/valueSize=8/numRangeKeys=1-24         6.19µs ± 1%    6.14µs ± 1%    ~     (p=0.310 n=5+5)
MVCCGet_Pebble/batch=true/versions=1/valueSize=8/numRangeKeys=100-24       69.2µs ± 0%    69.6µs ± 1%  +0.70%  (p=0.032 n=5+5)
MVCCGet_Pebble/batch=true/versions=10/valueSize=8/numRangeKeys=0-24        22.1µs ± 1%    22.0µs ± 2%    ~     (p=0.310 n=5+5)
MVCCGet_Pebble/batch=true/versions=10/valueSize=8/numRangeKeys=1-24        27.6µs ± 1%    27.8µs ± 1%    ~     (p=0.222 n=5+5)
MVCCGet_Pebble/batch=true/versions=10/valueSize=8/numRangeKeys=100-24      94.2µs ± 1%    95.7µs ± 1%  +1.57%  (p=0.032 n=5+5)
MVCCGet_Pebble/batch=true/versions=100/valueSize=8/numRangeKeys=0-24        105µs ± 1%     105µs ± 1%    ~     (p=0.841 n=5+5)
MVCCGet_Pebble/batch=true/versions=100/valueSize=8/numRangeKeys=1-24        114µs ± 1%     114µs ± 2%    ~     (p=0.841 n=5+5)
MVCCGet_Pebble/batch=true/versions=100/valueSize=8/numRangeKeys=100-24      188µs ± 3%     190µs ± 1%    ~     (p=0.310 n=5+5)

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @erikgrinaker and @RaduBerinde)

@jbowens
Copy link
Collaborator Author

jbowens commented Feb 27, 2023

TFTR!

@jbowens jbowens merged commit 73766d6 into cockroachdb:release-22.2 Feb 27, 2023
@jbowens jbowens deleted the 22.2-mangle branch February 27, 2023 17:42
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