feat(restore): add -f follow mode for continuous restore #1102
+769
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
-fflag to therestorecommand that continuously polls for and applies new LTX files after the initial restore, similar totail -fCloses #1065
Implementation Details
db.go: AddedFollowandFollowIntervalfields toRestoreOptionswithDefaultFollowInterval(1s).replica.go: Added validation (follow is incompatible with-txid/-timestamp), and four new methods:follow()- Main poll loop that opens the restored DB, reads page size, and ticks at the configured intervalapplyNewLTXFiles()- Polls level 0 for new files, handles gaps viafillFollowGap()applyLTXFile()- Applies a single LTX file's pages to the database (followsHydrator.ApplyLTXpattern)fillFollowGap()- Searches compaction levels 1-8 to bridge gaps when L0 files are compactedcmd/litestream/restore.go: Added-fflag, signal handling for clean Ctrl+C shutdown, usage docs and example.Usage
# Continuously restore (follow) a database from a replica litestream restore -f -o /tmp/read-replica.db s3://mybucket/dbImportant: The restored database should only be opened in read-only mode by consumers.
Test plan
TestReplica_Restore_Follow_IncompatibleFlags- Verifies error when Follow + TXID or Follow + TimestampTestReplica_Restore_Follow- Integration test: creates source DB, syncs to file replica, restores with follow, inserts new data, verifies follow applies it, cancels cleanlyTestReplica_Restore_Follow_ContextCancellation- Verifies immediate cancel returns nil (clean shutdown)🤖 Generated with Claude Code