Repository navigation
Fix table cache leak when flush install fails - #14577
Closed
pdillinger wants to merge 2 commits into
Closed
pdillinger wants to merge 2 commits into
pdillinger wants to merge 2 commits into
Conversation
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. ```
✅ clang-tidy: No findings on changed linesCompleted in 128.2s. |
|
@pdillinger has imported this pull request. If you are a Meta employee, you can view this in D99692601. |
|
@pdillinger merged this pull request in 92cedd5. |
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: 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:
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).
Test Plan:
New unit test DBFlushTest.LeakedTableCacheEntryOnFlushInstallFailure:
Existing compaction leak tests still pass: