Repository navigation
Fix table handle leak - #14469
Closed
joshkang97 wants to merge 9 commits into
Closed
Fix table handle leak #14469joshkang97 wants to merge 9 commits into
joshkang97 wants to merge 9 commits into
Conversation
|
@joshkang97 has imported this pull request. If you are a Meta employee, you can view this in D97190944. |
✅ clang-tidy: No findings on changed linesCompleted in 287.5s. |
hx235
requested changes
Mar 19, 2026
|
@joshkang97 has imported this pull request. If you are a Meta employee, you can view this in D97190944. |
|
@joshkang97 has imported this pull request. If you are a Meta employee, you can view this in D97190944. |
|
@joshkang97 has imported this pull request. If you are a Meta employee, you can view this in D97190944. |
|
@joshkang97 has imported this pull request. If you are a Meta employee, you can view this in D97190944. |
|
@joshkang97 merged this pull request in 3d99378. |
pdillinger
added a commit
to pdillinger/rocksdb
that referenced
this pull request
Apr 1, 2026
Summary: When CompactionJob::Run() succeeds but Install() fails (e.g., LogAndApply MANIFEST I/O error), compact_->status was never updated with the install failure. CleanupCompaction() passed the stale OK status to SubcompactionState::Cleanup(), which skipped ReleaseObsolete -- leaking table cache entries for output files that were cached by VerifyOutputFiles but never installed into any Version. This is the same class of bug fixed in meta#14469 (where Run() failed after VerifyOutputFiles), but in the Install() failure path. The FindObsoleteFiles full-scan backstop would normally catch this, but fails under crash test metadata read fault injection (--open_metadata_read_fault_one_in), causing the TEST_VerifyNoObsoleteFilesCached assertion to fire during Close(). Fix: propagate Install()'s local status back to compact_->status before CleanupCompaction(), so Cleanup() sees the failure and calls ReleaseObsolete on the output files. Test Plan: New unit test DBCompactionTest.LeakedTableCacheEntryOnInstallFailure: - Without fix (ASAN): assertion fires -- "File 12 is not live nor quarantined" - With fix (ASAN): passes -- ReleaseObsolete properly cleans up the entry ``` COMPILE_WITH_ASAN=1 make -j db_compaction_test ./db_compaction_test --gtest_filter="DBCompactionTest.LeakedTableCacheEntry*" [ PASSED ] 2 tests. ``` Tasks: T218515781
meta-codesync Bot
pushed a commit
that referenced
this pull request
Apr 2, 2026
Summary: When CompactionJob::Run() succeeds but Install() fails (e.g., LogAndApply MANIFEST I/O error), compact_->status was never updated with the install failure. CleanupCompaction() passed the stale OK status to SubcompactionState::Cleanup(), which skipped ReleaseObsolete -- leaking table cache entries for output files that were cached by VerifyOutputFiles but never installed into any Version. This is the same class of bug fixed in #14469 (where Run() failed after VerifyOutputFiles), but in the Install() failure path. The FindObsoleteFiles full-scan backstop would normally catch this, but fails under crash test metadata read fault injection (--open_metadata_read_fault_one_in), causing the TEST_VerifyNoObsoleteFilesCached assertion to fire during Close(). Fix: propagate Install()'s local status back to compact_->status before CleanupCompaction(), so Cleanup() sees the failure and calls ReleaseObsolete on the output files. Pull Request resolved: #14549 Test Plan: New unit test DBCompactionTest.LeakedTableCacheEntryOnInstallFailure: - Without fix (ASAN): assertion fires -- "File 12 is not live nor quarantined" - With fix (ASAN): passes -- ReleaseObsolete properly cleans up the entry ``` COMPILE_WITH_ASAN=1 make -j db_compaction_test ./db_compaction_test --gtest_filter="DBCompactionTest.LeakedTableCacheEntry*" [ PASSED ] 2 tests. ``` Reviewed By: joshkang97 Differential Revision: D99155908 Pulled By: pdillinger fbshipit-source-id: ed5374a38d7903866a38a0fe0f5539e12321bc84
pdillinger
added a commit
to pdillinger/rocksdb
that referenced
this pull request
Apr 6, 2026
Summary: When BuildTable succeeds during flush, it caches the output SST file in the table cache for subsequent user reads (builder.cc:460). If the flush then fails to install — e.g., LogAndApply MANIFEST I/O error, CF dropped, or shutdown — the cache entry was never evicted. BuildTable only cleans up its own failures (builder.cc:511), not failures in the install path. The FindObsoleteFiles full-scan backstop would normally catch this by finding the orphan file on disk and evicting the cache entry. However, under crash test metadata read fault injection (open_metadata_read_fault_one_in), GetChildren fails and the orphan is never found, causing the TEST_VerifyNoObsoleteFilesCached assertion to fire during Close(). This is the same class of bug previously fixed in the compaction path by meta#14469 (Run failure) and meta#14549 (Install failure), but in the flush path which had no analogous cleanup. Fix: call TableCache::ReleaseObsolete in FlushJob::Run() when the flush fails after BuildTable succeeded (meta_.fd.GetFileSize() > 0). Test Plan: New unit test DBFlushTest.LeakedTableCacheEntryOnFlushInstallFailure: - Injects failure after BuildTable via sync point, deactivates filesystem to prevent backstop cleanup - Without fix: assertion fires ("Leaked table cache entry") - With fix: passes ``` COMPILE_WITH_ASAN=1 make -j db_flush_test ./db_flush_test --gtest_filter="DBFlushTest.LeakedTableCacheEntry*" [ PASSED ] 1 test. ``` Existing compaction leak tests still pass: ``` COMPILE_WITH_ASAN=1 make -j db_compaction_test ./db_compaction_test --gtest_filter="*LeakedTableCacheEntry*" [ PASSED ] 2 tests. ```
meta-codesync Bot
pushed a commit
that referenced
this pull request
Apr 6, 2026
Summary: When BuildTable succeeds during flush, it caches the output SST file in the table cache for subsequent user reads (builder.cc:460). If the flush then fails to install — e.g., LogAndApply MANIFEST I/O error, CF dropped, or shutdown — the cache entry was never evicted. BuildTable only cleans up its own failures (builder.cc:511), not failures in the install path. The FindObsoleteFiles full-scan backstop would normally catch this by finding the orphan file on disk and evicting the cache entry. However, under crash test metadata read fault injection (open_metadata_read_fault_one_in), GetChildren fails and the orphan is never found, causing the TEST_VerifyNoObsoleteFilesCached assertion to fire during Close(). This is the same class of bug previously fixed in the compaction path by #14469 (Run failure) and #14549 (Install failure), but in the flush path which had no analogous cleanup. Fix: call TableCache::ReleaseObsolete in FlushJob::Run() when the flush fails after BuildTable succeeded (meta_.fd.GetFileSize() > 0). Pull Request resolved: #14577 Test Plan: New unit test DBFlushTest.LeakedTableCacheEntryOnFlushInstallFailure: - Injects failure after BuildTable via sync point, deactivates filesystem to prevent backstop cleanup - Without fix: assertion fires ("Leaked table cache entry") - With fix: passes ``` COMPILE_WITH_ASAN=1 make -j db_flush_test ./db_flush_test --gtest_filter="DBFlushTest.LeakedTableCacheEntry*" [ PASSED ] 1 test. ``` Existing compaction leak tests still pass: ``` COMPILE_WITH_ASAN=1 make -j db_compaction_test ./db_compaction_test --gtest_filter="*LeakedTableCacheEntry*" [ PASSED ] 2 tests. ``` Reviewed By: xingbowang Differential Revision: D99692601 Pulled By: pdillinger fbshipit-source-id: ff5aa1ad165b3abec915844f97f6af9e59d85774
doxtop
pushed a commit
to flyingw/rocksdb
that referenced
this pull request
Apr 7, 2026
Summary: Fix leaked table cache entries that cause `TEST_VerifyNoObsoleteFilesCached` assertion failure during `DB::Close()` in ASAN crash test builds (T258745630): ``` File 126519 is not live nor quarantined Assertion `cached_file_is_live_or_quar' failed. ``` When a compaction fails *after* `VerifyOutputFiles` succeeds (e.g., at `VerifyCompactionRecordCounts`), the overall `compact_->status` is set to error but each subcompaction's individual `status` remains OK. `SubcompactionState::Cleanup` only checked the individual subcompaction status, so it skipped calling `ReleaseObsolete` on the output files' table cache entries — leaking them. Normally, `Close()`'s backstop (`FindObsoleteFiles(force=true)` + `PurgeObsoleteFiles`) would catch this by finding the orphan file on disk, evicting the cache entry, and deleting the file. However, `FindObsoleteFiles` calls `FaultInjectionTestFS::GetChildren` which can fail under metadata read fault injection (`--open_metadata_read_fault_one_in=8`). The error is silently ignored (`s.PermitUncheckedError()` in db_impl_files.cc:199), so the orphan file is never found and the leaked cache entry is never evicted. The `Cleanup` bug is latent and predates recent changes. PR meta#14433 added `verify_output_flags` randomization to the crash test, and PR meta#14456 fixed false-positive corruptions that meta#14433 caused. Before meta#14456, `VerifyOutputFiles` would produce false corruption errors that *accidentally prevented the leak* by setting the subcompaction status to non-OK. ### How it triggers **Step 1 — VerifyOutputFiles adds cache entries for compaction output files:** ``` CompactionJob::Run() RunSubcompactions() // all subcompactions succeed // output file 12 written to disk // each sub_compact.status = OK SyncOutputDirectories() // status = OK VerifyOutputFiles() for each output_file: table_cache()->NewIterator(output_file.meta) FindTable() cache->Insert(file_number=12) // <<< ENTRY ADDED TO TABLE CACHE return iterator holding handle delete iter // releases handle, entry stays in LRU // status = OK ``` **Step 2 — A post-verification step fails, overall status set but NOT subcompaction status:** ``` CompactionJob::Run() VerifyCompactionRecordCounts() // returns Status::Corruption(...) FinalizeCompactionRun(status=Corruption) compact_->status = Corruption // <<< OVERALL status = error // each sub_compact.status is still OK! ``` **Step 3 — Install skips InstallCompactionResults (file 12 never enters a Version):** ``` CompactionJob::Install() status = compact_->status // Corruption if (status.ok()) // FALSE InstallCompactionResults() // <<< SKIPPED — file 12 not in any version ``` **Step 4 — CleanupCompaction skips ReleaseObsolete (THE BUG):** ``` CompactionJob::CleanupCompaction() for each sub_compact: sub_compact.Cleanup(table_cache) if (!status.ok()) // checks sub_compact.status = OK // <<< FALSE — individual status is OK! ReleaseObsolete(...) // <<< NEVER CALLED — cache entry leaked! ``` **Step 5 — Metadata read fault prevents backstop from finding the orphan:** `FindObsoleteFiles(force=true)` calls `GetChildren()` to scan the DB directory. `FaultInjectionTestFS::GetChildren` injects a metadata read error (`--open_metadata_read_fault_one_in=8`). The error is silently ignored (`s.PermitUncheckedError()`), so the directory listing is empty and the orphan file is never found. This happens both in the post-compaction cleanup (`BackgroundCallCompaction`) and in `Close()`'s backstop: ``` FindObsoleteFiles(force=true) fs->GetChildren(path, ...) // returns IOError (fault injected) s.PermitUncheckedError(); // error silently ignored // files vector is empty — orphan file 12 not found PurgeObsoleteFiles() // nothing to do — no Evict called ``` **Step 6 — Assertion fires during Close():** ``` CloseHelper() FindObsoleteFiles(force=true) // GetChildren fails again → orphan missed PurgeObsoleteFiles() // nothing to evict TEST_VerifyNoObsoleteFilesCached() for each cache entry: file_number = 12 live_and_quar_files.find(12) == end() // NOT in any version! >>> assert(cached_file_is_live_or_quar) FAILS <<< ``` **Crash test call stack:** ``` frame meta#9: __assert_fail_base("cached_file_is_live_or_quar", "db_impl_debug.cc", 389) frame meta#11: DBImpl::TEST_VerifyNoObsoleteFilesCached()::lambda // finds leaked entry frame meta#18: LRUCacheShard::ApplyToSomeEntries(...) // iterating cache shard frame meta#19: ShardedCache::ApplyToAllEntries(...) // iterating all shards frame meta#20: DBImpl::TEST_VerifyNoObsoleteFilesCached() // the verification frame meta#21: DBImpl::CloseHelper() // during Close frame meta#22: DBImpl::CloseImpl() frame meta#23: DBImpl::Close() frame meta#24: StressTest::Reopen() // crash test reopen frame meta#25: StressTest::OperateDb() // worker thread ``` ### Fix Pass the overall `compact_->status` to `SubcompactionState::Cleanup` and call `ReleaseObsolete` when *either* the subcompaction status or the overall status is non-OK: ```cpp // Before: if (!status.ok()) { ReleaseObsolete(...); } // After: if (!status.ok() || !overall_status.ok()) { ReleaseObsolete(...); } ``` ## Key changes - **`SubcompactionState::Cleanup`**: Now takes an `overall_status` parameter and calls `ReleaseObsolete` when *either* the subcompaction status or the overall compaction status is non-OK. - **`CompactionJob::CleanupCompaction`**: Passes `compact_->status` (the overall status) to each subcompaction's `Cleanup`. - **Sync point**: Added `CompactionJob::Run():AfterVerifyOutputFiles` for error injection in tests. - **Unit test**: `DBCompactionTest.LeakedTableCacheEntryOnCompactionFailure` uses `FaultInjectionTestFS` to reproduce the crash test scenario — injects error after `VerifyOutputFiles` and deactivates the filesystem so `GetChildren` fails in `FindObsoleteFiles`, preventing the backstop from evicting the leaked cache entry. Pull Request resolved: meta#14469 Test Plan: - `DBCompactionTest.LeakedTableCacheEntryOnCompactionFailure`: - **Without fix (ASAN)**: assertion fires during `Close()` — `File 12 is not live nor quarantined` - **With fix (ASAN)**: passes — `ReleaseObsolete` properly cleans up the cache entry - **With fix (non-ASAN)**: passes ``` $ COMPILE_WITH_ASAN=1 make -j db_compaction_test $ ./db_compaction_test --gtest_filter="DBCompactionTest.LeakedTableCacheEntryOnCompactionFailure" [ PASSED ] 1 test. ``` Reviewed By: xingbowang Differential Revision: D97190944 Pulled By: joshkang97 fbshipit-source-id: fdfd481cc1e192803cfb7d64052ccb9162c21b94
doxtop
pushed a commit
to flyingw/rocksdb
that referenced
this pull request
Apr 7, 2026
Summary: When CompactionJob::Run() succeeds but Install() fails (e.g., LogAndApply MANIFEST I/O error), compact_->status was never updated with the install failure. CleanupCompaction() passed the stale OK status to SubcompactionState::Cleanup(), which skipped ReleaseObsolete -- leaking table cache entries for output files that were cached by VerifyOutputFiles but never installed into any Version. This is the same class of bug fixed in meta#14469 (where Run() failed after VerifyOutputFiles), but in the Install() failure path. The FindObsoleteFiles full-scan backstop would normally catch this, but fails under crash test metadata read fault injection (--open_metadata_read_fault_one_in), causing the TEST_VerifyNoObsoleteFilesCached assertion to fire during Close(). Fix: propagate Install()'s local status back to compact_->status before CleanupCompaction(), so Cleanup() sees the failure and calls ReleaseObsolete on the output files. Pull Request resolved: meta#14549 Test Plan: New unit test DBCompactionTest.LeakedTableCacheEntryOnInstallFailure: - Without fix (ASAN): assertion fires -- "File 12 is not live nor quarantined" - With fix (ASAN): passes -- ReleaseObsolete properly cleans up the entry ``` COMPILE_WITH_ASAN=1 make -j db_compaction_test ./db_compaction_test --gtest_filter="DBCompactionTest.LeakedTableCacheEntry*" [ PASSED ] 2 tests. ``` Reviewed By: joshkang97 Differential Revision: D99155908 Pulled By: pdillinger fbshipit-source-id: ed5374a38d7903866a38a0fe0f5539e12321bc84
doxtop
pushed a commit
to flyingw/rocksdb
that referenced
this pull request
Apr 7, 2026
Summary: When BuildTable succeeds during flush, it caches the output SST file in the table cache for subsequent user reads (builder.cc:460). If the flush then fails to install — e.g., LogAndApply MANIFEST I/O error, CF dropped, or shutdown — the cache entry was never evicted. BuildTable only cleans up its own failures (builder.cc:511), not failures in the install path. The FindObsoleteFiles full-scan backstop would normally catch this by finding the orphan file on disk and evicting the cache entry. However, under crash test metadata read fault injection (open_metadata_read_fault_one_in), GetChildren fails and the orphan is never found, causing the TEST_VerifyNoObsoleteFilesCached assertion to fire during Close(). This is the same class of bug previously fixed in the compaction path by meta#14469 (Run failure) and meta#14549 (Install failure), but in the flush path which had no analogous cleanup. Fix: call TableCache::ReleaseObsolete in FlushJob::Run() when the flush fails after BuildTable succeeded (meta_.fd.GetFileSize() > 0). Pull Request resolved: meta#14577 Test Plan: New unit test DBFlushTest.LeakedTableCacheEntryOnFlushInstallFailure: - Injects failure after BuildTable via sync point, deactivates filesystem to prevent backstop cleanup - Without fix: assertion fires ("Leaked table cache entry") - With fix: passes ``` COMPILE_WITH_ASAN=1 make -j db_flush_test ./db_flush_test --gtest_filter="DBFlushTest.LeakedTableCacheEntry*" [ PASSED ] 1 test. ``` Existing compaction leak tests still pass: ``` COMPILE_WITH_ASAN=1 make -j db_compaction_test ./db_compaction_test --gtest_filter="*LeakedTableCacheEntry*" [ PASSED ] 2 tests. ``` Reviewed By: xingbowang Differential Revision: D99692601 Pulled By: pdillinger fbshipit-source-id: ff5aa1ad165b3abec915844f97f6af9e59d85774
Tim-Reed
pushed a commit
to Tim-Reed/rocksdb
that referenced
this pull request
Oct 1, 2026
Summary: Fix leaked table cache entries that cause `TEST_VerifyNoObsoleteFilesCached` assertion failure during `DB::Close()` in ASAN crash test builds (T258745630): ``` File 126519 is not live nor quarantined Assertion `cached_file_is_live_or_quar' failed. ``` When a compaction fails *after* `VerifyOutputFiles` succeeds (e.g., at `VerifyCompactionRecordCounts`), the overall `compact_->status` is set to error but each subcompaction's individual `status` remains OK. `SubcompactionState::Cleanup` only checked the individual subcompaction status, so it skipped calling `ReleaseObsolete` on the output files' table cache entries — leaking them. Normally, `Close()`'s backstop (`FindObsoleteFiles(force=true)` + `PurgeObsoleteFiles`) would catch this by finding the orphan file on disk, evicting the cache entry, and deleting the file. However, `FindObsoleteFiles` calls `FaultInjectionTestFS::GetChildren` which can fail under metadata read fault injection (`--open_metadata_read_fault_one_in=8`). The error is silently ignored (`s.PermitUncheckedError()` in db_impl_files.cc:199), so the orphan file is never found and the leaked cache entry is never evicted. The `Cleanup` bug is latent and predates recent changes. PR meta#14433 added `verify_output_flags` randomization to the crash test, and PR meta#14456 fixed false-positive corruptions that meta#14433 caused. Before meta#14456, `VerifyOutputFiles` would produce false corruption errors that *accidentally prevented the leak* by setting the subcompaction status to non-OK. ### How it triggers **Step 1 — VerifyOutputFiles adds cache entries for compaction output files:** ``` CompactionJob::Run() RunSubcompactions() // all subcompactions succeed // output file 12 written to disk // each sub_compact.status = OK SyncOutputDirectories() // status = OK VerifyOutputFiles() for each output_file: table_cache()->NewIterator(output_file.meta) FindTable() cache->Insert(file_number=12) // <<< ENTRY ADDED TO TABLE CACHE return iterator holding handle delete iter // releases handle, entry stays in LRU // status = OK ``` **Step 2 — A post-verification step fails, overall status set but NOT subcompaction status:** ``` CompactionJob::Run() VerifyCompactionRecordCounts() // returns Status::Corruption(...) FinalizeCompactionRun(status=Corruption) compact_->status = Corruption // <<< OVERALL status = error // each sub_compact.status is still OK! ``` **Step 3 — Install skips InstallCompactionResults (file 12 never enters a Version):** ``` CompactionJob::Install() status = compact_->status // Corruption if (status.ok()) // FALSE InstallCompactionResults() // <<< SKIPPED — file 12 not in any version ``` **Step 4 — CleanupCompaction skips ReleaseObsolete (THE BUG):** ``` CompactionJob::CleanupCompaction() for each sub_compact: sub_compact.Cleanup(table_cache) if (!status.ok()) // checks sub_compact.status = OK // <<< FALSE — individual status is OK! ReleaseObsolete(...) // <<< NEVER CALLED — cache entry leaked! ``` **Step 5 — Metadata read fault prevents backstop from finding the orphan:** `FindObsoleteFiles(force=true)` calls `GetChildren()` to scan the DB directory. `FaultInjectionTestFS::GetChildren` injects a metadata read error (`--open_metadata_read_fault_one_in=8`). The error is silently ignored (`s.PermitUncheckedError()`), so the directory listing is empty and the orphan file is never found. This happens both in the post-compaction cleanup (`BackgroundCallCompaction`) and in `Close()`'s backstop: ``` FindObsoleteFiles(force=true) fs->GetChildren(path, ...) // returns IOError (fault injected) s.PermitUncheckedError(); // error silently ignored // files vector is empty — orphan file 12 not found PurgeObsoleteFiles() // nothing to do — no Evict called ``` **Step 6 — Assertion fires during Close():** ``` CloseHelper() FindObsoleteFiles(force=true) // GetChildren fails again → orphan missed PurgeObsoleteFiles() // nothing to evict TEST_VerifyNoObsoleteFilesCached() for each cache entry: file_number = 12 live_and_quar_files.find(12) == end() // NOT in any version! >>> assert(cached_file_is_live_or_quar) FAILS <<< ``` **Crash test call stack:** ``` frame meta#9: __assert_fail_base("cached_file_is_live_or_quar", "db_impl_debug.cc", 389) frame meta#11: DBImpl::TEST_VerifyNoObsoleteFilesCached()::lambda // finds leaked entry frame meta#18: LRUCacheShard::ApplyToSomeEntries(...) // iterating cache shard frame meta#19: ShardedCache::ApplyToAllEntries(...) // iterating all shards frame meta#20: DBImpl::TEST_VerifyNoObsoleteFilesCached() // the verification frame meta#21: DBImpl::CloseHelper() // during Close frame meta#22: DBImpl::CloseImpl() frame meta#23: DBImpl::Close() frame meta#24: StressTest::Reopen() // crash test reopen frame meta#25: StressTest::OperateDb() // worker thread ``` ### Fix Pass the overall `compact_->status` to `SubcompactionState::Cleanup` and call `ReleaseObsolete` when *either* the subcompaction status or the overall status is non-OK: ```cpp // Before: if (!status.ok()) { ReleaseObsolete(...); } // After: if (!status.ok() || !overall_status.ok()) { ReleaseObsolete(...); } ``` ## Key changes - **`SubcompactionState::Cleanup`**: Now takes an `overall_status` parameter and calls `ReleaseObsolete` when *either* the subcompaction status or the overall compaction status is non-OK. - **`CompactionJob::CleanupCompaction`**: Passes `compact_->status` (the overall status) to each subcompaction's `Cleanup`. - **Sync point**: Added `CompactionJob::Run():AfterVerifyOutputFiles` for error injection in tests. - **Unit test**: `DBCompactionTest.LeakedTableCacheEntryOnCompactionFailure` uses `FaultInjectionTestFS` to reproduce the crash test scenario — injects error after `VerifyOutputFiles` and deactivates the filesystem so `GetChildren` fails in `FindObsoleteFiles`, preventing the backstop from evicting the leaked cache entry. Pull Request resolved: meta#14469 Test Plan: - `DBCompactionTest.LeakedTableCacheEntryOnCompactionFailure`: - **Without fix (ASAN)**: assertion fires during `Close()` — `File 12 is not live nor quarantined` - **With fix (ASAN)**: passes — `ReleaseObsolete` properly cleans up the cache entry - **With fix (non-ASAN)**: passes ``` $ COMPILE_WITH_ASAN=1 make -j db_compaction_test $ ./db_compaction_test --gtest_filter="DBCompactionTest.LeakedTableCacheEntryOnCompactionFailure" [ PASSED ] 1 test. ``` Reviewed By: xingbowang Differential Revision: D97190944 Pulled By: joshkang97 fbshipit-source-id: fdfd481cc1e192803cfb7d64052ccb9162c21b94
Tim-Reed
pushed a commit
to Tim-Reed/rocksdb
that referenced
this pull request
Oct 1, 2026
Summary: When CompactionJob::Run() succeeds but Install() fails (e.g., LogAndApply MANIFEST I/O error), compact_->status was never updated with the install failure. CleanupCompaction() passed the stale OK status to SubcompactionState::Cleanup(), which skipped ReleaseObsolete -- leaking table cache entries for output files that were cached by VerifyOutputFiles but never installed into any Version. This is the same class of bug fixed in meta#14469 (where Run() failed after VerifyOutputFiles), but in the Install() failure path. The FindObsoleteFiles full-scan backstop would normally catch this, but fails under crash test metadata read fault injection (--open_metadata_read_fault_one_in), causing the TEST_VerifyNoObsoleteFilesCached assertion to fire during Close(). Fix: propagate Install()'s local status back to compact_->status before CleanupCompaction(), so Cleanup() sees the failure and calls ReleaseObsolete on the output files. Pull Request resolved: meta#14549 Test Plan: New unit test DBCompactionTest.LeakedTableCacheEntryOnInstallFailure: - Without fix (ASAN): assertion fires -- "File 12 is not live nor quarantined" - With fix (ASAN): passes -- ReleaseObsolete properly cleans up the entry ``` COMPILE_WITH_ASAN=1 make -j db_compaction_test ./db_compaction_test --gtest_filter="DBCompactionTest.LeakedTableCacheEntry*" [ PASSED ] 2 tests. ``` Reviewed By: joshkang97 Differential Revision: D99155908 Pulled By: pdillinger fbshipit-source-id: ed5374a38d7903866a38a0fe0f5539e12321bc84
Tim-Reed
pushed a commit
to Tim-Reed/rocksdb
that referenced
this pull request
Oct 1, 2026
Summary: When BuildTable succeeds during flush, it caches the output SST file in the table cache for subsequent user reads (builder.cc:460). If the flush then fails to install — e.g., LogAndApply MANIFEST I/O error, CF dropped, or shutdown — the cache entry was never evicted. BuildTable only cleans up its own failures (builder.cc:511), not failures in the install path. The FindObsoleteFiles full-scan backstop would normally catch this by finding the orphan file on disk and evicting the cache entry. However, under crash test metadata read fault injection (open_metadata_read_fault_one_in), GetChildren fails and the orphan is never found, causing the TEST_VerifyNoObsoleteFilesCached assertion to fire during Close(). This is the same class of bug previously fixed in the compaction path by meta#14469 (Run failure) and meta#14549 (Install failure), but in the flush path which had no analogous cleanup. Fix: call TableCache::ReleaseObsolete in FlushJob::Run() when the flush fails after BuildTable succeeded (meta_.fd.GetFileSize() > 0). Pull Request resolved: meta#14577 Test Plan: New unit test DBFlushTest.LeakedTableCacheEntryOnFlushInstallFailure: - Injects failure after BuildTable via sync point, deactivates filesystem to prevent backstop cleanup - Without fix: assertion fires ("Leaked table cache entry") - With fix: passes ``` COMPILE_WITH_ASAN=1 make -j db_flush_test ./db_flush_test --gtest_filter="DBFlushTest.LeakedTableCacheEntry*" [ PASSED ] 1 test. ``` Existing compaction leak tests still pass: ``` COMPILE_WITH_ASAN=1 make -j db_compaction_test ./db_compaction_test --gtest_filter="*LeakedTableCacheEntry*" [ PASSED ] 2 tests. ``` Reviewed By: xingbowang Differential Revision: D99692601 Pulled By: pdillinger fbshipit-source-id: ff5aa1ad165b3abec915844f97f6af9e59d85774
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.
Summary
Fix leaked table cache entries that cause
TEST_VerifyNoObsoleteFilesCachedassertion failure duringDB::Close()in ASAN crash test builds (T258745630):When a compaction fails after
VerifyOutputFilessucceeds (e.g., atVerifyCompactionRecordCounts), the overallcompact_->statusis set to error but each subcompaction's individualstatusremains OK.SubcompactionState::Cleanuponly checked the individual subcompaction status, so it skipped callingReleaseObsoleteon the output files' table cache entries — leaking them.Normally,
Close()'s backstop (FindObsoleteFiles(force=true)+PurgeObsoleteFiles) would catch this by finding the orphan file on disk, evicting the cache entry, and deleting the file. However,FindObsoleteFilescallsFaultInjectionTestFS::GetChildrenwhich can fail under metadata read fault injection (--open_metadata_read_fault_one_in=8). The error is silently ignored (s.PermitUncheckedError()in db_impl_files.cc:199), so the orphan file is never found and the leaked cache entry is never evicted.The
Cleanupbug is latent and predates recent changes. PR #14433 addedverify_output_flagsrandomization to the crash test, and PR #14456 fixed false-positive corruptions that #14433 caused. Before #14456,VerifyOutputFileswould produce false corruption errors that accidentally prevented the leak by setting the subcompaction status to non-OK.How it triggers
Step 1 — VerifyOutputFiles adds cache entries for compaction output files:
Step 2 — A post-verification step fails, overall status set but NOT subcompaction status:
Step 3 — Install skips InstallCompactionResults (file 12 never enters a Version):
Step 4 — CleanupCompaction skips ReleaseObsolete (THE BUG):
Step 5 — Metadata read fault prevents backstop from finding the orphan:
FindObsoleteFiles(force=true)callsGetChildren()to scan the DB directory.FaultInjectionTestFS::GetChildreninjects a metadata read error(
--open_metadata_read_fault_one_in=8). The error is silently ignored(
s.PermitUncheckedError()), so the directory listing is empty and the orphanfile is never found. This happens both in the post-compaction cleanup
(
BackgroundCallCompaction) and inClose()'s backstop:Step 6 — Assertion fires during Close():
Crash test call stack:
Fix
Pass the overall
compact_->statustoSubcompactionState::Cleanupand callReleaseObsoletewhen either the subcompaction status or the overall statusis non-OK:
Key changes
SubcompactionState::Cleanup: Now takes anoverall_statusparameter and callsReleaseObsoletewhen either the subcompaction status or the overall compaction status is non-OK.CompactionJob::CleanupCompaction: Passescompact_->status(the overall status) to each subcompaction'sCleanup.CompactionJob::Run():AfterVerifyOutputFilesfor error injection in tests.DBCompactionTest.LeakedTableCacheEntryOnCompactionFailureusesFaultInjectionTestFSto reproduce the crash test scenario — injects error afterVerifyOutputFilesand deactivates the filesystem soGetChildrenfails inFindObsoleteFiles, preventing the backstop from evicting the leaked cache entry.Test Plan
DBCompactionTest.LeakedTableCacheEntryOnCompactionFailure:Close()—File 12 is not live nor quarantinedReleaseObsoleteproperly cleans up the cache entry