Skip to content

Commit

Permalink
Merge pull request #792 from signal18/proxysql
Browse files Browse the repository at this point in the history
When readonmasternoslave tag is set and bootstrap is ON,  make proxysql master as reader if no valid reader
  • Loading branch information
caffeinated92 authored Aug 7, 2024
2 parents 66b4aeb + 1e84232 commit 420b486
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions cluster/prx_proxysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func (proxy *ProxySQLProxy) Refresh() error {
}
updated = true

} else if s.IsLeader() && !isFoundBackendRead && (cluster.Configurator.HasProxyReadLeader() || (cluster.Configurator.HasProxyReadLeaderNoSlave() && cluster.HasNoValidSlave())) {
} else if s.IsLeader() && !isFoundBackendRead && (cluster.Configurator.HasProxyReadLeader() || (cluster.Configurator.HasProxyReadLeaderNoSlave() && (cluster.HasNoValidSlave() || !proxy.HasAvailableReader()))) {
// Add leader in reader group if not found and setup
// if cluster.Conf.ProxysqlDebug {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModProxySQL, config.LvlDbg, "Monitor ProxySQL add leader in reader group in %s", s.URL)
Expand All @@ -393,7 +393,7 @@ func (proxy *ProxySQLProxy) Refresh() error {
} else if s.IsLeader() && isFoundBackendRead && (!cluster.Configurator.HasProxyReadLeader()) {
// Drop the leader in reader group if not found and setup
// Cancel learder remove because no valid reader
if !cluster.Configurator.HasProxyReadLeaderNoSlave() || (cluster.Configurator.HasProxyReadLeaderNoSlave() && !cluster.HasNoValidSlave()) {
if !cluster.Configurator.HasProxyReadLeaderNoSlave() || (cluster.Configurator.HasProxyReadLeaderNoSlave() && !(cluster.HasNoValidSlave() || proxy.HasAvailableReader())) {
// if cluster.Conf.ProxysqlDebug {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModProxySQL, config.LvlDbg, "Monitor ProxySQL Drop the leader in reader group from %s", s.URL)
// }
Expand All @@ -420,13 +420,14 @@ func (proxy *ProxySQLProxy) Refresh() error {

// //Set the alert if proxysql status is OFFLINE_SOFT
if (bke.PrxStatus == "OFFLINE_SOFT" || bkeread.PrxStatus == "OFFLINE_SOFT") && !s.IsMaintenance {
if !cluster.StateMachine.IsInState("ERR00091") {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModProxySQL, config.LvlWarn, clusterError["ERR00091"], proxy.Name, s.URL)
}
cluster.SetState("ERR00091", state.State{ErrType: "WARNING", ErrDesc: fmt.Sprintf(clusterError["ERR00091"], proxy.Name, s.URL), ErrFrom: "PRX", ServerUrl: proxy.Name})
// s.SwitchMaintenance()
}

if s.IsLeader() && !isFoundBackendRead && (cluster.Configurator.HasProxyReadLeader() || (cluster.Configurator.HasProxyReadLeaderNoSlave() && (cluster.HasNoValidSlave() || !proxy.HasAvailableReader()))) {
cluster.SetState("ERR00093", state.State{ErrType: "WARNING", ErrDesc: fmt.Sprintf(clusterError["ERR00093"], proxy.Name), ErrFrom: "PRX", ServerUrl: proxy.Name})
}

// load the grants
if s.IsMaster() && cluster.Conf.ProxysqlCopyGrants {
myprxusermap, _, err := dbhelper.GetProxySQLUsers(psql.Connection)
Expand Down
1 change: 1 addition & 0 deletions config/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var ClusterError = map[string]string{
"ERR00090": "Monitoring save config enable but no encryption key for password, see the keygen command",
"ERR00091": "Proxysql %s found active server %s as OFFLINE_SOFT in ProxySQL.",
"ERR00092": "Cluster [%s] topology (%s) is not same with target topology (%s).",
"ERR00093": "Proxysql %s has read on master no slave and found no active reader but bootstrap is turned off.",
"WARN0022": "Rejoining standalone server %s to master %s",
"WARN0023": "Number of failed master ping has been reached",
"WARN0045": "Provision task is in queue",
Expand Down

0 comments on commit 420b486

Please sign in to comment.