Skip to content

Commit

Permalink
Fix switchover when many connection appear
Browse files Browse the repository at this point in the history
  • Loading branch information
noname0443 committed Sep 17, 2024
1 parent ba47dbf commit b461bfc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ replication_repair_max_attempts: 3
external_replication_type: off
show_only_gtid_diff: False
force_switchover: False
```

### Usage
Expand Down
15 changes: 15 additions & 0 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -182,6 +183,7 @@ func DefaultConfig() (Config, error) {
ReplMonErrorWaitInterval: 10 * time.Second,
ReplMonSlaveWaitInterval: 10 * time.Second,
ShowOnlyGTIDDiff: false,
ForceSwitchover: false,
}
return config, nil
}
Expand Down
1 change: 1 addition & 0 deletions tests/images/mysql/mysync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ replication_channel: ''
external_replication_type: 'external'
show_only_gtid_diff: false
repl_mon: ${REPL_MON:-false}
force_switchover: false

0 comments on commit b461bfc

Please sign in to comment.