db: fix obsolete file metric underflows#4839
Merged
jbowens merged 1 commit intocockroachdb:masterfrom Jun 6, 2025
Merged
Conversation
Member
4c652f7 to
683a17a
Compare
RaduBerinde
approved these changes
Jun 6, 2025
Member
RaduBerinde
left a comment
There was a problem hiding this comment.
Nice find!
Reviewable status: 0 of 4 files reviewed, 1 unresolved discussion
obsolete_files.go line 38 at r1 (raw file):
opts *Options objProvider objstorage.Provider onTableDeleteFn func(fileSize uint64, isLocal bool)
Nice to see this gone!
db.go line 460 at r1 (raw file):
// reference count to prohibit file cleaning. See // DB.{disable,enable}FileDeletions(). disabled int
[nit] disableCount
Previously a race existed in the calculation of obsolete file metrics resulting
in underflow. The values within versionSet.metrics were reset and recalculated
to reflect the set of files in versionSet.obsolete{Tables,Blobs} whenever new
files were added to obsoleteFiles. Additionally, the cleanup manager invoked a
callback to decrease versionSet.metrics whenever a table was deleted.
The recalculation of versionSet.metrics could reset the metrics to less than
the sum of outstanding pending deletes. When the cleanup manager eventually
deleted the pending tables, these metrics would underflow.
This commit fixes the bug by maintaining separate stats for all files that have
been enqueued for the cleanup manager and all files that have been successfully
deleted. The volume of outstanding, pending deletions is the difference between
the two.
For now, there's an additional wart that the set of files that are sitting in
versionSet.obsolete{Table,Blobs} are still separately tracked.
Fix cockroachdb#4811.
683a17a to
e47bd96
Compare
jbowens
commented
Jun 6, 2025
Contributor
Author
jbowens
left a comment
There was a problem hiding this comment.
TFTR!
Reviewable status: 0 of 4 files reviewed, all discussions resolved (waiting on @RaduBerinde)
db.go line 460 at r1 (raw file):
Previously, RaduBerinde wrote…
[nit] disableCount
Done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously a race existed in the calculation of obsolete file metrics resulting in underflow. The values within versionSet.metrics were reset and recalculated to reflect the set of files in versionSet.obsolete{Tables,Blobs} whenever new files were added to obsoleteFiles. Additionally, the cleanup manager invoked a callback to decrease versionSet.metrics whenever a table was deleted.
The recalculation of versionSet.metrics could reset the metrics to less than the sum of outstanding pending deletes. When the cleanup manager eventually deleted the pending tables, these metrics would underflow.
This commit fixes the bug by maintaining separate stats for all files that have been enqueued for the cleanup manager and all files that have been successfully deleted. The volume of outstanding, pending deletions is the difference between the two.
For now, there's an additional wart that the set of files that are sitting in versionSet.obsolete{Table,Blobs} are still separately tracked.
Fix #4811.