diff --git a/replica.go b/replica.go index 7376dd76..bca2ddf5 100644 --- a/replica.go +++ b/replica.go @@ -55,7 +55,7 @@ type Replica struct { // Frequency to create new snapshots. SnapshotInterval time.Duration - // Duration added to snapshot interval before the first one. Skips checking replica. + // Time waited before starting the snapshot interval. Skips checking replica to calculate offset. SnapshotOffset time.Duration // Time to keep snapshots and related WAL files. @@ -65,9 +65,15 @@ type Replica struct { // Time between checks for retention. RetentionCheckInterval time.Duration + // Time waited before starting the check interval. + RetentionCheckOffset time.Duration + // Time between validation checks. ValidationInterval time.Duration + // Time waited before starting the validation checks. + ValidationOffset time.Duration + // If true, replica monitors database for changes automatically. // Set to false if replica is being used synchronously (such as in tests). MonitorEnabled bool @@ -724,6 +730,13 @@ func (r *Replica) retainer(ctx context.Context) { checkInterval = r.Retention } + // Wait to start retention checks. + select { + case <-ctx.Done(): + return + case <-time.After(r.RetentionCheckOffset): + } + ticker := time.NewTicker(checkInterval) defer ticker.Stop() @@ -804,6 +817,13 @@ func (r *Replica) validator(ctx context.Context) { return } + // Wait to start validation checks. + select { + case <-ctx.Done(): + return + case <-time.After(r.ValidationOffset): + } + ticker := time.NewTicker(r.ValidationInterval) defer ticker.Stop()