Skip to content

Commit

Permalink
Fix race while waiting for catchup with unpaused replication
Browse files Browse the repository at this point in the history
  • Loading branch information
secwall committed Sep 9, 2024
1 parent 443d1bc commit 55bd4a7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/app/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ func (app *App) waitForCatchup(host, master string) error {

deadline := time.Now().Add(app.config.Redis.WaitCatchupTimeout)
for time.Now().Before(deadline) {
masterState := app.getHostState(master)
if !masterState.PingOk {
return fmt.Errorf("waitForCatchup: %s died while waiting for catchup on %s", master, host)
}
state := app.getHostState(host)
if !state.PingOk {
return fmt.Errorf("waitForCatchup: replica %s died while waiting for catchup from %s", host, master)
Expand All @@ -152,19 +156,15 @@ func (app *App) waitForCatchup(host, master string) error {
time.Sleep(time.Second)
continue
}
masterState := app.getHostState(master)
if !masterState.PingOk {
return fmt.Errorf("waitForCatchup: %s died while waiting for catchup on %s", master, host)
}
var ok bool
if masterState.IsMaster {
ok = masterState.MasterReplicationOffset == state.ReplicaState.ReplicationOffset
ok = masterState.MasterReplicationOffset <= state.ReplicaState.ReplicationOffset
} else if masterState.ReplicaState == nil {
app.logger.Warn(fmt.Sprintf("WaitForCatchup: %s has invalid replica state", master))
time.Sleep(time.Second)
continue
} else {
ok = masterState.ReplicaState.ReplicationOffset == state.ReplicaState.ReplicationOffset
ok = masterState.ReplicaState.ReplicationOffset <= state.ReplicaState.ReplicationOffset
}
if ok {
return nil
Expand Down

0 comments on commit 55bd4a7

Please sign in to comment.