]> git.giacomolli.uk - onechat/commit
Make the chat writes durable by group commit
authorAnderson A. Giacomolli <agiacomolli@gmail.com>
Fri, 6 Nov 2026 21:57:56 +0000 (18:57 -0300)
committerAnderson A. Giacomolli <agiacomolli@gmail.com>
Fri, 6 Nov 2026 21:57:56 +0000 (18:57 -0300)
commit2532718d5288e1a2586fe5716cc41bb2a0210e16
treef637f326f99a588f9e65eee4622282c7b5904500
parentc9183f90d757006e7221ecd0d4dc0db2a25f87e0
Make the chat writes durable by group commit

Each write of a chat still goes to the operating system at once, so a
crash of the process loses nothing. After each write, a background
syncfs of the file system of the chat starts unless one runs already,
and the next one starts when it ends. One sync makes every earlier write
durable, so a power loss loses at most the writes after the start of the
last finished sync, and there is never more than one sync at a time.
Memory.Flush returns when the writes before it are durable, so a caller
can make a tool call durable before the tool runs. A failed sync stays
and fails each later flush, because the kernel can drop the data of a
failed write back.

A crash can stop a write in the middle of a line. The open now cuts a
part of a line at the end of the last day file, whose write never
returned, and still refuses one in an earlier file.

golang.org/x/sys gives syncfs on every Linux architecture. The frozen
syscall package has no syncfs number on amd64.

A test kills a writer child process three times during writes of small
and large messages and finds every acknowledged message after each open.

Issue: 5daf23e
go.mod
go.sum
journal.go
log_test.go
memory.go
nix/package.nix
syncer.go [new file with mode: 0644]
syncer_test.go [new file with mode: 0644]