Repository navigation
Roll back atomic flush memtables when the directory sync fails (#15817) - #15817
Open
xingbowang wants to merge 3 commits into
Open
xingbowang wants to merge 3 commits into
xingbowang wants to merge 3 commits into
Conversation
|
@xingbowang has exported this pull request. If you are a Meta employee, you can view the originating Diff in D134907304. |
✅ clang-tidy: No findings on changed linesCompleted in 617.4s. |
xingbowang
force-pushed
the
export-D134907304
branch
from
November 29, 2026 00:35
fb1fd76 to
eb01ea3
Compare
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 29, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
force-pushed
the
export-D134907304
branch
from
November 29, 2026 00:41
eb01ea3 to
40c5856
Compare
xingbowang
force-pushed
the
export-D134907304
branch
from
November 29, 2026 01:36
40c5856 to
d18d702
Compare
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 29, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 29, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
force-pushed
the
export-D134907304
branch
from
November 30, 2026 18:32
d18d702 to
ef6cd9c
Compare
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
force-pushed
the
export-D134907304
branch
from
November 30, 2026 19:17
ef6cd9c to
c24e958
Compare
… atomic compaction unit covers it
Summary:
## Background
`TimedPut()` writes an entry of type `kTypeValuePreferredSeqno`. It carries its own sequence number and a smaller preferred sequence number, which comes from the write time through the seqno-to-time mapping. When a compaction proves that no older version of the key exists below the output level (`bottommost_level` or `KeyNotExistsBeyondOutputLevel()`), `CompactionIterator` swaps the entry to its preferred sequence number and writes it as a `kTypeValue`. Before the swap, it asks the compaction's range tombstone aggregator whether a tombstone would cover the entry at the preferred sequence number. If one would, it writes the entry unchanged, because a tombstone that is older than the entry must not delete it after the swap.
Compaction can cut its output between two versions of one user key: for example, when a snapshot keeps both versions and the file reaches its size limit, or at a grandparent or TTL cut, or at the start of a range tombstone. Adjacent files of one level that share a boundary user key form one atomic compaction unit (`Compaction::PopulateWithAtomicBoundaries()`). The exception is a file whose largest key is a range tombstone sentinel. When a range tombstone continues into the next file and the next file starts with a different user key, the earlier file ends at a sentinel key (the next file's first user key, `kMaxSequenceNumber`, `kTypeRangeDeletion`). Such a file ends its unit. When the cut falls between two versions of one user key, the earlier file ends at its last point key instead (`CompactionOutputs::AddRangeDels()`). Both files then share that user key and are one unit. When a later compaction reads a file of a unit with two or more files, it truncates the file's range tombstones at the bounds of the whole unit, not at the file's own bounds, because truncating at the shared user key could cut a tombstone between two versions of that key.
## The problem
A compaction reads each non-L0 input level through a `LevelIterator`. The `LevelIterator` adds the range tombstones of a file to the aggregator only when it opens that file. A tombstone in a later file of a multi-file unit is therefore not in the aggregator while the compaction is on a key in an earlier file of that unit, but after truncation at the unit bounds it can cover that key. The covered key can be the shared boundary key, a key before it in the earlier file, or a key from another input level whose range overlaps the unit. When such a key is a `TimedPut()` entry, the tombstone check of the swap passes, the entry is swapped to a preferred sequence number below the tombstone, and the tombstone, which goes to the same output, then covers it.
A worked example, reproduced by a new regression test (the sequence numbers are an example):
```
L6: [k6]
writes: DeleteRange [k2, k8) 102, snapshot S1
TimedPut(k3) 103 preferred seqno 0 (an old write time)
Put(k4, "old") 104, snapshot S2, Put(k4, "new") 105, Put(k7)
compaction 1 (L0 -> L5, cut between the two versions of k4):
L5 file A: k3@103 (kTypeValuePreferredSeqno), k4@105
tombstone dropped: no L6 data under A's range
L5 file B: k4@104, k7, tombstone [k2, k8)102 kept: L6 has k6
A and B share the user key k4, so they are one atomic compaction unit
release S1 and S2
compaction 2 (L5 -> L5, not bottommost):
on k3@103, file B is not open, so the swap check sees no tombstone
swap: k3@0 (kTypeValue)
file B is opened; its tombstone, truncated to the unit start k3, covers k3@0
result: Get(k3) returns NotFound, and a later compaction drops k3@0
```
The value is lost even though the tombstone is older than the write. The crash test found it: a key written with `TimedPut()` was missing after recovery, and the MANIFEST showed a `TimedPut()` entry at the end of one L5 file and a range tombstone that starts at the same user key at the start of the next file, before the compaction that lost the value.
The bug needs all of these:
- a `TimedPut()` entry whose preferred sequence number is below the sequence number of an older range tombstone that covers its key;
- that tombstone in a file of a multi-file atomic compaction unit, in a later file than the entry's key position, with the entry's key inside the unit;
- a compaction with level compaction style whose output level is not the bottommost, and where no level below the output holds the key.
Only level compaction swaps below the bottommost level: `KeyNotExistsBeyondOutputLevel()` returns false for other compaction styles unless the compaction is bottommost. At the bottommost level the swap is safe: a tombstone that is older than the entry is also older than the earliest snapshot there, and bottommost compaction output drops such tombstones. A `Put()` is not affected, because it keeps its own sequence number.
Values that were already lost cannot be recovered. This change protects future compactions only.
## The fix
In a compaction that is not bottommost, `CompactionIterator` does not swap a `kTypeValuePreferredSeqno` entry whose user key is inside a multi-file atomic compaction unit of any non-L0 input level. It writes the entry unchanged, through the existing "not safe to swap" path. The entry keeps its own sequence number, which is newer than the tombstone, so the tombstone cannot cover it. It also keeps its packed preferred sequence number, so a later compaction can still swap it. A bottommost compaction swaps as before, because the swap is safe there (see above).
On the first entry that needs them, the iterator builds the user-key ranges of the units that have two or more files, over all non-L0 input levels, and merges them into sorted, disjoint ranges. A compaction without such entries does not build them. Each lookup is one binary search. The ranges come from `Compaction::boundaries()`, the unit bounds that each `LevelIterator` of this compaction passes with a file when it truncates the file's range tombstones. A file is in a multi-file unit when its unit bounds differ from its own smallest or largest key. So two files that only touch at a range tombstone sentinel stay separate units, as in `Compaction::PopulateWithAtomicBoundaries()`. The ranges also include the last file of each unit, where the swap would be safe, to keep the rule simple.
## Changes visible to existing users
Only for `TimedPut()` entries in a compaction that is not bottommost, with a key inside a multi-file atomic compaction unit: the entry is written unchanged until a later compaction swaps it. Until then:
- it keeps its packed preferred sequence number, 8 more bytes in the value;
- it is not passed to the compaction filter, because `InvokeFilterIfNeeded()` skips `kTypeValuePreferredSeqno`;
- it is not moved to a blob file, because `PrepareOutput()` extracts only `kTypeValue`;
- it is not counted in `num_timed_put_swap_preferred_seqno`.
## Paths checked
- L0 inputs: `VersionSet::MakeInputIterator()` opens every L0 input file when it builds the input iterator and adds its range tombstones at that time, so L0 cannot have the gap. The fix skips L0 units.
- Flush: `CompactionIterator` gets no compaction, so the swap branch never runs.
- Level compactions (automatic, manual, `CompactFiles()`) and remote compaction workers build their input in `MakeInputIterator()`, with one `LevelIterator` per non-L0 level. Subcompactions clip that iterator to their key range and can have the gap too. The ranges come from the inputs of the whole compaction, so they cover every subcompaction.
- `MergeHelper::MergeUntil()` and `CompactionOutputs::AddRangeDels()` also read the aggregator. With a tombstone that is loaded late, they can only keep an entry, or leave a copy of the tombstone out of an output file. A file drops its copy only when nothing older that the tombstone covers can remain.
- Other decisions that consult the aggregator do not lower a sequence number below an unseen tombstone. Sequence number zeroing in `PrepareOutput()` runs only at the bottommost level, where the tombstone is dropped as described above. The first tombstone check of the swap branch uses the entry's own sequence number; missing coverage there can only keep a covered entry, and that entry cannot come back to life, because the dropped copy of the tombstone already required that no snapshot needs the older data.
## Possible follow-ups
- Root cause: when the compaction `LevelIterator` opens a file of a multi-file unit, it could also add the range tombstones of the remaining files of that unit to the aggregator. Every reader of the aggregator would then see the full coverage of the unit, at the cost of opening table readers earlier. This change does not touch the `LevelIterator` or tombstone loading.
- A compaction into a level that is not the bottommost could avoid cutting between a point entry and a range tombstone that start at the same user key, as the bottommost branch of `CompactionOutputs::AddToOutput()` already does. That would remove one source of splits, but not cuts between two versions of a point key, and it cannot repair existing files.
Differential Revision: D134698940
…on inputs Summary: Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those. The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`. The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data: - An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes. - The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level. A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them. Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`. `CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position. Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level. - On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself. - A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction. - Level and FIFO compaction do not filter inputs. The fix is in `Compaction`, so it covers the primary and the remote worker. Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries. Differential Revision: D134907303
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
force-pushed
the
export-D134907304
branch
from
November 30, 2026 19:19
c24e958 to
0979cdf
Compare
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
xingbowang
added a commit
to xingbowang/rocksdb
that referenced
this pull request
Nov 30, 2026
…15817) Summary: Pull Request resolved: meta#15817 With `atomic_flush=true`, a retryable error from the directory sync of a flush can make the DB hang. By default the automatic error recovery hangs. With `max_bgerror_resume_count=0`, a manual `DB::Resume()` hangs instead. Then `DB::Close()` hangs too, so the process has to exit. With the WAL off, a crash can also lose the writes of the failed flush. Background: `DBImpl::AtomicFlushMemTablesToOutputFiles()` runs one flush job per column family, then syncs the output directories, and only then installs all results in one MANIFEST write. If anything fails before the install, the function rolls back the picked memtables (`MemTableList::RollbackMemtableFlush()`), so that a later flush can pick them again. One such flush is the flush of the automatic error recovery (auto resume by `ErrorHandler`). The problem: the directory sync runs inside the branch for "all jobs succeeded". When the sync fails, the function sets the error status there, but the rollback is in the `else` branch of that check. The later rollbacks run only when the status is still OK: the one after a failed wait for the install turn, and the one inside `InstallMemtableAtomicFlushResults()` when the MANIFEST write fails. So no rollback runs. The picked memtables keep their "flush in progress" mark, although nothing was installed and the new SST files are later deleted as obsolete. This is a regression of [PR meta#6385](meta#6385) ("Atomic flush rollback once on failure"), first released in RocksDB 6.8. Before that change, the rollback ran at the end of the function for any error except a dropped column family, which covered a failed directory sync. That change moved the rollback into the `else` branch, to avoid a second rollback after a failed MANIFEST write. Which errors trigger the bug: - A retryable error from the sync becomes a soft error that stops background work, and the automatic recovery starts. With `max_bgerror_resume_count=0`, it is a hard error instead, and writes stop until `DB::Resume()`. In both cases the DB later needs a flush of the stuck memtables. - A non-retryable error from the sync is reported with `BackgroundErrorReason::kFlushNoWAL`, with the WAL on or off. With the default `paranoid_checks=true`, it is a fatal error, and `DB::Resume()` fails at once. The stuck memtables do not change that result. - A failed flush job, or a failed MANIFEST write, is not affected: those paths roll back already. Non-atomic flushes sync the directory inside the flush job and roll back on error. Effect of the stuck memtables: - Later flushes skip that column family while it has no newer immutable memtable. A later atomic flush can still install the other column families and write a larger last sequence number to the MANIFEST. The automatic error recovery does this: it requests a flush of every column family with immutable memtables, but the stuck column family is skipped when the flush job picks memtables. - The recovery then waits forever for the stuck memtable to be flushed (`WaitForFlushMemTables()` in `DBImpl::ResumeImpl()`). `DB::Close()` waits for the recovery: it joins the automatic recovery thread, or waits while a manual `DB::Resume()` is in progress. So `DB::Close()` hangs too. - The stuck column family can never flush again. When a newer memtable is sealed, the next atomic flush picks only the newer one and then waits forever to install it, because the stuck memtable is older. Immutable memtables pile up until writes stop. - With the WAL off (`WriteOptions::disableWAL`), a crash then loses the writes in the stuck memtables, while newer writes to other column families survive. That breaks the atomic flush promise that `DB::Open()` recovery without a WAL gives a consistent point in time across column families. With the WAL on, no data is lost, because the stuck column family keeps its old log number and `DB::Open()` replays its writes from the WAL. A crash test found this with many small atomic flushes and injected metadata write errors, with the WAL off. Fix: run the rollback whenever the status is an error that is not `ShutdownInProgress`, also when the directory sync set the error. The rollback code itself is unchanged. A small side effect: when a flush job returned `ShutdownInProgress` and the directory sync then fails, the rollback runs. That is harmless, because the DB is closing. Compatibility: no format, option or public API change. Only the error path of atomic flush changes. Differential Revision: D134907304
This branch has not been deployed
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:
With
atomic_flush=true, a retryable error from the directory sync of a flushcan make the DB hang. By default the automatic error recovery hangs. With
max_bgerror_resume_count=0, a manualDB::Resume()hangs instead. ThenDB::Close()hangs too, so the process has to exit. With the WAL off, a crashcan also lose the writes of the failed flush.
Background:
DBImpl::AtomicFlushMemTablesToOutputFiles()runs one flush jobper column family, then syncs the output directories, and only then installs
all results in one MANIFEST write. If anything fails before the install, the
function rolls back the picked memtables
(
MemTableList::RollbackMemtableFlush()), so that a later flush can pick themagain. One such flush is the flush of the
automatic error recovery (auto resume by
ErrorHandler).The problem: the directory sync runs inside the branch for "all jobs
succeeded". When the sync fails, the function sets the error status there, but
the rollback is in the
elsebranch of that check. The later rollbacks runonly when the status is still OK: the one after a failed wait for the install
turn, and the one inside
InstallMemtableAtomicFlushResults()when theMANIFEST write fails. So no rollback runs. The picked memtables keep their
"flush in progress" mark, although nothing was installed and the new SST files
are later deleted as obsolete.
This is a regression of
PR #6385 ("Atomic flush
rollback once on failure"), first released in RocksDB 6.8. Before that change,
the rollback ran at the end of the function for any error except a dropped
column family, which covered a failed directory sync. That change moved the
rollback into the
elsebranch, to avoid a second rollback after a failedMANIFEST write.
Which errors trigger the bug:
work, and the automatic recovery starts. With
max_bgerror_resume_count=0,it is a hard error instead, and writes stop until
DB::Resume(). In bothcases the DB later needs a flush of the stuck memtables.
BackgroundErrorReason::kFlushNoWAL, with the WAL on or off. With thedefault
paranoid_checks=true, it is a fatal error, andDB::Resume()fails at once. The stuck memtables do not change that result.
roll back already. Non-atomic flushes sync the directory inside the flush
job and roll back on error.
Effect of the stuck memtables:
memtable. A later atomic flush can still install the other column families
and write a larger last sequence number to the MANIFEST. The automatic error
recovery does this: it requests a flush of every column family with
immutable memtables, but the stuck column family is skipped when the flush
job picks memtables.
(
WaitForFlushMemTables()inDBImpl::ResumeImpl()).DB::Close()waitsfor the recovery: it joins the automatic recovery thread, or waits while a
manual
DB::Resume()is in progress. SoDB::Close()hangs too.sealed, the next atomic flush picks only the newer one and then waits
forever to install it, because the stuck memtable is older. Immutable
memtables pile up until writes stop.
WriteOptions::disableWAL), a crash then loses the writesin the stuck memtables, while newer writes to other column families
survive. That breaks the atomic flush promise that
DB::Open()recoverywithout a WAL gives a consistent point in time across column families. With
the WAL on, no data is lost, because the stuck column family keeps its old
log number and
DB::Open()replays its writes from the WAL.A crash test found this with many small atomic flushes and injected metadata
write errors, with the WAL off.
Fix: run the rollback whenever the status is an error that is not
ShutdownInProgress, also when the directory sync set the error. The rollbackcode itself is unchanged. A small side effect: when a flush job returned
ShutdownInProgressand the directory sync then fails, the rollback runs.That is harmless, because the DB is closing.
Compatibility: no format, option or public API change. Only the error path of
atomic flush changes.
Differential Revision: D134907304