Skip to content

Conversation

jbowens
Copy link
Collaborator

@jbowens jbowens commented Jun 6, 2025

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.

@jbowens jbowens requested a review from a team as a code owner June 6, 2025 20:14
@jbowens jbowens requested a review from RaduBerinde June 6, 2025 20:14
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jbowens jbowens force-pushed the cleanup-manager-stats branch 2 times, most recently from 4c652f7 to 683a17a Compare June 6, 2025 20:21
Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

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.
@jbowens jbowens force-pushed the cleanup-manager-stats branch from 683a17a to e47bd96 Compare June 6, 2025 20:29
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: 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

@jbowens jbowens merged commit 8ab4b15 into cockroachdb:master Jun 6, 2025
6 checks passed
@jbowens jbowens deleted the cleanup-manager-stats branch June 6, 2025 20:40
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.

Incorrect and overflowed db.Metrics().DiskSpaceUsage()
3 participants