diff --git a/internal/app/app.go b/internal/app/app.go index 4c0785cb..fec74e66 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -745,9 +745,9 @@ func (app *App) stateManager() appState { app.logger.Errorf("failed to update active nodes in dcs: %v", err) } - err = app.updateMdbReplMonTS(master) + err = app.updateReplMonTS(master) if err != nil { - app.logger.Errorf("failed to update mdb_repl_mon timestamp: %v", err) + app.logger.Errorf("failed to update repl_mon timestamp: %v", err) } return stateManager diff --git a/internal/app/app_dcs.go b/internal/app/app_dcs.go index 1832e753..77e1d174 100644 --- a/internal/app/app_dcs.go +++ b/internal/app/app_dcs.go @@ -229,7 +229,7 @@ func (app *App) GetMasterHostFromDcs() (string, error) { return "", nil } -func (app *App) SetMdbReplMonTS(ts string) error { +func (app *App) SetReplMonTS(ts string) error { err := app.dcs.Create(pathMasterReplMonTS, ts) if err != nil && err != dcs.ErrExists { return err @@ -241,7 +241,7 @@ func (app *App) SetMdbReplMonTS(ts string) error { return nil } -func (app *App) GetMdbReplMonTS() (string, error) { +func (app *App) GetReplMonTS() (string, error) { var ts string err := app.dcs.Get(pathMasterReplMonTS, &ts) if errors.Is(err, dcs.ErrNotFound) { diff --git a/internal/app/async.go b/internal/app/async.go index c36780d6..d6cd1118 100644 --- a/internal/app/async.go +++ b/internal/app/async.go @@ -8,12 +8,12 @@ import ( func (app *App) CheckAsyncSwitchAllowed(node *mysql.Node, switchover *Switchover) bool { if app.config.ASync && switchover.Cause == CauseAuto { app.logger.Infof("async mode is active and this is auto switch so we checking new master delay") - ts, err := app.GetMdbReplMonTS() + ts, err := app.GetReplMonTS() if err != nil { app.logger.Errorf("failed to get mdb repl mon ts: %v", err) return false } - delay, err := node.CalcMdbReplMonTSDelay(ts) + delay, err := node.CalcReplMonTSDelay(app.config.ReplMonTableName, ts) if err != nil { app.logger.Errorf("failed to calc mdb repl mon ts: %v", err) return false @@ -27,11 +27,11 @@ func (app *App) CheckAsyncSwitchAllowed(node *mysql.Node, switchover *Switchover return false } -func (app *App) updateMdbReplMonTS(master string) error { +func (app *App) updateReplMonTS(master string) error { masterNode := app.cluster.Get(master) - ts, err := masterNode.GetMdbReplMonTS() + ts, err := masterNode.GetReplMonTS(app.config.ReplMonTableName) if err != nil { - return fmt.Errorf("failed to get master mdb_repl_mon timestamp: %v", err) + return fmt.Errorf("failed to get master repl_mon timestamp: %v", err) } - return app.SetMdbReplMonTS(ts) + return app.SetReplMonTS(ts) } \ No newline at end of file diff --git a/internal/app/data.go b/internal/app/data.go index 7d0a0529..30db8d10 100644 --- a/internal/app/data.go +++ b/internal/app/data.go @@ -68,7 +68,7 @@ const ( pathLastShutdownNodeTime = "last_shutdown_node_time" - // last known timestamp from mysql.mdb_repl_mon + // last known timestamp from repl_mon table pathMasterReplMonTS = "master_repl_mon_ts" ) diff --git a/internal/mysql/data.go b/internal/mysql/data.go index c3c03b8d..519d63f2 100644 --- a/internal/mysql/data.go +++ b/internal/mysql/data.go @@ -272,11 +272,11 @@ type Version struct { PatchVersion int `db:"PatchVersion"` } -type MdbReplMonTS struct { +type ReplMonTS struct { Timestamp string `db:"ts"` } -type MdbReplMonTSDelay struct { +type ReplMonTSDelay struct { Delay int64 `db:"delay"` } diff --git a/internal/mysql/node.go b/internal/mysql/node.go index f72b16b3..c5c739b0 100644 --- a/internal/mysql/node.go +++ b/internal/mysql/node.go @@ -1005,15 +1005,15 @@ func (n *Node) SetDefaultReplicationSettings(masterNode *Node) error { return nil } -func (n *Node) GetMdbReplMonTS() (string, error) { - result := new(MdbReplMonTS) - err := n.queryRow(queryGetMdbReplMonTS, nil, result) +func (n *Node) GetReplMonTS(replMonTable string) (string, error) { + result := new(ReplMonTS) + err := n.queryRow(queryGetReplMonTS, map[string]interface{}{"replMonTable": replMonTable}, result) return result.Timestamp, err } -func (n *Node) CalcMdbReplMonTSDelay(ts string) (int64, error) { - result := new(MdbReplMonTSDelay) - err := n.queryRow(queryCalcMdbReplMonTSDelay, map[string]interface{}{"ts": ts}, result) +func (n *Node) CalcReplMonTSDelay(replMonTable string, ts string) (int64, error) { + result := new(ReplMonTSDelay) + err := n.queryRow(queryCalcReplMonTSDelay, map[string]interface{}{"ts": ts, "replMonTable": replMonTable}, result) return result.Delay, err } diff --git a/internal/mysql/queries.go b/internal/mysql/queries.go index 946b527b..24b68b97 100644 --- a/internal/mysql/queries.go +++ b/internal/mysql/queries.go @@ -46,8 +46,8 @@ const ( querySetInnodbFlushLogAtTrxCommit = "set_innodb_flush_log_at_trx_commit" querySetSyncBinlog = "set_sync_binlog" queryGetReplicationSettings = "get_replication_settings" - queryGetMdbReplMonTS = "get_mdb_repl_mon_ts" - queryCalcMdbReplMonTSDelay = "calc_mdb_repl_mon_ts_delay" + queryGetReplMonTS = "get_repl_mon_ts" + queryCalcReplMonTSDelay = "calc_repl_mon_ts_delay" queryCreateReplMonTable = "create_repl_mon_table" queryUpdateReplMon = "update_repl_mon" ) @@ -129,8 +129,8 @@ var DefaultQueries = map[string]string{ querySetInnodbFlushLogAtTrxCommit: `SET GLOBAL innodb_flush_log_at_trx_commit = :level`, queryGetReplicationSettings: `SELECT @@innodb_flush_log_at_trx_commit as InnodbFlushLogAtTrxCommit, @@sync_binlog as SyncBinlog`, querySetSyncBinlog: `SET GLOBAL sync_binlog = :sync_binlog`, - queryGetMdbReplMonTS: `SELECT UNIX_TIMESTAMP(ts) AS ts FROM mysql.mdb_repl_mon`, - queryCalcMdbReplMonTSDelay: `SELECT FLOOR(CAST(:ts AS DECIMAL(20,3)) - UNIX_TIMESTAMP(ts)) AS delay FROM mysql.mdb_repl_mon`, + queryGetReplMonTS: `SELECT UNIX_TIMESTAMP(ts) AS ts FROM :replMonTable`, + queryCalcReplMonTSDelay: `SELECT FLOOR(CAST(:ts AS DECIMAL(20,3)) - UNIX_TIMESTAMP(ts)) AS delay FROM :replMonTable`, queryCreateReplMonTable: `CREATE TABLE IF NOT EXISTS :replMonTable ( id INT NOT NULL PRIMARY KEY, ts TIMESTAMP(3)