Skip to content

fix: return Poisoned from write backpressure when a worker died - #359

Open
scarmuega wants to merge 3 commits into
fjall-rs:mainfrom
txpipe:full-volume-poison
Open

scarmuega wants to merge 3 commits into
fjall-rs:mainfrom
txpipe:full-volume-poison

Conversation

@scarmuega

@scarmuega scarmuega commented Nov 22, 2026 •

Copy link
Copy Markdown

When a flush or compaction worker fails (for example, the volume fills up), the database is poisoned and the worker exits. A writer that is in Keyspace::local_backpressure at that moment never comes back: both of its loops wait for workers to make progress, and neither checks the poison flag.

  • the sealed-memtable loop (sealed_memtable_count() >= 4) sleeps until a flush lowers the count, and a failed flush is never retried;
  • the L0 write-halt loop (check_write_halt, l0_run_count() >= 30) sleeps until a compaction lowers L0.

We hit this downstream with a store reopened on a nearly full volume: a writer parked at 0% CPU in local_backpressure, and freeing space afterwards did not wake it, so the process never exits and nothing reports why. A supervisor (a Kubernetes Job, systemd) can only act on a process that stops.

Change

  • local_backpressure returns crate::Result<bool>. Both loops return Error::Poisoned once the database is poisoned. Keyspace::insert, remove, remove_weak (through maintenance) and WriteBatch::commit pass the error on instead of completing the write.
  • The flush and compaction failure logs name the keyspace (they already log the I/O error at error).

A write that reaches backpressure has already been journaled and applied to the memtable when it returns Poisoned; the error does not roll it back. This matches how a persist failure is already reported for journaled writes.

The close path needed no change: since 3.1.13, DatabaseInner::drop drains and uses try_send, so a dead worker no longer parks it. A regression test for that is included.

Tests

tests/dead_worker.rs (Unix only; skipped when running as root, since it makes the tables folder read-only to force the worker failure):

cargo fmt --check is clean and cargo test passes on main plus this branch (macOS); with #326 stacked, all three tests pass in about 1 s.

Related: #326 (both touch check_write_halt / local_backpressure; the conflict between them is trivial).

Summary by CodeRabbit

  • Bug Fixes
    • Writes now surface errors encountered while checking backpressure, including when the database is poisoned, rather than silently continuing.
    • Flush and compaction failure logs now identify the affected keyspace, making errors easier to diagnose.
    • Batch commits now return errors from backpressure checks.

A worker that fails a flush or compaction poisons the database and exits.
A writer already waiting in local_backpressure, for sealed memtables or at
the L0 write halt, then waited forever, since nothing would flush or compact
again. Both loops now return Error::Poisoned, and insert, remove and batch
commit pass it on to the caller.

The tests force the failure with a read-only table folder.
Covers DatabaseInner::drop with a worker that exited on a failed flush, so
the close never waits on a thread that is gone.
A worker that dies of an I/O error logs it, but not which keyspace it was
working on. Put the keyspace in the flush and compaction failure logs.
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Write backpressure now propagates poison errors through keyspace maintenance and batch commits. Flush and compaction failure logs include the keyspace name. Unix-only tests cover blocked writers, the L0 write halt, and database close after worker failure.

Changes: Worker failure handling

Layer / File(s) Summary
Propagate backpressure errors
src/keyspace/mod.rs, src/batch/mod.rs
Backpressure checks and maintenance now return errors when the database is poisoned. Keyspace writes and batch commits propagate those errors.
Report and test worker failures
src/compaction/worker.rs, src/flush/worker.rs, tests/dead_worker.rs
Flush and compaction failure logs now include the keyspace name. Unix-only tests cover blocked writers, the L0 write halt, and database close after a failed worker.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: fix

Suggested reviewers: marvin-j97

Merge Risk: Minimal · up to f210b

Writers blocked behind a failed flush or compaction now get a Poisoned error instead of hanging. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: writes blocked in backpressure now return Error::Poisoned when a flush or compaction worker dies. The raw summary confirms this change in src/keyspace/mod.rs, where ch…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: writes blocked in backpressure now return Error::Poisoned when a flush or compaction worker dies. The raw summary confirms this change in src/keyspace/mod.rs, where check_write_halt and local_backpressure return Result and propagate Error::Poisoned, and maintenance, insert, remove, remove_weak, and WriteBatch::commit pass the error through. The title's 'fix:' prefix fits the stated objective. The title is 63 characters, which is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 969f432b-4470-4aea-9b68-6bed80b6a252
Commits

Reviewing files that changed from the base of the PR and between 8700604 and f210b86.

Files selected for processing: 5

  • src/batch/mod.rs
  • src/compaction/worker.rs
  • src/flush/worker.rs
  • src/keyspace/mod.rs
  • tests/dead_worker.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant