Skip to content

fix(journal): replay a record only while other nodes have not changed what it touches - #80

Merged
mattmattox merged 6 commits into
mainfrom
claude/journal-replay-guards
Nov 13, 2026
Merged

mattmattox merged 6 commits into
mainfrom
claude/journal-replay-guards

Conversation

@mattmattox

@mattmattox mattmattox commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

A peer takes a dead node's locks after 15 s, without waiting for the dead node's journal to be replayed. Each replayed record must therefore be safe on its own, whatever happened after the crash. When a record finds what it touches changed since it was logged, replay now skips the record. The worst case is then a leak, not freeing or remapping another node's data.

Within one transaction, a record also accepts the generation that the replay itself wrote. For example, an unlink's ExtentFree writes the inode, and its InodeDelete still applies.

Audit

Record Written by Can a later change by another node make replay wrong? Guard
InodeDelete unlink, rmdir Yes: it freed a new file in a reused slot (reproduced in #78) Logs MetaGeneration; FreeIf checks it under the inode lock
InodeCreate create, mkdir Yes: it recreated a file another node deleted Logs the free slot's generation; ClaimSlotIf claims only if unchanged
DirAddEntry create, mkdir Yes: a second name for another node's inode, or a deleted file back Applies only if this transaction's InodeCreate applied; skips a removed parent
DirRemoveEntry unlink, rmdir Yes: removed a new file's name Logs the child's generation; removes only if the name still points to that inode at that generation
ExtentAdd write Yes: remapped blocks a truncate freed, maybe to another file by then Logs generation and the write's size; replay also sets the size, so blocks are not hidden past EOF
ExtentFree truncate, unlink Guarded in #78 Frees everything past the logged size; drops the extent list and the 256-extent cap
InodeUpdate several No: replay does nothing none
SFBMigrate SFB migration No: no replay handler none
BlockFree older builds No: replay does nothing since #78 none
BlockAlloc never written Worst case a leak none
ExtentRemove never written Would unmap unguarded Handler removed
DirRename, Snapshot*, RefCountUpdate, SFBAlloc/Free never written No handler none

Folded-in follow-ups from #78

Residual gaps

  • The DirAddEntry, DirRemoveEntry and extent checks read before the change, not under the same lock. A peer change in that gap of milliseconds can slip through, although extent writes do retry on a tree conflict.
  • A skipped record can leak. fsck -repair frees leaked blocks, but only reports orphan inodes.
  • Records from older builds have no generations, so their guarded replay skips.
  • Create adds the name before it claims the slot. A crash between the two leaves a name for a free slot that another node can claim. This is the create's ordering, not replay; follow-up.

Results at 86471d3

🤖 Generated with Claude Code

mattmattox and others added 6 commits November 13, 2026 05:46
…eration left it

A peer can take a dead node's locks before replaying its journal, so a
record must not undo or repeat changes other nodes made since. InodeCreate,
InodeDelete, DirRemoveEntry and ExtentAdd now log generations and replay
checks them; DirAddEntry replays only with its inode's create. ExtentFree
frees everything past the logged size, which removes the 256-extent cap.
Root unlink and rmdir now share the subdirectory path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ashes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Subdirectory rmdir freed an inode only at link count 1, but directories
start at 2, so their inodes leaked. Root rmdir now shares this path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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