Skip to content

tests: reopen after the failed hash-table write in ht_write_error - #1005

Draft
citizen-stig wants to merge 12 commits into
thrumdev:masterfrom
citizen-stig:nikolai/ht-re-open-error
Draft

citizen-stig wants to merge 12 commits into
thrumdev:masterfrom
citizen-stig:nikolai/ht-re-open-error

Conversation

@citizen-stig

Copy link
Copy Markdown
Contributor

Stacked on #998. Only the last commit (ae68fbc) is new; the rest of the diff is #998 and goes away once that merges.

tests/ht_write_error.rs makes the hash-table page writes of a commit fail. Since #998 keeps the WAL when that happens, the commit reports the failure, and the test returned at that point. So it never checked what keeping the WAL is for: the commit's meta is written, its merkle pages are only in the WAL, and reopening has to replay them.

Changing SyncController::post_meta to truncate the WAL although the write failed left every test green.

Change

After the reported failure the test now reopens the database and compares it with a database that made the same commits without the fault:

  • the root;
  • every balance;
  • the root of one more commit that touches every account. The root after opening is read from the root page alone, so this is the check that sees the other merkle pages.

A commit that reports success is now a failure of the test. The limit makes writes past 40 MiB fail on every run, so the branch that tolerated a reported success never ran.

Testing

  • The test passes on hardening tests and fixes #998.
  • With the WAL truncated despite the error, it fails at the first comparison: the reopened root is not the root of the failed commit.

🤖 Generated with Claude Code

citizen-stig and others added 12 commits November 23, 2026 16:37
New branch and leaf nodes were written with a raw page pointer and kept
alive through deferred_drop_pages until all I/O was drained. If an I/O
error made update return early, the nodes could be freed while their
writes were still in flight.

Let the write command hold an Arc to the node instead, and remove the
deferred drop bookkeeping.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
LeafUpdater::keep_up_to returned early when there were no cells to keep
before the updated key, which skipped reclaiming the overflow pages of
the cell being replaced. This happens for the first key of a leaf and
for consecutive updated keys, and leaked those overflow pages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
write_ht ignored the results of the page writes, so post-meta truncated
the WAL even if some pages never reached the hash table. Drain all
writes and return the first error, which keeps the WAL for recovery.

Recovery parsed the whole WAL before checking its sequence number, so a
WAL left incomplete by a sync that never concluded made opening fail.
Read only the header first and discard a WAL from another sync without
parsing it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Stop at the manifest's last live record. A crash during an append can
  leave an incomplete record after it, which recovery used to reject.
- Check for gaps in segment IDs only up to the end of the live range,
  because an interrupted recovery may leave gaps among the segments
  after it.
- Check that live records are contiguous across segment boundaries.
  The first live record may come after the manifest's start, because
  that start can be an expired record whose segment was already pruned.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- After truncating, the new end of the live range was the record before
  the earliest removed delta. When every retained delta was removed,
  that record had already expired: it either came back after reopening,
  or pruning failed if its segment was already gone. Use the last
  retained delta, or nil.
- max_rollback_log_len(0) made the rollback sync thread panic on the
  first commit. Reject it in the setter, like io_workers(0).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Several commit paths returned on the first error while sibling tasks or
submitted writes were still running: leaf and branch workers, the I/O
completions in update, the bbn/ln fsyncs, the bitbox WAL writeout, and
the post-meta cleanup in Sync. Wait for all of them and then return the
first error.

Also poison the store when a commit unwinds, not only when it returns
an error.

Ported from 7be9540. Sync::sync changed on master since: it already
waits for both preparations before the meta write, so that part is
dropped. After the meta write the rollback cleanup is now awaited before
the beatree task is joined, so that neither an error from the hash-table
writeout nor a panic in the beatree task skips it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Mythos 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_017wb3qEshHAdfkLFsmMCXfc
Each of these fails on master and passes on this branch.

- ht_write_error: every hash-table page write past 40 MiB fails
  (RLIMIT_FSIZE). The commit must report it; before 4eb47b5 it returned
  Ok and the reopened database had a different root.
- overflow_leak: one 256 KiB value rewritten 300 times must not grow the
  leaf file beyond its first 32 MiB step (bc936da).
- commit_panic: a commit that panics after the meta write is durable and
  a later commit attempt on the same handle must not destroy it
  (7be9540, poison on unwind).

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_017wb3qEshHAdfkLFsmMCXfc
The test opened the database on the test thread and moved it, with its
open session, into a helper thread for the commit that is expected to
fail, so that a hang could be reported. A session is about to be tied to
the thread that created it, and the test would no longer compile.

Do all the database work on the helper thread.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_017wb3qEshHAdfkLFsmMCXfc
Replaces the hand-rolled read loop. The caller only recovers from a
non-empty WAL, which is now asserted in debug builds.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
The test stopped as soon as the commit reported the failure, which is
what happens since the WAL is kept on a failed hash-table write. So it
never checked what that fix is for: the commit's meta is written, its
merkle pages are only in the WAL, and reopening has to replay them.
Truncating the WAL despite the error left every test green.

Reopen after the failure and compare with a database that made the same
commits without the fault: the root, every balance, and the root of one
more commit that touches every account. The root after opening is read
from the root page alone, so the last check is the one that sees the
other merkle pages.

A commit that reports success is now a failure of the test. The limit
makes writes past 40 MiB fail on every run, so that branch never ran.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
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