Skip to content

Atomic flush rollback once on failure - #6385

Closed
riversand963 wants to merge 3 commits into
meta:masterfrom
riversand963:atomic-flush-rollback-once-on-failure
Closed

riversand963 wants to merge 3 commits into
meta:masterfrom
riversand963:atomic-flush-rollback-once-on-failure

Conversation

@riversand963

@riversand963 riversand963 commented Feb 7, 2020 •

Copy link
Copy Markdown
Contributor

Before this fix, atomic flush codepath may hit an assertion failure on a specific failure case.
If all flush jobs within an atomic flush succeed (they do not write to MANIFEST), but batch writing version edits to MANIFEST fails, then cfd->imm()->RollbackMemTableFlush() will be called twice, and the second invocation hits assertion failure assert(m->flush_in_progress_) since the first invocation resets the variable flush_in_progress_ to false already.

Test plan (dev server):

./db_flush_test --gtest_filter=DBAtomicFlushTest/DBAtomicFlushTest.RollbackAfterFailToInstallResults
make check

Both must succeed.

@facebook-github-bot facebook-github-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@riversand963 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@riversand963 has updated the pull request. Re-import the pull request

@facebook-github-bot facebook-github-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@riversand963 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@riversand963
riversand963 deleted the atomic-flush-rollback-once-on-failure branch February 7, 2020 19:32
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@riversand963 merged this pull request in f361ced.

Tim-Reed pushed a commit to Tim-Reed/rocksdb that referenced this pull request Oct 1, 2026
Summary:
Before this fix, atomic flush codepath may hit an assertion failure on a specific failure case.
If all flush jobs within an atomic flush succeed (they do not write to MANIFEST), but batch writing version edits to MANIFEST fails, then `cfd->imm()->RollbackMemTableFlush()` will be called twice, and the second invocation hits assertion failure `assert(m->flush_in_progress_)` since the first invocation resets the variable `flush_in_progress_` to false already.

Test plan (dev server):
```
./db_flush_test --gtest_filter=DBAtomicFlushTest/DBAtomicFlushTest.RollbackAfterFailToInstallResults
make check
```
Both must succeed.
Pull Request resolved: meta#6385

Differential Revision: D19782943

Pulled By: riversand963

fbshipit-source-id: 84e1592625e729d1b70fdc8479959387a74cb121
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
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 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
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
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 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 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 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
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
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Dec 1, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Dec 1, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Dec 1, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Dec 1, 2026
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 added a commit to xingbowang/rocksdb that referenced this pull request Dec 1, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants