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.