Skip to content

storage: tighten MVCCDeleteRangeUsingTombstone key span checks#87403

Merged
craig[bot] merged 2 commits intocockroachdb:masterfrom
erikgrinaker:mvcc-range-tombstone-local-keys
Sep 7, 2022
Merged

storage: tighten MVCCDeleteRangeUsingTombstone key span checks#87403
craig[bot] merged 2 commits intocockroachdb:masterfrom
erikgrinaker:mvcc-range-tombstone-local-keys

Conversation

@erikgrinaker
Copy link
Copy Markdown
Contributor

@erikgrinaker erikgrinaker commented Sep 6, 2022

storage: tighten MVCCDeleteRangeUsingTombstone key span checks

We've previously disallowed writing MVCC range tombstones across local
keyspace. However, this check used keys.IsLocal(), which simply checks
whether the key has the local prefix (\x01), so it was possible for
callers to use e.g. \x00 as a start key and span the local keyspace
anyway.

This patch changes the check to ensure the start key is at or after
keys.LocalMax.

Release justification: bug fixes and low-risk updates to new functionality

Release note: None

storage: fix intentInterleavingIter local key detection

intentInterleavingIter will error if given bounds that span from the
local to the global keyspace. However, it only checked whether the start
key satisfied keys.IsLocal(), i.e. that the key began with \x01.
This meant that it was possible to give a start key with a \x00 prefix
that spanned across the local and global keyspaces, without triggering
the error. This could cause the iterator to be incorrectly positioned in
the lock table keyspace.

This patch fixes the check by comparing the start key with
keys.LocalMax instead. This does not appear to have a measurable
impact on performance:

name                                                                old time/op    new time/op    delta
MVCCGet_Pebble/batch=true/versions=1/valueSize=8/numRangeKeys=0-24    2.39µs ± 1%    2.39µs ± 1%   ~     (p=0.810 n=10+10)

Resolves #87489.

Release justification: low risk, high benefit changes to existing functionality
Release note: None

@erikgrinaker erikgrinaker requested review from a team, aliher1911 and tbg September 6, 2022 09:03
@erikgrinaker erikgrinaker self-assigned this Sep 6, 2022
@erikgrinaker erikgrinaker requested a review from a team as a code owner September 6, 2022 09:03
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Collaborator

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @aliher1911, @erikgrinaker, and @tbg)


pkg/kv/kvserver/mvcc_gc_queue_test.go line 515 at r1 (raw file):

			require.NoError(t, storage.MVCCPut(ctx, rw, ms, key, delTime, hlc.ClockTimestamp{}, roachpb.Value{}, nil))
		}
	}

how about adding a require.Error test case that will fail with the new logic and that did not fail before?

@erikgrinaker erikgrinaker force-pushed the mvcc-range-tombstone-local-keys branch 2 times, most recently from e5805d8 to 3e9bfe4 Compare September 6, 2022 12:35
Copy link
Copy Markdown
Contributor Author

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @aliher1911, @sumeerbhola, and @tbg)


pkg/kv/kvserver/mvcc_gc_queue_test.go line 515 at r1 (raw file):

Previously, sumeerbhola wrote…

how about adding a require.Error test case that will fail with the new logic and that did not fail before?

Yeah, may as well, done (TestMVCCHistories). This shouldn't be possible in production code though, since we always use an appropriate key prefix.

@tbg tbg removed their request for review September 6, 2022 12:38
@aliher1911
Copy link
Copy Markdown
Contributor

I think this will blow up with changes that were done to MVCCStats randomized tests as they use range deletions for local space as well if I'm not mistaken.

@erikgrinaker
Copy link
Copy Markdown
Contributor Author

I think this will blow up with changes that were done to MVCCStats randomized tests as they use range deletions for local space as well if I'm not mistaken.

I asked Tobi to address that in the original PR, so I think it should be fixed? But I'll make sure to adapt any failing tests otherwise.

We've previously disallowed writing MVCC range tombstones across local
keyspace. However, this check used `keys.IsLocal()`, which simply checks
whether the key has the local prefix (`\x01`), so it was possible for
callers to use e.g. `\x00` as a start key and span the local keyspace
anyway.

This patch changes the check to ensure the start key is at or after
`keys.LocalMax`.

Release justification: bug fixes and low-risk updates to new functionality

Release note: None
@erikgrinaker erikgrinaker force-pushed the mvcc-range-tombstone-local-keys branch from 3e9bfe4 to b4b2ebe Compare September 7, 2022 13:43
`intentInterleavingIter` will error if given bounds that span from the
local to the global keyspace. However, it only checked whether the start
key satisfied `keys.IsLocal()`, i.e. that the key began with `\x01`.
This meant that it was possible to give a start key with a `\x00` prefix
that spanned across the local and global keyspaces, without triggering
the error. This could cause the iterator to be incorrectly positioned in
the lock table keyspace.

This patch fixes the check by comparing the start key with
`keys.LocalMax` instead. This does not appear to have a measurable
impact on performance:

```
name                                                                old time/op    new time/op    delta
MVCCGet_Pebble/batch=true/versions=1/valueSize=8/numRangeKeys=0-24    2.39µs ± 1%    2.39µs ± 1%   ~     (p=0.810 n=10+10)
```

Release justification: low risk, high benefit changes to existing functionality
Release note: None
@erikgrinaker
Copy link
Copy Markdown
Contributor Author

@sumeerbhola It turns out intentInterleavingIter had the same problem (see #87489), I've added on a commit which addresses it. PTAL.

Copy link
Copy Markdown
Collaborator

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r2, 2 of 2 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @aliher1911, @erikgrinaker, and @sumeerbhola)


pkg/storage/intent_interleaving_iter.go line 171 at r4 (raw file):

}

func isLocal(k roachpb.Key) bool {

this isLocal method is also used in mvcc.go in CanGCEntireRange -- it looks like this behavior change is fine for that case too.

@erikgrinaker
Copy link
Copy Markdown
Contributor Author

Looks like I won the flake jackpot with 3 different and unrelated CI failures.

bors r=sumeerbhola

@craig craig bot merged commit 76a5f63 into cockroachdb:master Sep 7, 2022
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Sep 7, 2022

Build succeeded:

@erikgrinaker erikgrinaker deleted the mvcc-range-tombstone-local-keys branch October 30, 2022 13:07
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.

storage: missing intent in TestMVCCHistories/range_tombstone_writes

4 participants