Skip to content

Commit

Permalink
Add logs and fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
noname0443 committed Aug 28, 2024
1 parent e2c43ec commit 2c5a3bf
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -963,18 +963,18 @@ func (app *App) calcActiveNodesChanges(clusterState map[string]*NodeState, activ
slaveState := clusterState[host].SlaveState
dataLag := calcLagBytes(masterBinlogs, slaveState.MasterLogFile, slaveState.MasterLogPos)
if dataLag > app.config.SemiSyncEnableLag {
newBinLog := fmt.Sprintf("%s%019d", slaveState.MasterLogFile, slaveState.MasterLogPos)
oldBinLog := app.slaveReadPositions[host]
newBinLogPos := fmt.Sprintf("%s%019d", slaveState.MasterLogFile, slaveState.MasterLogPos)
oldBinLogPos := app.slaveReadPositions[host]

if newBinLog <= oldBinLog {
if newBinLogPos <= oldBinLogPos {
app.logger.Warnf("calc active nodes: %v should become active, but it has data lag %d and it's IO is stopped, delaying...", host, dataLag)
becomeInactive = append(becomeInactive, host)
} else {
app.logger.Warnf("calc active nodes: %v has data lag %d, but it's IO is working", host, dataLag)
app.logger.Warnf("calc active nodes: %v has data lag %d, but it's IO is working. Old binlog position is %s, new binlog position is %s", host, dataLag, oldBinLogPos, newBinLogPos)
dataLagging = append(dataLagging, host)
}

app.slaveReadPositions[host] = newBinLog
app.slaveReadPositions[host] = newBinLogPos
}
}
becomeActive = filterOut(becomeActive, dataLagging)
Expand Down Expand Up @@ -1056,14 +1056,14 @@ func (app *App) updateActiveNodes(clusterState, clusterStateDcs map[string]*Node
}
}
for _, host := range becomeInactive {
err = app.disableSemiSyncOnSlave(host, false)
err = app.disableSemiSyncOnSlave(host, true)
if err != nil {
app.logger.Warnf("failed to disable semi-sync on slave %s: %v", host, err)
return err
}
}
for _, host := range becomeDataLag {
err = app.disableSemiSyncOnSlave(host, true)
err = app.disableSemiSyncOnSlave(host, false)
if err != nil {
app.logger.Warnf("failed to disable semi-sync on slave %s: %v", host, err)
return err
Expand Down Expand Up @@ -1151,15 +1151,15 @@ func (app *App) enableSemiSyncOnSlave(host string, slaveState, masterState *Node
return nil
}

func (app *App) disableSemiSyncOnSlave(host string, isSlaveWorking bool) error {
func (app *App) disableSemiSyncOnSlave(host string, restartIOThread bool) error {
node := app.cluster.Get(host)
err := node.SemiSyncDisable()
if err != nil {
app.logger.Errorf("failed to enable semi_sync_slave on %s: %s", host, err)
return err
}

if !isSlaveWorking {
if restartIOThread {
err = node.RestartSlaveIOThread()
if err != nil {
app.logger.Errorf("failed restart slave io thread after set semi_sync_slave on %s: %s", host, err)
Expand Down

0 comments on commit 2c5a3bf

Please sign in to comment.