From 8a1f02fedaf51a91a29b28bcb246ee7d03ee238d Mon Sep 17 00:00:00 2001 From: Fizic Date: Wed, 22 May 2024 14:32:50 +0300 Subject: [PATCH] fix: enabling semisync; feat: errno in logs --- internal/app/app.go | 12 +++++++++++- internal/mysql/node.go | 11 ++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index 16462cd2..b3e40a75 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -320,7 +320,12 @@ func (app *App) checkRecovery() { app.logger.Infof("recovery: local node %s has GTIDs %s", localNode.Host(), sstatus.GetExecutedGtidSet()) if isSlavePermanentlyLost(sstatus, mgtids) { - app.logger.Errorf("recovery: local node %s is NOT behind the master %s, need RESETUP", localNode.Host(), masterNode) + rp, err := localNode.GetReplicaStatus() + if err != nil { + app.logger.Errorf("recovery: local node %s is NOT behind the master %s, need RESETUP", localNode.Host(), masterNode) + } else { + app.logger.Errorf("recovery: local node %s is NOT behind the master %s, need RESETUP, last IO errno: %d", localNode.Host(), masterNode, rp.GetLastIOErrno()) + } app.writeResetupFile("") } else { readOnly, _, err := localNode.IsReadOnly() @@ -1072,6 +1077,11 @@ func (app *App) enableSemiSyncOnSlave(host string) error { app.logger.Errorf("failed restart slave io thread after set semi_sync_slave on %s: %s", host, err) return err } + err = node.RestartReplication() + if err != nil { + app.logger.Errorf("failed restart replication after set semi_sync_slave on %s: %s", host, err) + return err + } return nil } diff --git a/internal/mysql/node.go b/internal/mysql/node.go index 15f913aa..8e2485d9 100644 --- a/internal/mysql/node.go +++ b/internal/mysql/node.go @@ -722,6 +722,15 @@ func (n *Node) StartSlave() error { }) } +// RestartReplication restart replication +func (n *Node) RestartReplication() error { + err := n.StopSlave() + if err != nil { + return err + } + return n.StartSlave() +} + // StopSlaveIOThread stops IO replication thread func (n *Node) StopSlaveIOThread() error { return n.execMogrify(queryStopSlaveIOThread, map[string]interface{}{ @@ -736,7 +745,7 @@ func (n *Node) StartSlaveIOThread() error { }) } -// RestartSlaveIOThread stops IO replication thread +// RestartSlaveIOThread restart IO replication thread func (n *Node) RestartSlaveIOThread() error { err := n.StopSlaveIOThread() if err != nil {