Repository navigation
Conversation
Summary: Add two secondary tests for a table cache entry leak that 1192897 (meta#14914) fixed as a side effect. That commit added the eviction in `VersionBuilder::UnrefFile` for a failed `LogAndApply` on a primary, and its test detects a leaked entry only through `TEST_VerifyNoObsoleteFilesCached`, which returns early unless `kMustFreeHeapAllocations`, so no build without ASAN covers the eviction. The leak needs a secondary catch-up round that applies both the MANIFEST record adding a file and the record deleting it. While `verify_sst_unique_id_in_manifest` is set, the add puts a table reader in the cache through `VersionSet::VerifyFileMetadata` and releases the handle without erasing it, and the file never reaches a `Version`, so `FindObsoleteFiles` and `TableCache::ReleaseObsolete` never see it. With `max_open_files=-1` nothing evicts it for capacity, so each such file cost a secondary a `TableReader` and an fd for the life of the process. A 10.x fork hit this in production, where files that live less than one catch-up interval leak steadily. Test Plan: With the `TableCache::Evict` call in `UnrefFile` removed, `FilesAddedAndDeletedInOneCatchUp` reports a table cache of {13, 15, 16, 17} against a live set of {17}, and `NoGrowthOverRepeatedCatchUps`, which repeats five rounds, ends with 16 entries for 1 live file. Nothing else in `db_secondary_test` (91 tests) fails, and `version_builder_test` (31 tests) still passes in full, including `IngestExternalFileEvictsTableCacheOnLogAndApplyFailure`. Clearing `verify_sst_unique_id_in_manifest` in the fixture drops `NO_FILE_OPENS` from 4 to 1 and fails the new guard, so the absent cache entries cannot pass vacuously. `make check` and `ASSERT_STATUS_CHECKED=1 make check` pass.
✅ clang-tidy: No findings on changed linesCompleted in 264.2s. |
✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 833dacf SummaryWell-structured regression tests for a real production leak. The test design is sound: it correctly triggers the leak scenario (secondary catch-up applying both add and delete for the same file) and verifies that table cache entries are properly cleaned up. High-severity findings (0): No high-severity findings. Full review (click to expand)Findings🟡 MEDIUMM1.
|
| Context | Does code execute? | Assumptions hold? | Action needed? |
|---|---|---|---|
| BlobFileCache shared cache | Test does not create blobs | Yes — enable_blob_files=false by default |
None |
| WritePreparedTxnDB | N/A (test-only) | N/A | None |
| ReadOnly DB | N/A | N/A | None |
| User-defined timestamps | N/A | N/A | None |
| MANIFEST rotation | Primary uses default max_manifest_file_size (MAX) |
All records stay in one MANIFEST | None |
Assumption stress-test:
-
Claim: "Files added and deleted in one catch-up never reach a Version." Verified: the secondary hasn't caught up between the primary's flushes and compaction, so the VersionBuilder processes all MANIFEST records (flush adds + compaction add/delete) in one pass. The two flushed L0 files are added then deleted within the same
LogAndApplysequence, soUnrefFilehandles their cleanup. The defaultmax_manifest_file_sizeis very large, so no MANIFEST rotation splits the records. -
Claim: "ASSERT_EQ(2, deleted.size()) — exactly 2 files deleted." Verified: round 0 starts with no existing files. Two flushes create two L0 files.
CompactRangewithkForcecompacts them into one L1 file. The two L0 files are deleted. No prior L1 file exists to be replaced. -
Claim: "The final EXPECT_EQ also covers the intermediate compaction output." Verified: the compaction output is a live file and should appear in both
LiveTableFileNumbersandTableCacheFileNumbers. If the eviction were too aggressive (evicting live files), this check would catch it.
Positive Observations
-
Non-vacuous testing guard: The
NO_FILE_OPENS >= deleted.size() + 1assertion is a clever guard against the test passing vacuously whenverify_sst_unique_id_in_manifestis not actually causing file opens. The PR description confirms that setting the option to false drops the count and fails the guard. -
Proper handle cleanup: The test correctly releases the cache handle when
Lookupreturns non-null (lines 3080-3082), preventing a handle leak that would mask the cache entry issue. -
Good use of
ASSERT_NO_FATAL_FAILURE: Setup and verification steps that useASSERT_*internally are correctly wrapped inASSERT_NO_FATAL_FAILUREto propagate fatal failures to the test body. -
Complementary test coverage: The two tests cover different aspects —
FilesAddedAndDeletedInOneCatchUpverifies per-entry eviction, whileNoGrowthOverRepeatedCatchUpsverifies no unbounded growth over time. Together they provide strong regression coverage. -
SCOPED_TRACEusage: The second test usesSCOPED_TRACEto identify the failing round, which is good practice for loop-based tests.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
Summary:
Add two secondary tests for a table cache entry leak that 1192897
(#14914) fixed as a side effect. That commit added the eviction in
VersionBuilder::UnrefFilefor a failedLogAndApplyon a primary,and its test detects a leaked entry only through
TEST_VerifyNoObsoleteFilesCached, which returns early unlesskMustFreeHeapAllocations, so no build without ASAN covers theeviction.
The leak needs a secondary catch-up round that applies both the
MANIFEST record adding a file and the record deleting it. While
verify_sst_unique_id_in_manifestis set, the add puts a table readerin the cache through
VersionSet::VerifyFileMetadataand releases thehandle without erasing it, and the file never reaches a
Version, soFindObsoleteFilesandTableCache::ReleaseObsoletenever see it.With
max_open_files=-1nothing evicts it for capacity, so each suchfile cost a secondary a
TableReaderand an fd for the life of theprocess. A 10.x fork hit this in production, where files that live less
than one catch-up interval leak steadily.
Test Plan:
With the
TableCache::Evictcall inUnrefFileremoved,FilesAddedAndDeletedInOneCatchUpreports a table cache of{13, 15, 16, 17} against a live set of {17}, and
NoGrowthOverRepeatedCatchUps, which repeats five rounds, ends with 16entries for 1 live file. Nothing else in
db_secondary_test(91 tests)fails, and
version_builder_test(31 tests) still passes in full,including
IngestExternalFileEvictsTableCacheOnLogAndApplyFailure.Clearing
verify_sst_unique_id_in_manifestin the fixture dropsNO_FILE_OPENSfrom 4 to 1 and fails the new guard, so the absentcache entries cannot pass vacuously.
make checkandASSERT_STATUS_CHECKED=1 make checkpass.