Skip to content

wal: reuse the anchor-only tail instead of deleting it - #739

Merged
HagarMeir merged 1 commit into
hyperledger:mainfrom
pfi79:735-2-wal-restart
Oct 26, 2026
Merged

HagarMeir merged 1 commit into
hyperledger:mainfrom
pfi79:735-2-wal-restart

Conversation

@pfi79

@pfi79 pfi79 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Open no longer removes anchor-only tail files. Deleting the last one made
ReadAll create a new file on every restart, so the cleanup and the reuse branch
overlapped. Keep the reuse branch as the only mechanism and drop the now-unused
isAnchorOnlyFile helper.

Strengthen the in-flight proposal restart test to do ten restarts with a flat
file count, correct the partition description, and remove the undefined
requirement IDs from the test comments.

#736

@HagarMeir HagarMeir 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.

Thanks for splitting this out. The fix works, but the two mechanisms overlap: once the WAL has more than one file, Open deletes the anchor-only last file, so ReadAll never reuses it and creates it again on every restart. I suggest keeping only one of the two. Details and a few smaller points are inline.

Written by Claude (an AI assistant) on behalf of @HagarMeir.

Comment thread pkg/wal/writeaheadlog.go Outdated
// anchor-only file leaves the CRC chain of the files before it untouched.
//
// The last file of the WAL is kept even when it is an anchor-only one: an empty WAL still has to be
// a WAL of at least one file, and ReadAll() reuses that file instead of creating a fresh one.

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.

This only holds while the WAL is a single file. With [1 (records), 2 (anchor only)], removeAnchorOnlyTailFiles deletes 2, then ReadAll sees that 1 has records and creates 2 again (create + fsync). The count stays flat, but that's because of delete-and-recreate, not reuse. Maybe have Open remove only the anchor-only files before the last one, or drop the Open cleanup and rely on the reuse branch alone?

Comment thread pkg/wal/writeaheadlog.go Outdated
return nil, err
}

if err = wal.removeAnchorOnlyTailFiles(dirPath); err != nil {

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.

Open used to leave the directory untouched; now it can delete files before any write. The test harness calls Setup() again without closing the previous WAL, so a second Open can unlink the file the old instance is still writing to. Not a production issue as far as I can see, but worth a note in the Open doc.

Comment thread pkg/wal/writeaheadlog.go
return err
}

if lastFileInfo.Size() == crcAnchorRecordSize() {

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.

Here anchor-only means Size() == crcAnchorRecordSize(), while Open uses isAnchorOnlyFile (parse, then expect EOF). Could we use one check for both, so they can't drift apart?

Comment thread test/wal_truncation_test.go Outdated
"the WAL must still carry the same proposal in flight")
// The first restart after a proposal moves the write head to a new file. From
// then on ReadAll reuses that anchor-only file, so further restarts add none.
require.LessOrEqual(t, walLogFileCount(t, walDir), filesBeforeRestart+1,

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.

With a single restart, <= filesBeforeRestart+1 looks like it would pass on main too, since main adds exactly one file per restart. Several restarts with a flat count, or <= filesBeforeRestart, would catch a regression. (Also, the comment above says ReadAll reuses the file, but per the note on writeaheadlog.go it gets recreated.)

Comment thread test/wal_truncation_test.go Outdated
}

// TestRestartingNodeThatDoesNotProposeDoesNotGrowWAL covers R07.1 and R15i on
// real nodes: a node in a network partition neither proposes nor syncs, so its

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.

Nits: Restart() syncs from the shared in-memory ledger whatever the loss probability is, so the node does sync. R07.1/R15i (here and at line 154) aren't defined anywhere in the repo, so they should be dropped or explained.

Open no longer removes anchor-only tail files. Deleting the last one made
ReadAll create a new file on every restart, so the cleanup and the reuse branch
overlapped. Keep the reuse branch as the only mechanism and drop the now-unused
isAnchorOnlyFile helper.

Strengthen the in-flight proposal restart test to do ten restarts with a flat
file count, correct the partition description, and remove the undefined
requirement IDs from the test comments.

Signed-off-by: Fedor Partanskiy <fredprtnsk@gmail.com>
@pfi79
pfi79 force-pushed the 735-2-wal-restart branch from 63c000c to f6a4576 Compare October 26, 2026 10:58
@pfi79 pfi79 changed the title wal: reuse the anchor-only tail file on restart wal: reuse the anchor-only tail instead of deleting it Oct 26, 2026
@pfi79

pfi79 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for splitting this out. The fix works, but the two mechanisms overlap: once the WAL has more than one file, Open deletes the anchor-only last file, so ReadAll never reuses it and creates it again on every restart. I suggest keeping only one of the two. Details and a few smaller points are inline.

Written by Claude (an AI assistant) on behalf of @HagarMeir.

comments have been fix and the description has been changed

@HagarMeir

Copy link
Copy Markdown
Contributor

Thanks, this addresses my comments. A few small things you could fix before merge: the commit message and the description describe the change from the previous revision ("instead of deleting it", "Open no longer removes…") rather than from main, and the same goes for the test comment "Open no longer deletes files". "The audit measurement" and "the regression from the brief" in the test comments could be reworded too.

Written by Claude (an AI assistant) on behalf of @HagarMeir.

@HagarMeir
HagarMeir merged commit a6b84ec into hyperledger:main Oct 26, 2026
6 checks passed
@pfi79
pfi79 deleted the 735-2-wal-restart branch October 26, 2026 14:33
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.

2 participants