Skip to content

Commit

Permalink
Fix replica return (#108)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksandr Shevchuk <[email protected]>
  • Loading branch information
teem0n and Aleksandr Shevchuk authored Jun 11, 2024
1 parent 2ed636e commit bc9b606
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ func (app *App) calcActiveNodes(clusterState, clusterStateDcs map[string]*NodeSt
return activeNodes, nil
}

func (app *App) calcActiveNodesChanges(clusterState map[string]*NodeState, activeNodes []string, master string) (becomeActive, becomeInactive []string, err error) {
func (app *App) calcActiveNodesChanges(clusterState map[string]*NodeState, activeNodes []string, oldActiveNodes []string, master string) (becomeActive, becomeInactive []string, err error) {
masterNode := app.cluster.Get(master)
var syncReplicas []string
var deadReplicas []string
Expand All @@ -912,6 +912,17 @@ func (app *App) calcActiveNodesChanges(clusterState map[string]*NodeState, activ
becomeActive = filterOut(filterOut(activeNodes, syncReplicas), deadReplicas)
becomeInactive = filterOut(syncReplicas, activeNodes)

if len(oldActiveNodes) == 1 && oldActiveNodes[0] == master && len(becomeActive) == 0 {
// When replicas with semi-sync enabled returns to lone master,
// we should mark all of them as "become active" to restart replication
// because master may become stuck otherwise
for _, host := range activeNodes {
if host != master {
becomeActive = append(becomeActive, host)
}
}
}

if len(becomeActive) > 0 {
// Some replicas are going to become semi-sync.
// We need to check that they downloaded (not replayed) almost all binary logs,
Expand Down Expand Up @@ -973,7 +984,7 @@ func (app *App) updateActiveNodes(clusterState, clusterStateDcs map[string]*Node
return nil
}

becomeActive, becomeInactive, err := app.calcActiveNodesChanges(clusterState, activeNodes, master)
becomeActive, becomeInactive, err := app.calcActiveNodesChanges(clusterState, activeNodes, oldActiveNodes, master)
if err != nil {
app.logger.Errorf("update active nodes: failed to calc active nodes changes: %v", err)
return err
Expand Down

0 comments on commit bc9b606

Please sign in to comment.