Skip to content

Follow mode records the pages each applied file wrote, and keeps the position reached before an apply error - #6

Merged
jsas merged 3 commits into
c4x/mainfrom
c4x/follow-pages
Nov 17, 2026
Merged

jsas merged 3 commits into
c4x/mainfrom
c4x/follow-pages

Conversation

@jsas

@jsas jsas commented Nov 17, 2026 •

Copy link
Copy Markdown

Summary

Two changes to follow mode (restore -f), both aimed at a consumer that serves reads from a copy of the follow file.

  • Follow mode keeps the position reached before an apply error. A poll applies each new LTX file in turn and writes the -txid sidecar when the poll completes. When a later file of the poll failed, the files already applied stayed in the database but the position was not written, and a gap-fill dropped the position it had reached. The next poll applied the earlier files again, over pages that newer files had since written, so between two of those applies the database held pages of different transactions. The poll now writes the position it reached before it reports the error, and a gap-fill returns its progress together with its error.
  • -follow-pages records the pages each applied file wrote. With the flag (RestoreOptions.FollowPages), follow mode appends to the <output>-pages sidecar one partial record before an LTX file's first page write and one ok record after its last, both while the database file is locked for the apply. A record is one line: <minTXID> <maxTXID> <commit> <ok|partial> <pages>, with the pages as ascending ranges, for example 0000000000000014 0000000000000015 12 ok 2,4-6,9. A consumer that holds the database file against the apply reads a record for every page the file contains, can copy only those pages into its own copy, and sees a trailing partial record exactly when an apply did not complete. The sidecar is opened in append mode for each record, so the consumer may truncate it while it holds the file. The flag requires -f; follow mode without it is unchanged.

Observed

A reader that copies the whole follow file after every applied batch moved 650 MiB for a one-row change on a 733 MiB database. With the page records the copy is the pages the batch wrote.

Tests

  • TestReplica_Follow_ErrorKeepsPositionReached and TestReplica_ApplyNewLTXFiles_GapFillErrorKeepsPositionReached fail on the current code (the applied file is opened on every poll; the gap-fill reports the position it started from) and pass with the change.
  • TestApplyLTXFile_FollowPages: the two records and their ranges, an append after the consumer truncated the file, a failed apply leaving the partial record last, an unwritable sidecar applying no page, and no sidecar without the flag.
  • TestReplica_Restore_FollowPagesRequiresFollow.
  • TestReplica_Restore_Follow_Pages: against a real database and the file replica, copying the recorded pages onto a copy taken before the apply reproduces the follow file byte for byte.

The full suites of the root, internal and cmd/litestream packages pass.

Toolchain

go.mod moves the toolchain pin from go1.26.10 to go1.26.11 for GO-2026-6859 (an HTTP/1 server crash in net/http, fixed in go1.26.11). The workflows read the Go version from go.mod; no other file names the version. The root, internal and cmd/litestream suites, gofmt -l and go vet pass under go1.26.11.

james added 2 commits November 16, 2026 20:54
A follow poll applies each new LTX file in turn and writes the -txid
sidecar once the poll completes. When a later file of the poll failed,
the files already applied stayed in the database but the position was
not written, and a gap-fill dropped the position it had reached. The
next poll applied the earlier files again, over pages that newer files
had since written, so between two of those applies the database held
pages of different transactions. The poll now writes the position it
reached before it reports the error, and a gap-fill returns its
progress together with its error.
With -follow-pages (RestoreOptions.FollowPages), follow mode appends to
the <output>-pages sidecar one "partial" record before an LTX file's
first page write and one "ok" record after its last, both while the
database file is locked for the apply. An "ok" record carries the
file's TXID range, the page count it commits and the page numbers it
wrote as ascending ranges. A consumer that holds the database file
against the apply reads a record for every page the file contains, can
copy only those pages into a copy of its own, and sees a trailing
"partial" record exactly when an apply did not complete. The sidecar is
opened in append mode for each record, so the consumer may truncate it
while it holds the file. Follow mode without the flag is unchanged.
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

PR Build Metrics

✅ All clear — no issues detected

Check Status Summary
Binary size ✅ 52.17 MB (+4.0 KB / +0.01%)
Dependencies ✅ No changes
Vulnerabilities ✅ None detected
Go toolchain ✅ 1.26.11 (latest)
Module graph ✅ 1617 edges (0)

Binary Size

Size Change
Base (fbdc5cf) 52.16 MB
PR (2305974) 52.17 MB +4.0 KB (+0.01%)

Dependency Changes

No dependency changes.

govulncheck Output

=== Symbol Results ===

No vulnerabilities found.

Your code is affected by 0 vulnerabilities.
This scan also found 0 vulnerabilities in packages you import and 5
vulnerabilities in modules you require, but your code doesn't appear to call
these vulnerabilities.
Use '-show verbose' for more details.

Build Info

Metric Value
Build time 57s
Go version go1.26.11
Commit 2305974

History (1 previous)

Commit Updated Status Summary
0c1dc0b 2026-11-17 06:31 UTC ✅ 52.17 MB (+4.0 KB / +0.01%)

🤖 Updated on each push.

@github-actions github-actions Bot added metrics: vulns-found govulncheck found vulnerabilities metrics: go-update Go toolchain has a newer patch release labels Nov 17, 2026
GO-2026-6859 is an HTTP/1 server crash in net/http, present in
go1.26.10 and fixed in go1.26.11. The workflows read the Go version
from go.mod, so the toolchain line is the only place that names it.
@github-actions github-actions Bot removed metrics: vulns-found govulncheck found vulnerabilities metrics: go-update Go toolchain has a newer patch release labels Nov 17, 2026
@jsas
jsas merged commit b1b2eb0 into c4x/main Nov 17, 2026
29 checks passed
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