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

batcheval: add latch key protecting range key stats update #86608

Merged
merged 1 commit into from
Aug 25, 2022

Conversation

aliher1911
Copy link
Contributor

@aliher1911 aliher1911 commented Aug 22, 2022

Previously GC needed to get a read latch with max timestamp to
ensure that range tombstones are not modified during GC. This
is causing all writers to get stuck in queue while GC is validating
request and removing range tombstone.
This commit adds a dedicated latch key
LocalRangeRangeTombstoneStatsUpdateLockSuffix to address the problem.
All range tombstone writers obtain this read latch on top of the write
latches for the ranges they are interested to update.
GC on the other hand will obtain write latch on that key. This
approach allows point writers to proceed during GC, but will block new
range tombstones from being written. Non conflicting writes of range
tombstones could still proceed since their write latch ranges don't
overlap.

Release justification: this is a safe change as range tombstone
behaviour is not enabled yet and the change is needed to address
potential performance regressions.

Release note: None

Fixes #84576
Fixes #86551

@aliher1911 aliher1911 requested review from erikgrinaker and tbg August 22, 2022 20:03
@aliher1911 aliher1911 self-assigned this Aug 22, 2022
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@aliher1911
Copy link
Contributor Author

Other commands needs latches as well. TBD.

pkg/kv/kvserver/batcheval/cmd_gc.go Outdated Show resolved Hide resolved
pkg/keys/constants.go Outdated Show resolved Hide resolved
pkg/kv/kvserver/batcheval/cmd_delete_range.go Outdated Show resolved Hide resolved
Copy link
Member

@tbg tbg left a comment

Choose a reason for hiding this comment

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

Looks good mod Erik's comments.

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @aliher1911 and @erikgrinaker)


pkg/keys/keys.go line 1061 at r1 (raw file):

// RangeTombstoneStatsUpdateKey returns a system-local key for last used GC threshold on the
// user keyspace. Reads and writes <= this timestamp will not be served.
func (b RangeIDPrefixBuf) RangeTombstoneStatsUpdateKey() roachpb.Key {

Inconsistent name and comment.


pkg/kv/kvserver/batcheval/cmd_delete_range.go line 63 at r1 (raw file):

Previously, erikgrinaker (Erik Grinaker) wrote…

We only need to set this when UseRangeTombstone is set.

We'll need this for all other operations that can affect range keys too, i.e. ClearRange, RevertRange, and AddSSTable. The last one is a bit unfortunate -- we could maybe look at the given SST stats, but I'm not sure we want to rely on them for correctness.

Why is it unfortunate to do this for AddSSTable? Shouldn't matter much, since ranges undergoing GC are unlikely to also be receiving SSTs, no?

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.

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


pkg/kv/kvserver/batcheval/cmd_delete_range.go line 63 at r1 (raw file):

Previously, tbg (Tobias Grieger) wrote…

Why is it unfortunate to do this for AddSSTable? Shouldn't matter much, since ranges undergoing GC are unlikely to also be receiving SSTs, no?

It's just a bit coarse to essentially block all AddSSTableactivity during MVCC range tombstone GC. This is for the general MVCC range tombstone GC, not for the fast path used by schema GC, so this could happen across live keyspace. E.g. if someone cancels an import, then retries it, and the GC triggers during the import. Not a huge deal though, should be fine (at least for now).

@aliher1911 aliher1911 force-pushed the range_tombstone_magic_latch branch 3 times, most recently from 38085f1 to 722e313 Compare August 24, 2022 08:31
@aliher1911 aliher1911 marked this pull request as ready for review August 24, 2022 08:31
@aliher1911 aliher1911 requested a review from a team as a code owner August 24, 2022 08:31
@aliher1911 aliher1911 requested review from erikgrinaker and tbg August 24, 2022 08:32
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.

I think we'll have to do this for EndTxn too, for splits/merges, where we peek around the split/merge point and adjust range key stats -- since GC is now latchless and the stats updates are non-commutative.

pkg/keys/keys.go Outdated

// RangeTombstoneStatsUpdateKey returns a range local key protecting range
// tombstone mvcc stats calculations during range tombstone GC.
func (b RangeIDPrefixBuf) RangeTombstoneStatsUpdateKey() roachpb.Key {
Copy link
Contributor

Choose a reason for hiding this comment

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

MVCCRangeKeyGCKey()

// Obtain a read only lock on range key stats update key to serialize with
// range tombstone GC requests.
latchSpans.AddNonMVCC(spanset.SpanReadOnly, roachpb.Span{
Key: keys.MakeRangeIDPrefixBuf(rs.GetRangeID()).RangeTombstoneStatsUpdateKey(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a helper for this, similarly to e.g. keys.RaftTruncatedStateKey(rangeID).

@erikgrinaker
Copy link
Contributor

We discussed earlier that GC takes out a read latch on the range descriptor, but how exactly does that serialize with splits/merges? May well be right, I'd just like to be sure we're covered.

@aliher1911
Copy link
Contributor Author

I think you are right here. We are not getting enough latches to cover GC range ops.

@erikgrinaker
Copy link
Contributor

While we're here, could you update all the comments around rangeTombstonePeekBounds() calls to say that even though we're possibly taking out latches beyond the range end bound, the latches are enforced per-range, so we won't contend with other ranges -- and the peek bounds will be tightened to the range bounds during evaluation.

@aliher1911 aliher1911 force-pushed the range_tombstone_magic_latch branch from 722e313 to f079490 Compare August 24, 2022 14:18
@aliher1911 aliher1911 force-pushed the range_tombstone_magic_latch branch from f079490 to 249575f Compare August 24, 2022 21:47
pkg/kv/kvserver/batcheval/cmd_clear_range.go Outdated Show resolved Hide resolved
pkg/kv/kvserver/batcheval/cmd_add_sstable.go Outdated Show resolved Hide resolved
Previously GC needed to get a read latch with max timestamp to
ensure that range tombstones are not modified during GC. This
is causing all writers to get stuck in queue while GC is validating
request and removing range tombstone.
This commit adds a dedicated latch key
LocalRangeMVCCRangeKeyGCLockSuffix to address the problem.
All range tombstone writers obtain this read latch on top of the write
latches for the ranges they are interested to update.
GC on the other hand will obtain write latch on that key. This
approach allows point writers to proceed during GC, but will block new
range tombstones from being written. Non conflicting writes of range
tombstones could still proceed since their write latch ranges don't
overlap.

Release justification: this is a safe change as range tombstone
behaviour is not enabled yet and the change is needed to address
potential performance regressions.

Release note: None
@aliher1911 aliher1911 force-pushed the range_tombstone_magic_latch branch from 249575f to d15851a Compare August 25, 2022 08:34
@aliher1911
Copy link
Contributor Author

bors r=erikgrinaker

@craig
Copy link
Contributor

craig bot commented Aug 25, 2022

Build succeeded:

@craig craig bot merged commit 54bc65f into cockroachdb:master Aug 25, 2022
@aliher1911 aliher1911 deleted the range_tombstone_magic_latch branch August 31, 2022 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants