Skip to content

Commit

Permalink
Allow disabling WAL sync
Browse files Browse the repository at this point in the history
This way Litestream can be used to only snapshot at regular intervals.
  • Loading branch information
hifi committed Jul 31, 2024
1 parent d949e7e commit 95c2fd7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }()
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 95c2fd7

Please sign in to comment.