From b461bfc2d77115219a5ee948140f35b21af44372 Mon Sep 17 00:00:00 2001 From: noname0443 Date: Tue, 17 Sep 2024 15:38:13 +0300 Subject: [PATCH] Fix switchover when many connection appear --- README.md | 1 + internal/app/app.go | 15 +++++++++++++++ internal/config/config.go | 2 ++ tests/images/mysql/mysync.yaml | 1 + 4 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 2b9e6159..7619bf50 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,7 @@ replication_repair_max_attempts: 3 external_replication_type: off show_only_gtid_diff: False +force_switchover: False ``` ### Usage diff --git a/internal/app/app.go b/internal/app/app.go index 02f79fe4..f143eb48 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -1208,6 +1208,21 @@ func (app *App) performSwitchover(clusterState map[string]*NodeState, activeNode } node := app.cluster.Get(host) // in case node is a master + + if app.config.ForceSwitchover { + err := node.SetOffline() + if err != nil { + app.logger.Infof("switchover: failed to set node %s offline: %v", host, err) + return fmt.Errorf("failed to set node %s read-only: %v", host, err) + } + + err = node.SemiSyncDisable() + if err != nil { + app.logger.Infof("switchover: failed to disable semi-sync on node %s: %v", host, err) + return fmt.Errorf("failed to set node %s read-only: %v", host, err) + } + } + err := node.SetReadOnly(true) if err != nil || app.emulateError("freeze_ro") { app.logger.Infof("switchover: failed to set node %s read-only, trying kill bad queries: %v", host, err) diff --git a/internal/config/config.go b/internal/config/config.go index 21b00332..d4d3c8d6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -97,6 +97,7 @@ type Config struct { ReplMonErrorWaitInterval time.Duration `config:"repl_mon_error_wait_interval" yaml:"repl_mon_error_wait_interval"` ReplMonSlaveWaitInterval time.Duration `config:"repl_mon_slave_wait_interval" yaml:"repl_mon_slave_wait_interval"` ShowOnlyGTIDDiff bool `config:"show_only_gtid_diff" yaml:"show_only_gtid_diff"` + ForceSwitchover bool `config:"force_switchover" yaml:"force_switchover"` } // DefaultConfig returns default configuration for MySync @@ -182,6 +183,7 @@ func DefaultConfig() (Config, error) { ReplMonErrorWaitInterval: 10 * time.Second, ReplMonSlaveWaitInterval: 10 * time.Second, ShowOnlyGTIDDiff: false, + ForceSwitchover: false, } return config, nil } diff --git a/tests/images/mysql/mysync.yaml b/tests/images/mysql/mysync.yaml index a2a47a3d..72a8cd60 100644 --- a/tests/images/mysql/mysync.yaml +++ b/tests/images/mysql/mysync.yaml @@ -62,3 +62,4 @@ replication_channel: '' external_replication_type: 'external' show_only_gtid_diff: false repl_mon: ${REPL_MON:-false} +force_switchover: false