Skip to content

rollback: don't revive pruned deltas on reopen - #973

Open
citizen-stig wants to merge 1 commit into
thrumdev:masterfrom
citizen-stig:nikolai/fix-rollback-reopen-resurrects-pruned
Open

citizen-stig wants to merge 1 commit into
thrumdev:masterfrom
citizen-stig:nikolai/fix-rollback-reopen-resurrects-pruned

Conversation

@citizen-stig

Copy link
Copy Markdown
Contributor

writeout_start returns the live range that goes into the manifest, but it computed that range before pruning, so the manifest could still cover pruned deltas and a reopen loaded them back:

  • Prune: the range kept the pre-prune start, so a reopened log held max_rollback_log_len + 1 deltas. Pruning dropped only one delta per sync, so the log never shrank back.
  • Truncate to empty: the range was min(seglog start, pending_truncate), and pending_truncate then points at the last pruned delta. After a reopen, rollback succeeded one commit past the rollback window.

Repro with max_rollback_log_len(1): commit 1, 2, 3; rollback(1) succeeds and a second one fails; reopen; rollback(1) succeeds again and restores the state after commit 1.

Fix: derive the range from the deltas still in memory ((0, 0) if none), and prune until the log fits max_rollback_log_len, so reopening with a smaller length shrinks the log on the next commit.

Writing the pre-prune start was also unsafe on its own: writeout_end deletes the segments before the new start, which the manifest kept pointing into until the next sync.

Tests (the new ones fail without the fix):

  • rollback::tests::rollback_writeout_truncate_to_empty_after_prune (new). rollback_writeout_start_and_end now expects the post-prune start.
  • tests/rollback.rs: test_rollback_log_len_holds_across_reopen, test_rollback_log_shrinks_to_smaller_len_on_reopen.

Found by the concurrent_rollback fuzz target.

🤖 Generated with Claude Code

`writeout_start` returns the live range the manifest is written with,
before `writeout_end` prunes the log. It returned a range that still
covered pruned deltas, and a reopen loaded them back:

- After pruning the oldest delta it returned the pre-prune start, so a
  reopened log held one delta more than `max_rollback_log_len`. Pruning
  only dropped one delta per sync, so the log never shrank back.
- After a truncate it returned `min(seglog start, pending_truncate)`. When
  the truncate removed every delta, `pending_truncate` points at the last
  pruned delta, so the range revived it. A rollback after reopen then
  succeeded and rewound one commit past the rollback window.

With `max_rollback_log_len(1)`: commit 1, 2, 3, `rollback(1)` succeeds and
a second fails; after a reopen `rollback(1)` succeeded and restored the
state after commit 1.

Derive the range from the deltas still in memory, which is what stays
live, and use (0, 0) when none do. Prune until the log fits its length,
so a log opened with a smaller length shrinks on the next commit.

Writing the pre-prune start was also unsafe on its own: `writeout_end`
deletes the segments before the new start, which the manifest still
pointed into until the next sync.

Found by the concurrent_rollback fuzz target.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@citizen-stig
citizen-stig force-pushed the nikolai/fix-rollback-reopen-resurrects-pruned branch from b082064 to 43b16ba Compare November 24, 2026 22:45
@citizen-stig
citizen-stig marked this pull request as ready for review November 25, 2026 07:58
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