Secondary open/catch-up can fail if an obsolete SST disappears during MANIFEST replay with unique-ID verification disabled
Summary
I use a Secondary DB for an external indexer while the primary continues to compact. On RocksDB 11.8.1, both DB::OpenAsSecondary() and TryCatchUpWithPrimary() can fail if an SST is present when MANIFEST replay verifies it, but the primary removes it before the Secondary opens its table reader. In my reproducer, the SST is already obsolete: the primary has compacted its contents into a newer, live SST.
This reproduces with max_open_files = -1 and verify_sst_unique_id_in_manifest = false. The latter is not the default; with its default value (true), both paths pass. I am reporting the narrower non-default configuration, not claiming that the default Secondary configuration has this failure.
Reproduction and result
I added two deterministic DBSecondaryTest cases on top of the unmodified v11.8.1 engine:
- Disable automatic compactions and primary file deletion. Write
foo=oldand flush to SST A; writefoo=newand flush to SST B. - Compact A and B into SST C. A and B are now obsolete, while C contains
foo=new. - Delete B before replay. Use
VersionBuilder::Rep::LoadTableHandlers::BeforeFindTableto delete A immediately before itsFindTablecall. This makes A disappear after the earlier verification saw it. - For the open case, call
DB::OpenAsSecondary()after the primary writes. For the catch-up case, open an empty Secondary before the primary writes, then callTryCatchUpWithPrimary()after step 3. Both usemax_open_files = -1,max_file_opening_threads = 1, and explicitly setverify_sst_unique_id_in_manifesttofalseortruefor an A/B comparison.
Expected: MANIFEST replay can advance past the unavailable historical version and open the latest complete version; reading foo returns new.
Actual with verify_sst_unique_id_in_manifest = false: both DB::OpenAsSecondary() and TryCatchUpWithPrimary() return IOError(kPathNotFound):
IO error: No such file or directory: While open a file for random read: .../000013.sst: No such file or directoryOn unmodified v11.8.1, each path failed 20/20 runs with false and passed 100/100 runs with true. I also removed the explicit assignment and reran the unmodified engine: each path passed another 100/100 runs with the native default. Every successful run read foo=new, and each test asserts that the deletion callback actually fired. This is a Secondary availability failure after primary compaction has completed; it does not demonstrate an incorrect read or primary data corruption.
Code path
VersionBuilder::Rep::ApplyFileAddition()callsManifestTailer::VerifyFile(), which can classify A as present.VersionSet::VerifyFileMetadata()checks its size; whenverify_sst_unique_id_in_manifestis false, it does not open a table reader at this point.- On the valid-to-invalid transition caused by missing B,
VersionEditHandlerPointInTime::MaybeCreateVersionBeforeApplyEdit()tries to materialize the preceding version.LoadTableHandlersHelper()then callsFindTable()for A, which has just been removed. - That point-in-time handler currently skips
CorruptionfromLoadTableHandlers(), but returnsPathNotFound. Replay stops before reaching the newer complete version.ManifestTailer::VerifyFile()already has a TODO to open or link the file so it cannot disappear.
max_open_files = -1 protects table readers after they have been opened; it cannot protect A during this replay window when unique-ID verification is disabled.
Related upstream work
I noticed the open PR #14815, which proposes a different initial Secondary recovery path. It may avoid the open-time case, but I have not run either reproducer against that PR. The catch-up case also needs consideration because it calls ManifestTailer. These tests would be useful regression coverage if that change is adopted.
Possible minimal fix
In the point-in-time handler, when a negative edge is saving a pre-edit candidate and LoadTableHandlers() returns PathNotFound/NotFound, treat that candidate as unavailable and continue replaying the subsequent MANIFEST edits, as the existing Corruption branch does. Keep unrelated I/O errors visible, and do not silently accept a missing SST in the final live version.
I tested that narrow condition locally with verify_sst_unique_id_in_manifest = false: both race tests, the existing MissingTableFileDuringOpen test, and a test injecting a generic table-open IOError each passed 20/20 runs. This is a possible small fix, not a request to weaken error handling generally. Pinning or linking the file during ManifestTailer::VerifyFile() may be a more comprehensive approach if that fits the intended contract better.
Separate default-configuration stale-read result (not the missing-SST race above)
I also checked a different Secondary failure on the unmodified v11.8.1 engine through ckb-rocksdb, without assigning verify_sst_unique_id_in_manifest (its native default is true):
- Primary writes
key=v1and callsFlushWAL(true); Secondary catches up and readsv1. - Primary writes
key=v2and callsFlush(); the same Secondary'sTryCatchUpWithPrimary()returns OK, butGet(key)still returnsv1. A second successful catch-up also returnsv1. - A newly opened Secondary reads
v2.
The same stale result occurs when the Secondary also sets max_open_files=-1. This reproduces the stale-memtable behavior reported separately in #14444 and #15051. The default verify_sst_unique_id_in_manifest=true does not guarantee fresh Secondary reads after a successful catch-up. Conversely, this result does not show that the default option fails the specific obsolete-SST PathNotFound race described in this issue; my 100/100 results for that narrower race still stand. The proposed PathNotFound handling above should not be read as a fix for stale memtables.
Source: facebook/rocksdb