Skip to content

Commit

Permalink
fixup! Allow setting replica snapshot interval offset
Browse files Browse the repository at this point in the history
  • Loading branch information
hifi committed Nov 17, 2023
1 parent abdad37 commit 934cf77
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 934cf77

Please sign in to comment.