lease: VerifyReplicaAt restores pinned to a planned TXID (#898)
The nightly drill plans a restore with dbdoor.PlanFrom and must test exactly that transaction, under the run's deadline. VerifyReplicaAt restores through txid with litestream's RestoreOptions.TXID (0 is the newest copy), checks with CheckDBContext(ctx) instead of CheckDB, and returns ctx's own error when the context ends first, so the drill can abandon rather than record a failure. The copy, litestream's .tmp and the -wal/-shm sidecars are swept on every path. VerifyReplica is VerifyReplicaAt(..., 0), unchanged for its callers. Restore and the verify path now share restoreFrom. A pinned TXID the replica cannot reach is an error wrapping ErrTxNotAvailable, never ErrNoReplica.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/lease/check.go+84 −11internal/lease/check_test.go+250 −3internal/lease/lease.go+1 −12
CI failed — run details
Intent
<task-notification> <task-id>ae0b97e2593adfd1f</task-id> <tool-use-id>toolu_01KnxvbN4DU3SFjSm3mkxzM8</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/ae0b97e2593adfd1f.output</output-file> <status>completed</status> <summary>Agent "Implement slice 2a Task 2" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE. Fix round 2 is in; nothing pushed. A record the agent can no longer rewrite now goes stale, so the drill refuses it even when the old file can't be deleted. Commits: 3e962a32 (Task 2), 038807ea (round 1), 9b66dd45 (round 2). What changed, per your ruling: - **Self-expiring record.** `boxself.Self` now has an `At` time, and `Write` refuses a record without one. - **New `ReadFresh(dataDir, now, maxAge)`.** It refuses with a new `ErrStale` error when `At` is missing, older than `maxAge`, or more than a minute in the future. Task 5's drill should call it with 15 minutes. - **Rewritten every 5 minutes.** The agent writes `self.json` at start and every 5 minutes on every box, fixed and group. The rewriting stops, and is waited for, when the agent stops. - **Round 1 kept.** A failed write still deletes the old file where it can. Tests: - **Unwritable directory, as the ruling asked:** the old record is 20 minutes old and the monitor directory is 0555. The new write and the deletion both fail, the old file is still there, and `ReadFresh` returns `ErrStale`. A second version forces the deletion to fail through a test hook, so it also runs as root. - **Freshness edges:** a record written 1 minute ago passes. Each boundary is checked on both sides. - **Rewrite loop:** a new test shows the agent keeps rewriting while it runs and stops once it has stopped. It passed 30 repeated runs. - **RED:** three mutation checks (age check skipped, no rewrite loop, loop outliving the agent) each make their test fail. - **Covering run:** all five packages pass. gofmt, vet and the linux, darwin and windows builds are clean. Concerns: - If the agent is down for more than 15 minutes, the drill refuses until it is back. That is intended. - The Minor (`Decoder.More()` accepting a trailing `]` or `}`) is still deferred. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups-2a/.superpowers/sdd/2026-11-11-member-backups-slice2a/task-2-report.md</result> <usage><subagent_tokens>197196</subagent_tokens><tool_uses>11</tool_uses><duration_ms>308275</duration_ms></usage> </task-notification>
Attributed to this commit: 19.8 g CO₂e (2,510,194 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on member-backups-2a, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/lease/check.go b/internal/lease/check.go| index fb4d00e74..0cf5e1218 100644 |
| --- a/internal/lease/check.go |
| +++ b/internal/lease/check.go |
| @@ -15,9 +15,54 @@ import ( |
| _ "modernc.org/sqlite" |
| ) |
| -// restoreForVerify is Restore behind a package var so the drill's three |
| -// outcomes (clean, damaged, never-replicated) are testable without S3. |
| -var restoreForVerify = Restore |
| +// restoreForVerify is the verify restore behind a package var so the |
| +// drill's three outcomes (clean, damaged, never-replicated) are testable |
| +// without S3. |
| +var restoreForVerify = func(ctx context.Context, out, bucket, prefix, region string, txid ltx.TXID) (bool, error) { |
| + client, err := verifyReplicaClient(ctx, bucket, prefix, region) |
| + if err != nil { |
| + return false, err |
| + } |
| + return restoreFrom(ctx, client, out, txid) |
| +} |
| + |
| +// verifyReplicaClient is the replica client a verify restore reads, behind |
| +// a package var so tests can hand it a litestream file replica and still |
| +// run the real pinned restore, check and sweep. Built as Restore builds its |
| +// own: the same region resolution, the same endpoint override. |
| +var verifyReplicaClient = func(ctx context.Context, bucket, prefix, region string) (litestream.ReplicaClient, error) { |
| + region, err := resolveRegion(ctx, region) |
| + if err != nil { |
| + return nil, err |
| + } |
| + return newReplicaClient(bucket, prefix, region) |
| +} |
| + |
| +// restoreFrom restores client's replica into out through transaction txid, |
| +// with litestream's own restore (RestoreOptions.TXID); zero is the newest |
| +// copy. With txid zero, a replica with nothing to restore is restored=false |
| +// and a nil error, Restore's "boot fresh". A pinned txid the replica cannot |
| +// reach is an error wrapping litestream.ErrTxNotAvailable instead: the |
| +// caller planned that transaction from a listing, so its absence is |
| +// something that changed, never "nothing replicated yet". |
| +func restoreFrom(ctx context.Context, client litestream.ReplicaClient, out string, txid ltx.TXID) (bool, error) { |
| + // A nil *DB is litestream's own pattern for URL restores (the CLI does |
| + // the same): Restore only needs the replica client and the output path. |
| + r := litestream.NewReplicaWithClient(nil, client) |
| + opt := litestream.NewRestoreOptions() |
| + opt.OutputPath = out |
| + opt.TXID = txid |
| + if err := r.Restore(ctx, opt); err != nil { |
| + if txid == 0 && (errors.Is(err, litestream.ErrTxNotAvailable) || errors.Is(err, litestream.ErrNoSnapshots)) { |
| + return false, nil |
| + } |
| + if txid != 0 && errors.Is(err, litestream.ErrTxNotAvailable) { |
| + return false, fmt.Errorf("transaction %s is not restorable: %w", txid, err) |
| + } |
| + return false, err |
| + } |
| + return true, nil |
| +} |
| // ErrNoReplica reports that a prefix holds no backup at all — a brand-new |
| // instance that has never replicated, not a damaged one. Verification callers |
| @@ -70,10 +115,20 @@ func CheckDBContext(ctx context.Context, path string) error { |
| return nil |
| } |
| -// VerifyReplica restores s3://bucket/prefix into a throwaway file under dir |
| -// and proves it opens clean, then deletes it. It returns ErrNoReplica when |
| -// the prefix has never been replicated to, and a describing error when the |
| -// restore or the check fails. |
| +// VerifyReplica restores the newest copy of s3://bucket/prefix into a |
| +// throwaway file under dir and proves it opens clean, then deletes it: it is |
| +// VerifyReplicaAt with no target. |
| +func VerifyReplica(ctx context.Context, bucket, prefix, region, dir string) (uint32, error) { |
| + return VerifyReplicaAt(ctx, bucket, prefix, region, dir, 0) |
| +} |
| + |
| +// VerifyReplicaAt restores s3://bucket/prefix exactly through transaction |
| +// txid (zero is the newest copy) into a throwaway file under dir and proves |
| +// it opens clean, then deletes it. Pinning is what lets a drill that planned |
| +// a restore record the position it actually tested. With no target it |
| +// returns ErrNoReplica when the prefix has never been replicated to (a |
| +// pinned target the replica cannot reach is an error, see restoreFrom); it |
| +// returns a describing error when the restore or the check fails. |
| // |
| // IT DELIBERATELY DOES NOT TAKE THE LEASE, and that is safe in a way Restore |
| // itself is not. Restore's contract requires the lease because it materializes |
| @@ -85,7 +140,13 @@ func CheckDBContext(ctx context.Context, path string) error { |
| // `carlos ops restore-verify` has always restored databases that its own |
| // replicator was actively streaming, and litestream restores a committed |
| // position rather than a live tail. |
| -func VerifyReplica(ctx context.Context, bucket, prefix, region, dir string) (uint32, error) { |
| +// |
| +// ctx bounds all of it: the restore and the integrity scan |
| +// (CheckDBContext). When ctx ends first, the error wraps ctx's own |
| +// (context.Canceled or context.DeadlineExceeded), not a restore or check |
| +// failure, so a caller out of time can abandon the database instead of |
| +// recording it as damaged. |
| +func VerifyReplicaAt(ctx context.Context, bucket, prefix, region, dir string, txid uint64) (uint32, error) { |
| out := filepath.Join(dir, "verify-"+filepath.Base(prefix)+".db") |
| // A retry must not trip over a previous attempt's file: litestream refuses |
| // to restore over an existing output path. |
| @@ -93,21 +154,33 @@ func VerifyReplica(ctx context.Context, bucket, prefix, region, dir string) (uin |
| // Sweep on EVERY path, including a failed check. The sidecars are swept |
| // too: CheckDB's "mode=ro" does not stop the driver attaching a WAL, and a |
| // drill that left a copy of every tenant's database on the box would be |
| - // both a disk bug and a data-exposure one. |
| + // both a disk bug and a data-exposure one. litestream's ".tmp" goes |
| + // too: litestream removes its own on return, and this costs nothing if |
| + // it did. |
| defer func() { |
| _ = os.Remove(out) |
| + _ = os.Remove(out + ".tmp") |
| _ = os.Remove(out + "-wal") |
| _ = os.Remove(out + "-shm") |
| }() |
| - restored, err := restoreForVerify(ctx, out, bucket, prefix, region) |
| + restored, err := restoreForVerify(ctx, out, bucket, prefix, region, ltx.TXID(txid)) |
| if err != nil { |
| + // A download cut off by ctx surfaces from litestream as whatever |
| + // its decoder made of the short stream ("decode header: EOF"); |
| + // ctx's own error is the true one. |
| + if cerr := ctx.Err(); cerr != nil { |
| + return 0, fmt.Errorf("restore stopped: %w", cerr) |
| + } |
| return 0, fmt.Errorf("restore: %w", err) |
| } |
| if !restored { |
| return 0, ErrNoReplica |
| } |
| - if err := CheckDB(out); err != nil { |
| + if err := CheckDBContext(ctx, out); err != nil { |
| + if cerr := ctx.Err(); cerr != nil { |
| + return 0, fmt.Errorf("check stopped: %w", cerr) |
| + } |
| return 0, err |
| } |
| // The counter is read BEFORE the deferred sweep removes the copy: it is |
diff --git a/internal/lease/check_test.go b/internal/lease/check_test.go| index 8156b30e5..3e4dcee7b 100644 |
| --- a/internal/lease/check_test.go |
| +++ b/internal/lease/check_test.go |
| @@ -4,10 +4,16 @@ import ( |
| "context" |
| "database/sql" |
| "errors" |
| + "fmt" |
| + "io" |
| "os" |
| "path/filepath" |
| + "sync" |
| "testing" |
| + "github.com/benbjohnson/litestream" |
| + lsfile "github.com/benbjohnson/litestream/file" |
| + "github.com/superfly/ltx" |
| _ "modernc.org/sqlite" |
| ) |
| @@ -152,7 +158,7 @@ func TestVerifyReplicaCleansUpEvenOnFailure(t *testing.T) { |
| // A restore that "succeeds" into a corrupt file: the check fails, and the |
| // wreckage must still be swept. |
| prev := restoreForVerify |
| - restoreForVerify = func(_ context.Context, out, _, _, _ string) (bool, error) { |
| + restoreForVerify = func(_ context.Context, out, _, _, _ string, _ ltx.TXID) (bool, error) { |
| if err := os.WriteFile(out, []byte("not a database"), 0o600); err != nil { |
| return false, err |
| } |
| @@ -180,7 +186,7 @@ func TestVerifyReplicaCleansUpEvenOnFailure(t *testing.T) { |
| // restore yet", which callers must not report as a failure. |
| func TestVerifyReplicaReportsNoReplica(t *testing.T) { |
| prev := restoreForVerify |
| - restoreForVerify = func(context.Context, string, string, string, string) (bool, error) { |
| + restoreForVerify = func(context.Context, string, string, string, string, ltx.TXID) (bool, error) { |
| return false, nil |
| } |
| t.Cleanup(func() { restoreForVerify = prev }) |
| @@ -204,7 +210,7 @@ func TestVerifyReplicaReturnsTheRestoredChangeCounter(t *testing.T) { |
| } |
| prev := restoreForVerify |
| - restoreForVerify = func(_ context.Context, out, _, _, _ string) (bool, error) { |
| + restoreForVerify = func(_ context.Context, out, _, _, _ string, _ ltx.TXID) (bool, error) { |
| body, err := os.ReadFile(src) |
| if err != nil { |
| return false, err |
| @@ -236,3 +242,244 @@ func TestCheckDBContextHonoursCancellation(t *testing.T) { |
| t.Fatalf("cancelled context = %v, want context.Canceled", err) |
| } |
| } |
| + |
| +// replicatedBatches replicates seedDB's rows and then two more batches of |
| +// writes to a litestream file replica, syncing after each, and returns the |
| +// replica directory and the TXID each batch ended at. Every batch also sets |
| +// user_version to its number, so the fixture can prove a restore to batch |
| +// two and one to batch three are different copies. |
| +func replicatedBatches(t *testing.T) (string, [3]ltx.TXID) { |
| + t.Helper() |
| + path := filepath.Join(t.TempDir(), "source.db") |
| + seedDB(t, path) |
| + replica := t.TempDir() |
| + db := litestream.NewDB(path) |
| + db.MonitorInterval = 0 |
| + db.Replica = litestream.NewReplicaWithClient(db, lsfile.NewReplicaClient(replica)) |
| + db.Replica.MonitorEnabled = false |
| + if err := db.Open(); err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { _ = db.Close(context.Background()) }) |
| + |
| + writer, err := sql.Open("sqlite", path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { writer.Close() }) |
| + |
| + var txids [3]ltx.TXID |
| + for batch := range txids { |
| + if batch > 0 { |
| + for i := 0; i < 20; i++ { |
| + if _, err := writer.Exec(`INSERT INTO t (body) VALUES (?)`, fmt.Sprintf("batch-%d-row-%d", batch, i)); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + } |
| + if _, err := writer.Exec(fmt.Sprintf("PRAGMA user_version=%d", batch+1)); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := db.SyncAndWait(context.Background()); err != nil { |
| + t.Fatal(err) |
| + } |
| + txids[batch] = db.Replica.Pos().TXID |
| + } |
| + if !(txids[0] < txids[1] && txids[1] < txids[2]) { |
| + t.Fatalf("batches did not end at increasing transactions: %v", txids) |
| + } |
| + return replica, txids |
| +} |
| + |
| +// useFileReplica points VerifyReplica's replica client at a litestream file |
| +// replica: everything after the client (the pinned restore, the check, the |
| +// counter, the sweep) is the production path. |
| +func useFileReplica(t *testing.T, client litestream.ReplicaClient) { |
| + t.Helper() |
| + prev := verifyReplicaClient |
| + verifyReplicaClient = func(context.Context, string, string, string) (litestream.ReplicaClient, error) { |
| + return client, nil |
| + } |
| + t.Cleanup(func() { verifyReplicaClient = prev }) |
| +} |
| + |
| +// restoredHeader restores replica straight through litestream, to txid, and |
| +// returns the copy's change counter and user_version: the expected answer, |
| +// computed without the code under test. |
| +func restoredHeader(t *testing.T, replica string, txid ltx.TXID) (counter uint32, userVersion int) { |
| + t.Helper() |
| + out := filepath.Join(t.TempDir(), "expected.db") |
| + opt := litestream.NewRestoreOptions() |
| + opt.OutputPath = out |
| + opt.TXID = txid |
| + if err := litestream.NewReplicaWithClient(nil, lsfile.NewReplicaClient(replica)).Restore(context.Background(), opt); err != nil { |
| + t.Fatal(err) |
| + } |
| + counter, err := ChangeCounter(out) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + d, err := sql.Open("sqlite", "file:"+out+"?mode=ro") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer d.Close() |
| + if err := d.QueryRow("PRAGMA user_version").Scan(&userVersion); err != nil { |
| + t.Fatal(err) |
| + } |
| + return counter, userVersion |
| +} |
| + |
| +func assertEmptyDir(t *testing.T, dir string) { |
| + t.Helper() |
| + left, err := os.ReadDir(dir) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(left) != 0 { |
| + names := []string{} |
| + for _, e := range left { |
| + names = append(names, e.Name()) |
| + } |
| + t.Fatalf("left %v behind in %s", names, dir) |
| + } |
| +} |
| + |
| +// The nightly drill plans a restore and must test exactly the transaction |
| +// it planned: the position its verdict records. A restore of "the latest" |
| +// would test whatever was replicated after the plan. |
| +func TestVerifyReplicaAtStopsAtTheTarget(t *testing.T) { |
| + replica, txids := replicatedBatches(t) |
| + want, version := restoredHeader(t, replica, txids[1]) |
| + latest, latestVersion := restoredHeader(t, replica, txids[2]) |
| + if version != 2 || latestVersion != 3 { |
| + t.Fatalf("fixture: user_version at batch two %d, at batch three %d; want 2 and 3", version, latestVersion) |
| + } |
| + |
| + // SQLite does not advance the file change counter on a WAL-mode commit, |
| + // so the counters of batch two and batch three may well be equal (they |
| + // are, with this fixture): the counter alone cannot show which copy was |
| + // tested. The client records the newest transaction of any file the |
| + // restore opened, which can. |
| + client := &openedMaxClient{ReplicaClient: lsfile.NewReplicaClient(replica)} |
| + useFileReplica(t, client) |
| + dir := t.TempDir() |
| + |
| + got, err := VerifyReplicaAt(context.Background(), "bucket", "hib/x.example.com", "", dir, uint64(txids[1])) |
| + if err != nil { |
| + t.Fatalf("VerifyReplicaAt: %v", err) |
| + } |
| + if got != want { |
| + t.Fatalf("pinned restore counter = %d, want %d (batch two)", got, want) |
| + } |
| + if got := client.newest(); got != txids[1] { |
| + t.Fatalf("pinned restore read through transaction %s, want %s", got, txids[1]) |
| + } |
| + assertEmptyDir(t, dir) |
| + |
| + // Zero is the latest, which is what VerifyReplica has always restored. |
| + client.reset() |
| + got, err = VerifyReplica(context.Background(), "bucket", "hib/x.example.com", "", dir) |
| + if err != nil { |
| + t.Fatalf("VerifyReplica: %v", err) |
| + } |
| + if got != latest { |
| + t.Fatalf("latest restore counter = %d, want %d (batch three)", got, latest) |
| + } |
| + if got := client.newest(); got != txids[2] { |
| + t.Fatalf("latest restore read through transaction %s, want %s", got, txids[2]) |
| + } |
| + assertEmptyDir(t, dir) |
| +} |
| + |
| +// openedMaxClient remembers the highest MaxTXID of any LTX file a restore |
| +// opens. |
| +type openedMaxClient struct { |
| + litestream.ReplicaClient |
| + mu sync.Mutex |
| + max ltx.TXID |
| +} |
| + |
| +func (c *openedMaxClient) OpenLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, offset, size int64) (io.ReadCloser, error) { |
| + c.mu.Lock() |
| + if maxTXID > c.max { |
| + c.max = maxTXID |
| + } |
| + c.mu.Unlock() |
| + return c.ReplicaClient.OpenLTXFile(ctx, level, minTXID, maxTXID, offset, size) |
| +} |
| + |
| +func (c *openedMaxClient) newest() ltx.TXID { |
| + c.mu.Lock() |
| + defer c.mu.Unlock() |
| + return c.max |
| +} |
| + |
| +func (c *openedMaxClient) reset() { |
| + c.mu.Lock() |
| + defer c.mu.Unlock() |
| + c.max = 0 |
| +} |
| + |
| +// cancelOnReadClient cancels the run the moment the restore reads replica |
| +// bytes, and from then on fails reads with the context's error, as an S3 |
| +// download does when its request context ends. |
| +type cancelOnReadClient struct { |
| + litestream.ReplicaClient |
| + ctx context.Context |
| + cancel context.CancelFunc |
| +} |
| + |
| +func (c *cancelOnReadClient) OpenLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, offset, size int64) (io.ReadCloser, error) { |
| + rc, err := c.ReplicaClient.OpenLTXFile(ctx, level, minTXID, maxTXID, offset, size) |
| + if err != nil { |
| + return nil, err |
| + } |
| + return &cancelOnRead{ReadCloser: rc, c: c}, nil |
| +} |
| + |
| +type cancelOnRead struct { |
| + io.ReadCloser |
| + c *cancelOnReadClient |
| +} |
| + |
| +func (r *cancelOnRead) Read(p []byte) (int, error) { |
| + r.c.cancel() |
| + if err := r.c.ctx.Err(); err != nil { |
| + return 0, err |
| + } |
| + return r.ReadCloser.Read(p) |
| +} |
| + |
| +// The drill's time budget is the run context's deadline: once it ends, |
| +// VerifyReplicaAt stops, says so with the context's error (the drill |
| +// abandons the host rather than recording a failure), and leaves nothing in |
| +// dir. |
| +func TestVerifyReplicaAtHonoursCancel(t *testing.T) { |
| + replica, txids := replicatedBatches(t) |
| + |
| + t.Run("during the restore", func(t *testing.T) { |
| + ctx, cancel := context.WithCancel(context.Background()) |
| + defer cancel() |
| + useFileReplica(t, &cancelOnReadClient{ReplicaClient: lsfile.NewReplicaClient(replica), ctx: ctx, cancel: cancel}) |
| + dir := t.TempDir() |
| + if _, err := VerifyReplicaAt(ctx, "bucket", "hib/x.example.com", "", dir, uint64(txids[1])); !errors.Is(err, context.Canceled) { |
| + t.Fatalf("VerifyReplicaAt cancelled mid-restore = %v, want context.Canceled", err) |
| + } |
| + assertEmptyDir(t, dir) |
| + }) |
| + |
| + // A file replica ignores the context, so the restore completes; the |
| + // integrity check is what must then see the cancellation (CheckDBContext, |
| + // never CheckDB's context.Background()). |
| + t.Run("before the check", func(t *testing.T) { |
| + useFileReplica(t, lsfile.NewReplicaClient(replica)) |
| + ctx, cancel := context.WithCancel(context.Background()) |
| + cancel() |
| + dir := t.TempDir() |
| + if _, err := VerifyReplicaAt(ctx, "bucket", "hib/x.example.com", "", dir, uint64(txids[1])); !errors.Is(err, context.Canceled) { |
| + t.Fatalf("VerifyReplicaAt with a cancelled context = %v, want context.Canceled", err) |
| + } |
| + assertEmptyDir(t, dir) |
| + }) |
| +} |
diff --git a/internal/lease/lease.go b/internal/lease/lease.go| index e3d9bb2bc..6e3778ef6 100644 |
| --- a/internal/lease/lease.go |
| +++ b/internal/lease/lease.go |
| @@ -625,16 +625,5 @@ func Restore(ctx context.Context, dbPath, bucket, prefix, region string) (bool, |
| return false, fmt.Errorf("create %s: %w", filepath.Dir(dbPath), err) |
| } |
| - // A nil *DB is litestream's own pattern for URL restores (the CLI does the |
| - // same): Restore only needs the replica client and the output path. |
| - r := litestream.NewReplicaWithClient(nil, client) |
| - opt := litestream.NewRestoreOptions() |
| - opt.OutputPath = dbPath |
| - if err := r.Restore(ctx, opt); err != nil { |
| - if errors.Is(err, litestream.ErrTxNotAvailable) || errors.Is(err, litestream.ErrNoSnapshots) { |
| - return false, nil |
| - } |
| - return false, err |
| - } |
| - return true, nil |
| + return restoreFrom(ctx, client, dbPath, 0) |
| } |