blob_garbage_collection_force_threshold = 0.0 makes the forced-GC predicate a tautology: an idle DB compacts forever
Summary
VersionStorageInfo::ComputeFilesMarkedForForcedBlobGC() decides whether to
force blob GC with
if (sum_garbage_blob_bytes <
blob_garbage_collection_force_threshold * sum_total_blob_bytes) {
return;
}At blob_garbage_collection_force_threshold = 0.0 the right-hand side is 0 and
the test is unsigned < 0, which is never true. The early return becomes
unreachable, so every batch of blob files is marked for forced garbage
collection, including batches containing no garbage at all. The resulting
compaction rewrites those blobs into fresh blob files, which also contain no
garbage, and which are immediately marked again.
0.0 is inside the range RocksDB itself validates (db/column_family.cc accepts
[0.0, 1.0]), and the option's documentation says GC is forced when the garbage
ratio "exceeds" the threshold — i.e. >, whereas the code implements >=. For
any threshold in (0, 1) the difference is invisible, because the garbage bytes
are essentially never exactly equal to threshold * total. At 0.0 it is the
whole defect.
Reproduction
400 keys written twice, a quarter deleted, one flush — and then the DB is
completely quiet: no writes, no flushes, no manual compaction. Compactions
are counted via an EventListener over a 60-second window, sampled every 10 s.
(The probe deliberately does not call CompactRange/WaitForCompact, because in
the affected configuration those do not return.)
compactions observed during a 60s quiet window
force=0.01 t=10s:4 t=20s:4 t=30s:4 t=40s:4 t=50s:4 t=60s:4 forcedGC=3
force=0.0 t=10s:19 t=20s:46 t=30s:70 t=40s:94 t=50s:122 t=60s:150 forcedGC=149force=0.01 is the control and it does the right thing: it runs forced GC three
times, reclaims what there is, and stops — flat at 4 compactions for the
remaining 50 seconds. force=0.0 climbs in a dead straight line at ~2.5
compactions/s for the entire window with no sign of levelling off, and
essentially every one of those compactions is a forced blob GC
(CompactionReason::kForcedBlobGC, 149 of 150).
A threshold sweep on the same workload shows the boundary is exact — every
threshold above zero quiesces, only 0.0 does not:
defaults (cutoff 0.25 / force 1.0) 0 compactions in the quiet window forcedGC=0
force=0.9 0 forcedGC=0
force=0.5 0 forcedGC=0
force=0.25 0 forcedGC=0
force=0.1 0 forcedGC=0
force=0.01 0 forcedGC=1
force=0.0 climbing forcedGC=36 <<<
force=0.0, cutoff=1.0 climbing forcedGC=6 <<<Only the force threshold matters; the age cutoff is incidental.
Root cause
db/version_set.cc, VersionStorageInfo::ComputeFilesMarkedForForcedBlobGC().
The function is entered whenever
blob_garbage_collection_force_threshold < 1.0 and the age cutoff is positive,
so 0.0 passes the entry guard:
if (!(enable_blob_garbage_collection &&
blob_garbage_collection_age_cutoff > 0.0 &&
blob_garbage_collection_force_threshold < 1.0)) {
return;
}then, after summing over the eligible batch (line 4061):
if (sum_garbage_blob_bytes <
blob_garbage_collection_force_threshold * sum_total_blob_bytes) {
return;
}sum_garbage_blob_bytes is uint64_t. With the threshold at 0.0 the
comparison is x < 0.0, false for every x, so the function always proceeds to
mark every linked SST.
The documented rule is strict:
// If the ratio of garbage in the blob files currently eligible for garbage
// collection exceeds this threshold, targeted compactions are scheduled in
// order to force garbage collecting the oldest blob files.
double blob_garbage_collection_force_threshold = 1.0;The sibling function guards exactly this case
Twenty-five lines below, in the same file, the read-triggered equivalent handles a zero threshold explicitly (line 4089):
void VersionStorageInfo::ComputeFilesMarkedForReadTriggeredCompaction(
double threshold, CompactionStyle compaction_style) {
read_triggered_compaction_files_.clear();
if (threshold <= 0.0 || compaction_style == kCompactionStyleFIFO) {
return;
}Suggested fix
Match the documented "exceeds", and make the zero case explicit the way the sibling does:
if (blob_garbage_collection_force_threshold <= 0.0) {
// "Force GC whenever there is any garbage" — but no garbage means nothing
// to do, so do not mark a clean batch.
if (sum_garbage_blob_bytes == 0) {
return;
}
} else if (sum_garbage_blob_bytes <=
blob_garbage_collection_force_threshold * sum_total_blob_bytes) {
return;
}At minimum < has to become <=, so that a zero threshold with zero garbage
does not qualify. Rejecting 0.0 in ValidateOptions would also stop the
symptom, but it is a worse answer — "force GC whenever there is any garbage" is a
reasonable thing to ask for and is what the option reads like it means.
Environment
mainat507206e46bdf876174532b8eb6b26f54f698b8dc(2026-09-21)- CMake Release, gcc 11.4.0, Ubuntu 22.04 x86-64, compression disabled
- Also present in 11.8.1, where the same configuration produced ~190 compactions/s and grew the directory from 0.4 MB to 29.7 MB in nine seconds
Source: facebook/rocksdb