From 95c2fd7f76360104f0a733ff671bde475e3cf405 Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Wed, 31 Jul 2024 12:25:33 +0300 Subject: [PATCH] Allow disabling WAL sync This way Litestream can be used to only snapshot at regular intervals. --- replica.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/replica.go b/replica.go index 69bbcf55..611f5190 100644 --- a/replica.go +++ b/replica.go @@ -228,6 +228,18 @@ func (r *Replica) syncWAL(ctx context.Context) (err error) { } defer rd.Close() + // If WAL sync is disabled, just advance our position. + if r.SyncInterval == 0 { + if _, err = io.Copy(io.Discard, rd); err != nil { + return err + } + + r.mu.Lock() + r.pos = rd.Pos() + r.mu.Unlock() + return nil + } + // Copy shadow WAL to client write via io.Pipe(). pr, pw := io.Pipe() defer func() { _ = pw.CloseWithError(err) }() @@ -680,7 +692,12 @@ func (r *Replica) deleteWALSegmentsBeforeIndex(ctx context.Context, generation s // monitor runs in a separate goroutine and continuously replicates the DB. func (r *Replica) monitor(ctx context.Context) { - ticker := time.NewTicker(r.SyncInterval) + monitorInterval := r.SyncInterval + if monitorInterval == 0 { + monitorInterval = time.Second + } + + ticker := time.NewTicker(monitorInterval) defer ticker.Stop() // Continuously check for new data to replicate.