From f2046c45f220d3161c35697d0042ba0a4fd5ab12 Mon Sep 17 00:00:00 2001 From: suetin Date: Mon, 17 Jun 2024 16:14:54 +0300 Subject: [PATCH 1/2] async: refactor AsyncAllowedLag to time.Duration --- internal/app/async.go | 3 ++- internal/config/config.go | 4 ++-- internal/mysql/switch_helper.go | 5 ++--- tests/features/async_setting.feature | 8 ++++---- tests/images/mysql/mysync.yaml | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/app/async.go b/internal/app/async.go index 43dc2bd8..faa23951 100644 --- a/internal/app/async.go +++ b/internal/app/async.go @@ -2,6 +2,7 @@ package app import ( "fmt" + "time" "github.com/yandex/mysync/internal/mysql" ) @@ -19,7 +20,7 @@ func (app *App) CheckAsyncSwitchAllowed(node *mysql.Node, switchover *Switchover app.logger.Errorf("failed to calc mdb repl mon ts: %v", err) return false } - if delay < app.config.AsyncAllowedLag { + if time.Duration(delay) * time.Second < 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) return true diff --git a/internal/config/config.go b/internal/config/config.go index b27bc3c6..5fe6b956 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 time.Duration `config:"async_allowed_lag" yaml:"async_allowed_lag"` ReplMon bool `config:"repl_mon" yaml:"repl_mon"` ReplMonSchemeName string `config:"repl_mon_scheme_name" yaml:"repl_mon_scheme_name"` ReplMonTableName string `config:"repl_mon_table_name" yaml:"repl_mon_table_name"` @@ -173,7 +173,7 @@ func DefaultConfig() (Config, error) { ExternalReplicationChannel: "external", ExternalReplicationType: util.Disabled, ASync: false, - AsyncAllowedLag: 0, + AsyncAllowedLag: 0 * time.Second, ReplMon: false, ReplMonSchemeName: "mysql", ReplMonTableName: "mysync_repl_mon", diff --git a/internal/mysql/switch_helper.go b/internal/mysql/switch_helper.go index d6d342ba..b880fc53 100644 --- a/internal/mysql/switch_helper.go +++ b/internal/mysql/switch_helper.go @@ -17,9 +17,8 @@ type SwitchHelper struct { func NewSwitchHelper(config *config.Config) ISwitchHelper { priorityChoiceMaxLag := config.PriorityChoiceMaxLag if config.ASync { - AsyncAllowedLagTime := time.Duration(config.AsyncAllowedLag) * time.Second - if AsyncAllowedLagTime > config.PriorityChoiceMaxLag { - priorityChoiceMaxLag = AsyncAllowedLagTime + if config.AsyncAllowedLag > config.PriorityChoiceMaxLag { + priorityChoiceMaxLag = config.AsyncAllowedLag } } return &SwitchHelper{ diff --git a/tests/features/async_setting.feature b/tests/features/async_setting.feature index a37c8855..5423e3a2 100644 --- a/tests/features/async_setting.feature +++ b/tests/features/async_setting.feature @@ -5,7 +5,7 @@ Feature: mysync async mode tests """ MYSYNC_SEMISYNC=false MYSYNC_ASYNC=true - ASYNC_ALLOWED_LAG=120 + ASYNC_ALLOWED_LAG=120s MYSYNC_REPLICATION_LAG_QUERY="SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) - UNIX_TIMESTAMP(ts) AS Seconds_Behind_Master FROM mysql.mysync_repl_mon" MYSYNC_FAILOVER=true MYSYNC_FAILOVER_DELAY=0s @@ -101,7 +101,7 @@ Feature: mysync async mode tests """ MYSYNC_SEMISYNC=false MYSYNC_ASYNC=true - ASYNC_ALLOWED_LAG=60 + ASYNC_ALLOWED_LAG=60s MYSYNC_REPLICATION_LAG_QUERY="SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) - UNIX_TIMESTAMP(ts) AS Seconds_Behind_Master FROM mysql.mysync_repl_mon" MYSYNC_FAILOVER=true MYSYNC_FAILOVER_DELAY=0s @@ -206,7 +206,7 @@ Feature: mysync async mode tests """ MYSYNC_SEMISYNC=false MYSYNC_ASYNC=true - ASYNC_ALLOWED_LAG=120 + ASYNC_ALLOWED_LAG=120s MYSYNC_REPLICATION_LAG_QUERY="SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) - UNIX_TIMESTAMP(ts) AS Seconds_Behind_Master FROM mysql.mysync_repl_mon" MYSYNC_FAILOVER=true MYSYNC_FAILOVER_DELAY=0s @@ -314,7 +314,7 @@ Feature: mysync async mode tests """ MYSYNC_SEMISYNC=false MYSYNC_ASYNC=true - ASYNC_ALLOWED_LAG=50 + ASYNC_ALLOWED_LAG=50s MYSYNC_REPLICATION_LAG_QUERY="SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) - UNIX_TIMESTAMP(ts) AS Seconds_Behind_Master FROM mysql.mysync_repl_mon" MYSYNC_FAILOVER=true MYSYNC_FAILOVER_DELAY=0s diff --git a/tests/images/mysql/mysync.yaml b/tests/images/mysql/mysync.yaml index 96a126d5..35d82840 100644 --- a/tests/images/mysql/mysync.yaml +++ b/tests/images/mysql/mysync.yaml @@ -11,7 +11,7 @@ failover_delay: ${MYSYNC_FAILOVER_DELAY:-0s} inactivation_delay: ${MYSYNC_INACTIVATION_DELAY:-5s} semi_sync: ${MYSYNC_SEMISYNC:-true} async: ${MYSYNC_ASYNC:-false} -async_allowed_lag: ${ASYNC_ALLOWED_LAG:-0} +async_allowed_lag: ${ASYNC_ALLOWED_LAG:-0s} resetupfile: /tmp/mysync.resetup resetup_crashed_hosts: ${MYSYNC_RESETUP_CRASHED_HOSTS:-false} zookeeper: From 036e3f5dba0285be6554460b3372850b2237704c Mon Sep 17 00:00:00 2001 From: suetin Date: Mon, 17 Jun 2024 16:46:19 +0300 Subject: [PATCH 2/2] linters fix --- internal/app/async.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/app/async.go b/internal/app/async.go index faa23951..01449080 100644 --- a/internal/app/async.go +++ b/internal/app/async.go @@ -20,7 +20,7 @@ func (app *App) CheckAsyncSwitchAllowed(node *mysql.Node, switchover *Switchover app.logger.Errorf("failed to calc mdb repl mon ts: %v", err) return false } - if time.Duration(delay) * time.Second < app.config.AsyncAllowedLag { + if time.Duration(delay)*time.Second < 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) return true