diff --git a/internal/app/app.go b/internal/app/app.go index 85237f1a..2426bc12 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -1210,15 +1210,8 @@ func (app *App) performSwitchover(clusterState map[string]*NodeState, activeNode // in case node is a master if app.config.ForceSwitchover { - err := node.SetOffline() - if err != nil { - return fmt.Errorf("switchover: failed to set node %s offline: %v", host, err) - } - - err = node.SemiSyncDisable() - if err != nil { - return fmt.Errorf("switchover: failed to disable semi-sync on node %s: %v", host, err) - } + node.SetOfflineForce() + defer node.SetOnline() } err := node.SetReadOnly(true) diff --git a/internal/config/config.go b/internal/config/config.go index d4d3c8d6..88837a7b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -97,7 +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"` + ForceSwitchover bool `config:"force_switchover" yaml:"force_switchover"` // TODO: Remove when we will be sure it's right way to do switchover } // DefaultConfig returns default configuration for MySync diff --git a/internal/mysql/node.go b/internal/mysql/node.go index 4475e56a..94b01937 100644 --- a/internal/mysql/node.go +++ b/internal/mysql/node.go @@ -833,6 +833,20 @@ func (n *Node) SetOnline() error { return n.exec(queryDisableOfflineMode, nil) } +func (n *Node) SetOfflineForce() error { + err := n.SemiSyncDisable() + if err != nil { + return fmt.Errorf("failed to disable semi-sync on node %s: %v", n.host, err) + } + + err = n.SetOffline() + if err != nil { + return fmt.Errorf("failed to set node %s offline: %v", n.host, err) + } + + return nil +} + // ChangeMaster changes master of MySQL Node, demoting it to slave func (n *Node) ChangeMaster(host string) error { useSsl := 0