Prevent checkpoints during snapshots (#477)

This commit is contained in:
Toni Spets
2023-08-08 05:20:27 +03:00
committed by GitHub
parent 749bc0d95a
commit 2512d35d8d
2 changed files with 24 additions and 0 deletions

View File

@@ -463,6 +463,10 @@ 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 {
return info, fmt.Errorf("pre-snapshot checkpoint: %w", err)