Repository navigation
fix: continue replicating after restoring a database - #25
Merged
Merged
Conversation
Restoring a database into the replica's own path, as ensureExists() does on a new host, left the local position at zero. The next sync() wrote TXID 1, which the replica already had, so the new changes were never uploaded and a later restore silently lost them. Restore now discards the local LTX cache and records the restored TXID, so the next sync() continues with the following TXID from a snapshot. It also removes the -wal and -shm files left at the output path, which SQLite would replay on top of the restored database. sync() throws ErrReplicaAhead instead of skipping uploads when the replica is ahead of the local database. Signed-off-by: Matteo Collina <hello@matteocollina.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #24.
Restoring a database into the replica's own path, as
ensureExists()does on a new host, left the local position at zero. The nextsync()wrote TXID 1, which the replica already had, so the new changes were never uploaded and a later restore silently lost them.Changes
<meta>/base-txid.pos()takes it into account, and the nextsync()continues with the following TXID, starting from a snapshot.-waland-shmfiles at the output path before moving the restored database into place, so SQLite doesn't replay them on top of it.sync()no longer skips uploads silently. It throws the newErrReplicaAhead(ERR_REPLICA_AHEAD, withlocalTXIDandremoteTXID) when the replica is ahead of the local database.Tests
Three integration tests in
test/integration/replicate-restore.test.ts:ensureExists()reach the replica, and a third restore sees them;sync()throwsErrReplicaAheadwhen the replica is ahead.All tests pass, including the Postgres and S3 backends, and typecheck and lint are clean. README and CHANGELOG are updated.
🤖 Generated with Claude Code