Repository navigation
Quarantine files in a limbo state after a manifest error - #12030
jowlyzhang wants to merge 3 commits into
Conversation
dc25872 to
8305ff5
Compare
bc887a9 to
0d8e211
Compare
|
@jowlyzhang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
0d8e211 to
b2e79a3
Compare
|
@jowlyzhang has updated the pull request. You must reimport the pull request before landing. |
| std::vector<const std::vector<uint64_t>*> files_to_quarantine_if_commit_fail; | ||
| std::vector<uint64_t> limbo_descriptor_log_file_number; |
There was a problem hiding this comment.
Does autovector work for these types?
There was a problem hiding this comment.
autovector works well. Thank you for the suggestion!
| // TODO: when CURRENT file rename fails, should the in memory state | ||
| // continue to be updated to use the new descriptor, should we do: | ||
| // manifest_io_status = io_s; |
There was a problem hiding this comment.
I don't know. The CURRENT rename might have succeeded and returned an error, in which case a restart will look for the new MANIFEST. But if we set manifest_io_status to non-OK it looks like it cleans up the new MANIFEST. I think keeping both like you're doing below is safest although if there's a cleaner way to do it correctly that'd be a welcome improvement.
There was a problem hiding this comment.
Thank you for the detailed context. I agree that keeping both is safest. I removed this TODO since there isn't too much of a follow up needed here.
b2e79a3 to
c5fc849
Compare
|
@jowlyzhang has updated the pull request. You must reimport the pull request before landing. |
|
@jowlyzhang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Thank you for help review the PR. |
|
@jowlyzhang merged this pull request in 509947c. |
Summary: Part of the procedures to handle manifest IO error is to disable file deletion in case some files in limbo state get deleted prematurely. This is not ideal because: 1) not all the VersionEdits whose commit encounter such an error contain updates for files, disabling file deletion sometimes are not necessary. 2) `EnableFileDeletion` has a force mode that could make other threads accidentally disrupt this procedure in recovery. 3) Disabling file deletion as a whole is also not as efficient as more precisely tracking impacted files from being prematurely deleted. This PR replaces this mechanism with tracking such files and quarantine them from being deleted in `ErrorHandler`. These are the types of files being actively tracked in quarantine in this PR: 1) new table files and blob files from a background job 2) old manifest file whose immediately following new manifest file's CURRENT file creation gets into unclear state. Current handling is not sufficient to make sure the old manifest file is kept in case it's needed. Note that WAL logs are not part of the quarantine because `min_log_number_to_keep` is a safe mechanism and it's only updated after successful manifest commits so it can prevent this premature deletion issue from happening. We track these files' file numbers because they share the same file number space. Pull Request resolved: meta#12030 Test Plan: Modified existing unit tests Reviewed By: ajkr Differential Revision: D51036774 Pulled By: jowlyzhang fbshipit-source-id: 84ef26271fbbc888ef70da5c40fe843bd7038716
Summary: Background: when a MANIFEST write fails, RocksDB cannot know whether the failed edit is in the MANIFEST that CURRENT names. For example, the record can be written and synced before the error is reported. Or a batch can create a new MANIFEST, rename CURRENT to it, and then get an error from the directory sync. So `VersionSet::ProcessManifestWrites()` puts the new files of the failed batch (the edits of one `ProcessManifestWrites()` call) in the error handler quarantine, and the purge of obsolete files does not delete them. When a MANIFEST write fails, `ProcessManifestWrites()` also resets `descriptor_log_`, and a batch without a `descriptor_log_` sets `new_descriptor_log`. So the next batch that writes the MANIFEST always starts a new MANIFEST. Once that new MANIFEST is installed, the old one is no longer used, and the quarantine is cleared. `VersionSet::io_status_` keeps the MANIFEST write error until then. How the code got into this state: - Since meta#7034, `ProcessManifestWrites()` resets `io_status_` after any call whose MANIFEST I/O status is OK. It records only the first error. - meta#12030 added the quarantine. It added the files of a failed batch only inside the "first error" block, and it cleared the quarantine together with the reset of `io_status_`. At that time `SetOptions()` still wrote to the MANIFEST. - meta#13384 made `SetOptions()` skip the MANIFEST write. So every `SetOptions()` became a call with an OK MANIFEST I/O status that writes no new MANIFEST. The problems: 1. Two kinds of calls have an OK MANIFEST I/O status but write no new MANIFEST: - `DBImpl::SetOptions()` installs a new Version through `LogAndApply()` with an edit that writes nothing to the MANIFEST (`skip_manifest_write`). - A batch can fail before any MANIFEST I/O, for example when `LoadTableHandlers()` fails with `paranoid_checks`. A compaction that is already running when a flush's MANIFEST write fails still commits, because the background error is checked only when the compaction starts. After such a call, the old MANIFEST can still hold the failed edit, but its files are no longer quarantined. 2. A second failed MANIFEST write, while `io_status_` already holds an earlier error, does not quarantine its own files. This is a problem when the second batch creates a new MANIFEST and renames CURRENT to it, and then reports an error. CURRENT names the new MANIFEST, and it lists the new files. In both cases, the purge after the failed job, or the purge in a clean `Close()`, deletes the files. When CURRENT names a MANIFEST that lists a deleted file, every `DB::Open()` fails with "Corruption: IO error: No such file or directory ... .sst The file MANIFEST-... may be corrupted". A db_stress crash test hit problem 1: a flush's MANIFEST write got an injected write error, a `SetOptions()` ran about 1.6 ms later and cleared the quarantine, the flush job deleted its SST, and the harness killed the process. This change cannot repair a DB that already lost such an SST. Example of problem 2, reproduced by the new unit test: ``` 1. DropColumnFamily(): the MANIFEST record is synced, then the write reports an error. io_status_ = that error. No background error is set. 2. (optional) SetOptions() succeeds. 3. Flush: starts a new MANIFEST that lists the flushed SST, renames CURRENT to it, then SetCurrentFile() reports an error. io_status_ is already bad, so the SST is not quarantined. 4. The flush job's purge deletes the SST. The next DB::Open() fails. ``` Without step 2, upstream fails this way. With step 2, upstream passes, because `SetOptions()` resets `io_status_` before the flush, so the flush failure is the "first" error. Fixing problem 1 alone would make the run with step 2 fail too, because `SetOptions()` would no longer reset `io_status_`. So this change fixes both problems. New behavior: - Every MANIFEST write failure adds the files of its batch to the quarantine. `io_status_` keeps the first error. A file number is added only once, because automatic recovery can retry many times, each retry adds the old MANIFEST again, and each `FindObsoleteFiles()` copies the list. - `io_status_` is reset and the quarantine is cleared only when the call wrote and installed a new MANIFEST (s is OK and `new_descriptor_log` is set). A batch that skips the MANIFEST write never sets `new_descriptor_log`. Until then, the files stay quarantined. This is enough for recovery: because `descriptor_log_` was reset, the next real MANIFEST write (for example, a non-atomic flush, a compaction, or the forced write in `DB::Resume()`) starts a new MANIFEST, and its success clears the whole quarantine. - `DBImpl::SetOptions()` sets no background error after its `LogAndApply()` (a related cleanup). Since meta#13384, that call does no MANIFEST I/O and is never grouped with other writers, so a non-OK `io_status()` there always belongs to another, earlier batch. The block only reported that old error again. After a failed `DropColumnFamily()`, which sets no background error, a `SetOptions()` call with an invalid value would have stopped the DB with the old error. This change closes both problems above: the `SetOptions()` trigger, the "failure before MANIFEST I/O" trigger, and the second failed MANIFEST write, with or without a `SetOptions()` in between. The same rule also covers a running compaction whose commit fails at the CURRENT step after a flush's MANIFEST write failed (derived from the code, not tested separately). Consequences: - Quarantined files can stay longer, until the next new MANIFEST or a reopen. This only delays their deletion. - `DB::Resume()` writes a new MANIFEST when `versions_->io_status()` is an `IOError`. Without this change, a `SetOptions()` before the `Resume()` made it skip that write. With this change the write happens, and it clears the quarantine. - After an earlier MANIFEST write error, a later failure that is not a MANIFEST I/O error still sees the old `IOError` in `versions_->io_status()`. Callers then report that old error as a MANIFEST write error. Examples: - An atomic flush fails before its install because of that old error. This was already true between the failure and the next OK call. This change adds the case after a `SetOptions()`. The flush can install only after a new MANIFEST is written, for example by `DB::Resume()`. - A running compaction whose commit fails before MANIFEST I/O, for example with `Corruption` from `LoadTableHandlers()`, reports the old `IOError` with reason `kManifestWrite` instead of its own `Corruption`. The background error then has the severity of the old error (for example fatal instead of unrecoverable). The impact is low, because the outputs of that compaction were never committed. - No API, option or format change. Differential Revision: D134907305
Summary: Background: when a MANIFEST write fails, RocksDB cannot know whether the failed edit is in the MANIFEST that CURRENT names. For example, the record can be written and synced before the error is reported. Or a batch can create a new MANIFEST, rename CURRENT to it, and then get an error from the directory sync. So `VersionSet::ProcessManifestWrites()` puts the new files of the failed batch (the edits of one `ProcessManifestWrites()` call) in the error handler quarantine, and the purge of obsolete files does not delete them. When a MANIFEST write fails, `ProcessManifestWrites()` also resets `descriptor_log_`, and a batch without a `descriptor_log_` sets `new_descriptor_log`. So the next batch that writes the MANIFEST always starts a new MANIFEST. Once that new MANIFEST is installed, the old one is no longer used, and the quarantine is cleared. `VersionSet::io_status_` keeps the MANIFEST write error until then. How the code got into this state: - Since meta#7034, `ProcessManifestWrites()` resets `io_status_` after any call whose MANIFEST I/O status is OK. It records only the first error. - meta#12030 added the quarantine. It added the files of a failed batch only inside the "first error" block, and it cleared the quarantine together with the reset of `io_status_`. At that time `SetOptions()` still wrote to the MANIFEST. - meta#13384 made `SetOptions()` skip the MANIFEST write. So every `SetOptions()` became a call with an OK MANIFEST I/O status that writes no new MANIFEST. The problems: 1. Two kinds of calls have an OK MANIFEST I/O status but write no new MANIFEST: - `DBImpl::SetOptions()` installs a new Version through `LogAndApply()` with an edit that writes nothing to the MANIFEST (`skip_manifest_write`). - A batch can fail before any MANIFEST I/O, for example when `LoadTableHandlers()` fails with `paranoid_checks`. A compaction that is already running when a flush's MANIFEST write fails still commits, because the background error is checked only when the compaction starts. After such a call, the old MANIFEST can still hold the failed edit, but its files are no longer quarantined. 2. A second failed MANIFEST write, while `io_status_` already holds an earlier error, does not quarantine its own files. This is a problem when the second batch creates a new MANIFEST and renames CURRENT to it, and then reports an error. CURRENT names the new MANIFEST, and it lists the new files. In both cases, the purge after the failed job, or the purge in a clean `Close()`, deletes the files. When CURRENT names a MANIFEST that lists a deleted file, every `DB::Open()` fails with "Corruption: IO error: No such file or directory ... .sst The file MANIFEST-... may be corrupted". A db_stress crash test hit problem 1: a flush's MANIFEST write got an injected write error, a `SetOptions()` ran about 1.6 ms later and cleared the quarantine, the flush job deleted its SST, and the harness killed the process. This change cannot repair a DB that already lost such an SST. Example of problem 2, reproduced by the new unit test: ``` 1. DropColumnFamily(): the MANIFEST record is synced, then the write reports an error. io_status_ = that error. No background error is set. 2. (optional) SetOptions() succeeds. 3. Flush: starts a new MANIFEST that lists the flushed SST, renames CURRENT to it, then SetCurrentFile() reports an error. io_status_ is already bad, so the SST is not quarantined. 4. The flush job's purge deletes the SST. The next DB::Open() fails. ``` Without step 2, upstream fails this way. With step 2, upstream passes, because `SetOptions()` resets `io_status_` before the flush, so the flush failure is the "first" error. Fixing problem 1 alone would make the run with step 2 fail too, because `SetOptions()` would no longer reset `io_status_`. So this change fixes both problems. New behavior: - Every MANIFEST write failure adds the files of its batch to the quarantine. `io_status_` keeps the first error. A file number is added only once, because automatic recovery can retry many times, each retry adds the old MANIFEST again, and each `FindObsoleteFiles()` copies the list. - `io_status_` is reset and the quarantine is cleared only when the call wrote and installed a new MANIFEST (s is OK and `new_descriptor_log` is set). A batch that skips the MANIFEST write never sets `new_descriptor_log`. Until then, the files stay quarantined. This is enough for recovery: because `descriptor_log_` was reset, the next real MANIFEST write (for example, a non-atomic flush, a compaction, or the forced write in `DB::Resume()`) starts a new MANIFEST, and its success clears the whole quarantine. - `DBImpl::SetOptions()` sets no background error after its `LogAndApply()` (a related cleanup). Since meta#13384, that call does no MANIFEST I/O and is never grouped with other writers, so a non-OK `io_status()` there always belongs to another, earlier batch. The block only reported that old error again. After a failed `DropColumnFamily()`, which sets no background error, a `SetOptions()` call with an invalid value would have stopped the DB with the old error. This change closes both problems above: the `SetOptions()` trigger, the "failure before MANIFEST I/O" trigger, and the second failed MANIFEST write, with or without a `SetOptions()` in between. The same rule also covers a running compaction whose commit fails at the CURRENT step after a flush's MANIFEST write failed (derived from the code, not tested separately). Consequences: - Quarantined files can stay longer, until the next new MANIFEST or a reopen. This only delays their deletion. - `DB::Resume()` writes a new MANIFEST when `versions_->io_status()` is an `IOError`. Without this change, a `SetOptions()` before the `Resume()` made it skip that write. With this change the write happens, and it clears the quarantine. - After an earlier MANIFEST write error, a later failure that is not a MANIFEST I/O error still sees the old `IOError` in `versions_->io_status()`. Callers then report that old error as a MANIFEST write error. Examples: - An atomic flush fails before its install because of that old error. This was already true between the failure and the next OK call. This change adds the case after a `SetOptions()`. The flush can install only after a new MANIFEST is written, for example by `DB::Resume()`. - A running compaction whose commit fails before MANIFEST I/O, for example with `Corruption` from `LoadTableHandlers()`, reports the old `IOError` with reason `kManifestWrite` instead of its own `Corruption`. The background error then has the severity of the old error (for example fatal instead of unrecoverable). The impact is low, because the outputs of that compaction were never committed. - No API, option or format change. Differential Revision: D134907305
Part of the procedures to handle manifest IO error is to disable file deletion in case some files in limbo state get deleted prematurely. This is not ideal because: 1) not all the VersionEdits whose commit encounter such an error contain updates for files, disabling file deletion sometimes are not necessary. 2)
EnableFileDeletionhas a force mode that could make other threads accidentally disrupt this procedure in recovery. 3) Disabling file deletion as a whole is also not as efficient as more precisely tracking impacted files from being prematurely deleted. This PR replaces this mechanism with tracking such files and quarantine them from being deleted inErrorHandler.These are the types of files being actively tracked in quarantine in this PR:
Note that WAL logs are not part of the quarantine because
min_log_number_to_keepis a safe mechanism and it's only updated after successful manifest commits so it can prevent this premature deletion issue from happening.We track these files' file numbers because they share the same file number space.
Test plan:
Modified existing unit tests