From 8a1f02fedaf51a91a29b28bcb246ee7d03ee238d Mon Sep 17 00:00:00 2001 From: Fizic Date: Wed, 22 May 2024 14:32:50 +0300 Subject: [PATCH 1/3] 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 { From 174710d5834ab5b1011183a3c870f38bc13f4cbe Mon Sep 17 00:00:00 2001 From: Fizic Date: Thu, 23 May 2024 12:44:33 +0300 Subject: [PATCH 2/3] fix: issues --- internal/app/app.go | 13 ++++--------- internal/mysql/node.go | 4 ++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index b3e40a75..eb235e7c 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -321,10 +321,10 @@ func (app *App) checkRecovery() { if isSlavePermanentlyLost(sstatus, mgtids) { 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) + if err == nil { + app.logger.Errorf("recovery: local node %s has IO errno: %d", localNode.Host(), rp.GetLastIOErrno()) } 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.logger.Errorf("recovery: local node %s is NOT behind the master %s, need RESETUP", localNode.Host(), masterNode) } app.writeResetupFile("") } else { @@ -1072,12 +1072,7 @@ func (app *App) enableSemiSyncOnSlave(host string) error { app.logger.Errorf("failed to enable semi_sync_slave on %s: %s", host, err) return err } - err = node.RestartSlaveIOThread() - if err != nil { - app.logger.Errorf("failed restart slave io thread after set semi_sync_slave on %s: %s", host, err) - return err - } - err = node.RestartReplication() + err = node.RestartReplica() if err != nil { app.logger.Errorf("failed restart replication after set semi_sync_slave on %s: %s", host, err) return err diff --git a/internal/mysql/node.go b/internal/mysql/node.go index 8e2485d9..642095d7 100644 --- a/internal/mysql/node.go +++ b/internal/mysql/node.go @@ -722,8 +722,8 @@ func (n *Node) StartSlave() error { }) } -// RestartReplication restart replication -func (n *Node) RestartReplication() error { +// RestartReplica restart replication +func (n *Node) RestartReplica() error { err := n.StopSlave() if err != nil { return err From 26c08b6ebaced23a8b2f90db78320541de2cf862 Mon Sep 17 00:00:00 2001 From: Fizic Date: Mon, 27 May 2024 11:22:41 +0300 Subject: [PATCH 3/3] fix: issues --- internal/app/app.go | 7 ++++++- internal/mysql/data.go | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index eb235e7c..9332dc11 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -322,7 +322,12 @@ func (app *App) checkRecovery() { if isSlavePermanentlyLost(sstatus, mgtids) { rp, err := localNode.GetReplicaStatus() if err == nil { - app.logger.Errorf("recovery: local node %s has IO errno: %d", localNode.Host(), rp.GetLastIOErrno()) + if rp.GetLastError() != "" { + app.logger.Errorf("recovery: local node %s has error: %s", localNode.Host(), rp.GetLastError()) + } + if rp.GetLastIOError() != "" { + app.logger.Errorf("recovery: local node %s has IO error: %s", localNode.Host(), rp.GetLastIOError()) + } } else { app.logger.Errorf("recovery: local node %s is NOT behind the master %s, need RESETUP", localNode.Host(), masterNode) } diff --git a/internal/mysql/data.go b/internal/mysql/data.go index 8f480073..854a5e06 100644 --- a/internal/mysql/data.go +++ b/internal/mysql/data.go @@ -68,9 +68,11 @@ type SlaveStatusStruct struct { ReadMasterLogPos int64 `db:"Read_Master_Log_Pos"` SlaveIORunning string `db:"Slave_IO_Running"` SlaveSQLRunning string `db:"Slave_SQL_Running"` + LastError string `db:"Last_Error"` RetrievedGtidSet string `db:"Retrieved_Gtid_Set"` ExecutedGtidSet string `db:"Executed_Gtid_Set"` LastIOErrno int `db:"Last_IO_Errno"` + LastIOError string `db:"Last_IO_Error"` LastSQLErrno int `db:"Last_SQL_Errno"` Lag sql.NullFloat64 `db:"Seconds_Behind_Master"` } @@ -83,9 +85,11 @@ type ReplicaStatusStruct struct { ReadSourceLogPos int64 `db:"Read_Source_Log_Pos"` ReplicaIORunning string `db:"Replica_IO_Running"` ReplicaSQLRunning string `db:"Replica_SQL_Running"` + LastError string `db:"Last_Error"` RetrievedGtidSet string `db:"Retrieved_Gtid_Set"` ExecutedGtidSet string `db:"Executed_Gtid_Set"` LastIOErrno int `db:"Last_IO_Errno"` + LastIOError string `db:"Last_IO_Error"` LastSQLErrno int `db:"Last_SQL_Errno"` Lag sql.NullFloat64 `db:"Seconds_Behind_Source"` } @@ -95,12 +99,14 @@ type ReplicaStatus interface { ReplicationSQLRunning() bool ReplicationRunning() bool ReplicationState() string + GetLastError() string GetMasterHost() string GetMasterLogFile() string GetReadMasterLogPos() int64 GetExecutedGtidSet() string GetRetrievedGtidSet() string GetLastIOErrno() int + GetLastIOError() string GetLastSQLErrno() int GetReplicationLag() sql.NullFloat64 } @@ -144,6 +150,14 @@ func (ss *SlaveStatusStruct) GetLastIOErrno() int { return ss.LastIOErrno } +func (ss *SlaveStatusStruct) GetLastError() string { + return ss.LastError +} + +func (ss *SlaveStatusStruct) GetLastIOError() string { + return ss.LastIOError +} + func (ss *SlaveStatusStruct) GetLastSQLErrno() int { return ss.LastSQLErrno } @@ -211,7 +225,13 @@ func (ss *ReplicaStatusStruct) GetReplicationLag() sql.NullFloat64 { return ss.Lag } -//GetReplicationLag +func (ss *ReplicaStatusStruct) GetLastError() string { + return ss.LastError +} + +func (ss *ReplicaStatusStruct) GetLastIOError() string { + return ss.LastIOError +} // ReplicationState ... func (ss *SlaveStatusStruct) ReplicationState() string {