diff --git a/internal/app/app.go b/internal/app/app.go index 2df2db6f..83280e28 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -1223,8 +1223,13 @@ func (app *App) performSwitchover(clusterState map[string]*NodeState, activeNode newMaster = switchover.To } else if switchover.From != "" { positions2 := filterOutNodeFromPositions(positions, switchover.From) + PriorityChoiceMaxLag := app.config.PriorityChoiceMaxLag + AsyncAllowedLagTime := time.Duration(app.config.AsyncAllowedLag) * time.Second + if app.config.ASync && switchover.Cause == CauseAuto && AsyncAllowedLagTime > app.config.PriorityChoiceMaxLag { + PriorityChoiceMaxLag = AsyncAllowedLagTime + } // we ignore splitbrain flag as it should be handled during searching most recent host - newMaster, err = getMostDesirableNode(app.logger, positions2, app.config.PriorityChoiceMaxLag) + newMaster, err = getMostDesirableNode(app.logger, positions2, PriorityChoiceMaxLag) if err != nil { return fmt.Errorf("switchover: error while looking for highest priority node: %s", switchover.From) } @@ -2143,9 +2148,9 @@ func (app *App) waitForCatchUp(node *mysql.Node, gtidset gtids.GTIDSet, timeout app.logger.Errorf("failed to calc mdb repl mon ts: %v", err) continue } - if delay < app.config.ASyncAllowedLag { + if delay < app.config.AsyncAllowedLag { app.logger.Infof("async allowed lag is %d and current lag on host %s is %d, so we don't wait for catch up any more", - app.config.ASyncAllowedLag, node.Host(), delay) + app.config.AsyncAllowedLag, node.Host(), delay) return true, nil } } diff --git a/internal/config/config.go b/internal/config/config.go index aef8f6f8..e9066850 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -89,7 +89,7 @@ type Config struct { ExternalReplicationChannel string `config:"external_replication_channel" yaml:"external_replication_channel"` ExternalReplicationType util.ExternalReplicationType `config:"external_replication_type" yaml:"external_replication_type"` ASync bool `config:"async" yaml:"async"` - ASyncAllowedLag int64 `config:"async_allowed_lag" yaml:"async_allowed_lag"` + AsyncAllowedLag int64 `config:"async_allowed_lag" yaml:"async_allowed_lag"` } // DefaultConfig returns default configuration for MySync @@ -167,7 +167,7 @@ func DefaultConfig() (Config, error) { ExternalReplicationChannel: "external", ExternalReplicationType: util.Disabled, ASync: false, - ASyncAllowedLag: 0, + AsyncAllowedLag: 0, } return config, nil } diff --git a/internal/mysql/queries.go b/internal/mysql/queries.go index d4641054..250893a8 100644 --- a/internal/mysql/queries.go +++ b/internal/mysql/queries.go @@ -126,5 +126,5 @@ var DefaultQueries = map[string]string{ 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 UNIX_TIMESTAMP(CURRENT_TIMESTAMP(0)) - CAST(:ts AS DECIMAL(20,0)) AS delay`, + queryCalcMdbReplMonTsDelay: `SELECT FLOOR(CAST(:ts AS DECIMAL(20,3)) - UNIX_TIMESTAMP(ts)) AS ts FROM mysql.mdb_repl_mon AS delay`, }