Skip to content

Commit

Permalink
fix PriorityChoiceMaxLag in async mode
Browse files Browse the repository at this point in the history
  • Loading branch information
suetin committed Mar 20, 2024
1 parent 71f4403 commit 091024c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Check failure on line 91 in internal/config/config.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
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
Expand Down Expand Up @@ -167,7 +167,7 @@ func DefaultConfig() (Config, error) {
ExternalReplicationChannel: "external",
ExternalReplicationType: util.Disabled,
ASync: false,
ASyncAllowedLag: 0,
AsyncAllowedLag: 0,
}
return config, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/mysql/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
}

0 comments on commit 091024c

Please sign in to comment.