Skip to content

storage: always write RANGEKEYDELs in ClearRangeWithHeuristic #145096

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

Merged
merged 1 commit into from
May 6, 2025

Conversation

jbowens
Copy link
Collaborator

@jbowens jbowens commented Apr 24, 2025

Previously, ClearRangeWithHeuristic applied a heuristic that would switch between writing RANGEKEYUNSETs versus RANGEKEYDELs. When multiple range keys overlap, unsetting each individual range key with RANGEKEYUNSET is strictly worse than writing a single RANGEKEYDEL over the same span.

This commit adapts ClearRangeWithHeuristic to write a single RANGEKEYDEL over the cleared span, but only if there are indeed range keys within the span. Setting a broad RANGEKEYDEL increases the likelihood that data can be removed using a delete-only compaction.

Close #144954.
Epic: none
Release note: none

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jbowens jbowens marked this pull request as ready for review April 24, 2025 21:45
@jbowens jbowens requested review from a team as code owners April 24, 2025 21:45
@jbowens jbowens requested a review from sumeerbhola April 24, 2025 21:45
@RaduBerinde
Copy link
Member

Just curious - why doesn't the same apply to point deletes?

@jbowens
Copy link
Collaborator Author

jbowens commented Apr 25, 2025

Just curious - why doesn't the same apply to point deletes?

If we end up writing point deletes, we won't be able to pursue a delete-only compaction either. But if the heuristic triggers and there were fewer keys than the threshold (64 during replica removals), it was unlikely that we could've found a sstable wholly contained within the key span anyways because there are so few keys. The same logic doesn't apply for range keys, since a single range key can have a very broad key span.

@RaduBerinde
Copy link
Member

I see - still, what's the downside of writing a single rangedel vs multiple point dels?

@jbowens
Copy link
Collaborator Author

jbowens commented Apr 25, 2025

I see - still, what's the downside of writing a single rangedel vs multiple point dels?

I think the iteration overhead of a rangedel is higher than a small quantity of point dels because
a) we need to load every higher level's overlapping sstable's range deletion block if it exists
b) every point tombstone needs to be compared to the current range deletion in all higher levels' range deletion blocks (this is what cockroachdb/pebble#3600 strived to avoid but I never managed to track down the last of the correctness issues there).

Copy link
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 6 of 6 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jbowens)


pkg/storage/engine.go line 1599 at r1 (raw file):

// will switch from clearing individual keys using point tombstones to clearing
// the entire range using Pebble range tombstones (RANGEDELs). Setting
// pointKeyThreshold to 0 disables checking for and clearing point keys. NB: An

This 0 behavior is very confusing, and I don't see any code in production calling it with 0.
Similarly for rangeKeyThreshold. Can we require this threshold to be > 0 and eliminate the shouldClearRangeKeys parameter?

@jbowens jbowens force-pushed the clearrangewithheuristic branch 2 times, most recently from 7e94755 to 93b22d3 Compare April 30, 2025 20:36
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!

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


pkg/storage/engine.go line 1599 at r1 (raw file):

Previously, sumeerbhola wrote…

This 0 behavior is very confusing, and I don't see any code in production calling it with 0.
Similarly for rangeKeyThreshold. Can we require this threshold to be > 0 and eliminate the shouldClearRangeKeys parameter?

Good call, Done.

Copy link
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 6 of 6 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jbowens)

@jbowens jbowens force-pushed the clearrangewithheuristic branch 2 times, most recently from c448f92 to 6ce4031 Compare May 5, 2025 17:50
Previously, ClearRangeWithHeuristic applied a heuristic that would switch
between writing RANGEKEYUNSETs versus RANGEKEYDELs. When multiple range keys
overlap, unsetting each individual range key with RANGEKEYUNSET is strictly
worse than writing a single RANGEKEYDEL over the same span.

This commit adapts ClearRangeWithHeuristic to write a single RANGEKEYDEL over
the cleared span, but only if there are indeed range keys within the span.
Setting a broad RANGEKEYDEL increases the likelihood that data can be removed
using a delete-only compaction.

Close cockroachdb#144954.
Epic: none
Release note: none
@jbowens jbowens force-pushed the clearrangewithheuristic branch from 6ce4031 to 614868e Compare May 5, 2025 18:39
@jbowens
Copy link
Collaborator Author

jbowens commented May 6, 2025

TFTR!

bors r=sumeerbhola

@craig
Copy link
Contributor

craig bot commented May 6, 2025

@craig craig bot merged commit 3faaec6 into cockroachdb:master May 6, 2025
22 checks passed
@jbowens jbowens deleted the clearrangewithheuristic branch May 7, 2025 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

storage: ClearRangeWithHeuristic should prefer RANGEKEYDELs
4 participants