Skip to content

Commit

Permalink
async: refactor AsyncAllowedLag to time.Duration
Browse files Browse the repository at this point in the history
  • Loading branch information
suetin committed Jun 17, 2024
1 parent 6937a8b commit 95aa919
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
3 changes: 2 additions & 1 deletion internal/app/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"fmt"
"time"

"github.com/yandex/mysync/internal/mysql"
)
Expand All @@ -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
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"`
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"`
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions internal/mysql/switch_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions tests/features/async_setting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/images/mysql/mysync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 95aa919

Please sign in to comment.