Skip to content

Commit

Permalink
async mode: add tests, fix linters
Browse files Browse the repository at this point in the history
  • Loading branch information
suetin committed Mar 27, 2024
1 parent b685481 commit 2bfb126
Show file tree
Hide file tree
Showing 11 changed files with 507 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker-tests-8.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
command:
- 'VERSION=8.0 GODOG_FEATURE=active_nodes.feature make test'
- 'VERSION=8.0 GODOG_FEATURE=async.feature make test'
- 'VERSION=8.0 GODOG_FEATURE=async_setting.feature.feature make test'
- 'VERSION=8.0 GODOG_FEATURE=cascade_replicas.feature make test'
- 'VERSION=8.0 GODOG_FEATURE=CLI.feature make test'
- 'VERSION=8.0 GODOG_FEATURE=crash_recovery.feature make test'
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/docker-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ jobs:
matrix:
command:
- 'GODOG_FEATURE=active_nodes.feature make test'
- 'GODOG_FEATURE=async.feature make test'
- 'GODOG_FEATURE=async.feature make test'
- 'GODOG_FEATURE=async_setting.feature.feature make test'
- 'GODOG_FEATURE=cascade_replicas.feature make test'
- 'GODOG_FEATURE=CLI.feature make test'
- 'GODOG_FEATURE=crash_recovery.feature make test'
Expand Down
12 changes: 6 additions & 6 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func (app *App) stateManager() appState {
app.logger.Errorf("failed to update active nodes in dcs: %v", err)
}

err = app.updateMdbReplMonTs(master)
err = app.updateMdbReplMonTS(master)
if err != nil {
app.logger.Errorf("failed to update mdb_repl_mon timestamp: %v", err)
}
Expand Down Expand Up @@ -2138,12 +2138,12 @@ func (app *App) waitForCatchUp(node *mysql.Node, gtidset gtids.GTIDSet, timeout
}
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.GetMdbReplMonTS()
if err != nil {
app.logger.Errorf("failed to get mdb repl mon ts: %v", err)
continue
}
delay, err := node.CalcMdbReplMonTsDelay(ts)
delay, err := node.CalcMdbReplMonTSDelay(ts)
if err != nil {
app.logger.Errorf("failed to calc mdb repl mon ts: %v", err)
continue
Expand Down Expand Up @@ -2257,13 +2257,13 @@ func (app *App) getNodePositions(activeNodes []string) ([]nodePosition, error) {
return positions, util.CombineErrors(errs)
}

func (app *App) updateMdbReplMonTs(master string) error {
func (app *App) updateMdbReplMonTS(master string) error {
masterNode := app.cluster.Get(master)
ts, err := masterNode.GetMdbReplMonTs()
ts, err := masterNode.GetMdbReplMonTS()
if err != nil {
return fmt.Errorf("failed to get master mdb_repl_mon timestamp: %v", err)
}
return app.SetMdbReplMonTs(ts)
return app.SetMdbReplMonTS(ts)
}

/*
Expand Down
6 changes: 3 additions & 3 deletions internal/app/app_dcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (app *App) GetMasterHostFromDcs() (string, error) {
return "", nil
}

func (app *App) SetMdbReplMonTs(ts string) error {
func (app *App) SetMdbReplMonTS(ts string) error {
err := app.dcs.Create(pathMasterReplMonTs, ts)
if err != nil && err != dcs.ErrExists {
return err
Expand All @@ -241,11 +241,11 @@ func (app *App) SetMdbReplMonTs(ts string) error {
return nil
}

func (app *App) GetMdbReplMonTs() (string, error) {
func (app *App) GetMdbReplMonTS() (string, error) {
var ts string
err := app.dcs.Get(pathMasterReplMonTs, &ts)
if errors.Is(err, dcs.ErrNotFound) {
return "", nil
}
return ts, err
}
}
8 changes: 4 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ type Config struct {
ReplicationChannel string `config:"replication_channel" yaml:"replication_channel"`
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"`
ASync bool `config:"async" yaml:"async"`
AsyncAllowedLag int64 `config:"async_allowed_lag" yaml:"async_allowed_lag"`
}

// DefaultConfig returns default configuration for MySync
Expand Down Expand Up @@ -166,8 +166,8 @@ func DefaultConfig() (Config, error) {
ReplicationChannel: "",
ExternalReplicationChannel: "external",
ExternalReplicationType: util.Disabled,
ASync: false,
AsyncAllowedLag: 0,
ASync: false,
AsyncAllowedLag: 0,
}
return config, nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/mysql/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ type Version struct {
PatchVersion int `db:"PatchVersion"`
}

type MdbReplMonTs struct {
type MdbReplMonTS struct {
Timestamp string `db:"ts"`
}

type MdbReplMonTsDelay struct {
type MdbReplMonTSDelay struct {
Delay int64 `db:"delay"`
}

Expand Down
10 changes: 5 additions & 5 deletions internal/mysql/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,14 +986,14 @@ func (n *Node) SetDefaultReplicationSettings(masterNode *Node) error {
return nil
}

func (n *Node) GetMdbReplMonTs() (string, error) {
result := new(MdbReplMonTs)
func (n *Node) GetMdbReplMonTS() (string, error) {
result := new(MdbReplMonTS)
err := n.queryRow(queryGetMdbReplMonTs, nil, 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) CalcMdbReplMonTSDelay(ts string) (int64, error) {
result := new(MdbReplMonTSDelay)
err := n.queryRow(queryCalcMdbReplMonTSDelay, map[string]interface{}{"ts": ts}, result)
return result.Delay, err
}
8 changes: 4 additions & 4 deletions internal/mysql/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,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"
queryGetMdbReplMonTs = "get_mdb_repl_mon_ts"
queryCalcMdbReplMonTSDelay = "calc_mdb_repl_mon_ts_delay"

Check failure on line 49 in internal/mysql/queries.go

View workflow job for this annotation

GitHub Actions / lint

ST1003: const queryGetMdbReplMonTs should be queryGetMdbReplMonTS (stylecheck)
)

var DefaultQueries = map[string]string{
Expand Down Expand Up @@ -125,6 +125,6 @@ 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`,
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`,
}
Loading

0 comments on commit 2bfb126

Please sign in to comment.