Skip to content

Commit

Permalink
fix: enabling semisync; feat: errno in logs (#103)
Browse files Browse the repository at this point in the history
* fix: enabling semisync; feat: errno in logs

* fix: issues

* fix: issues
  • Loading branch information
Fizic authored May 27, 2024
1 parent d74946f commit 8173179
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
16 changes: 13 additions & 3 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,17 @@ 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 {
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)
}
app.writeResetupFile("")
} else {
readOnly, _, err := localNode.IsReadOnly()
Expand Down Expand Up @@ -1067,9 +1077,9 @@ 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()
err = node.RestartReplica()
if err != nil {
app.logger.Errorf("failed restart slave io thread after set semi_sync_slave on %s: %s", host, err)
app.logger.Errorf("failed restart replication after set semi_sync_slave on %s: %s", host, err)
return err
}
return nil
Expand Down
22 changes: 21 additions & 1 deletion internal/mysql/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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"`
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 10 additions & 1 deletion internal/mysql/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,15 @@ func (n *Node) StartSlave() error {
})
}

// RestartReplica restart replication
func (n *Node) RestartReplica() 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{}{
Expand All @@ -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 {
Expand Down

0 comments on commit 8173179

Please sign in to comment.