diff --git a/replica.go b/replica.go index bf858836..6211200b 100644 --- a/replica.go +++ b/replica.go @@ -477,16 +477,16 @@ func (r *Replica) Snapshot(ctx context.Context) (info SnapshotInfo, err error) { r.muf.Lock() defer r.muf.Unlock() - // Prevent checkpoints during snapshot. - r.db.BeginSnapshot() - defer r.db.EndSnapshot() - // Issue a passive checkpoint to flush any pages to disk before snapshotting. - if _, err := r.db.db.ExecContext(ctx, `PRAGMA wal_checkpoint(PASSIVE);`); err != nil { + if err := r.db.Checkpoint(ctx, CheckpointModePassive); err != nil { return info, fmt.Errorf("pre-snapshot checkpoint: %w", err) } - // Acquire a read lock on the database during snapshot to prevent checkpoints. + // Prevent internal checkpoints during snapshot. + r.db.BeginSnapshot() + defer r.db.EndSnapshot() + + // Acquire a read lock on the database during snapshot to prevent external checkpoints. tx, err := r.db.db.Begin() if err != nil { return info, err