Skip to content

Commit d6f9f45

Browse files
committed
replace-writer-from-reader-list
1 parent f667875 commit d6f9f45

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

cluster/prx_proxysql.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (proxy *ProxySQLProxy) Failover() {
231231
}
232232
}
233233
if s.IsMaster() && !s.IsRelay && cluster.oldMaster != nil {
234-
err = psql.ReplaceWriter(misc.Unbracket(s.Host), s.Port, misc.Unbracket(cluster.oldMaster.Host), cluster.oldMaster.Port, cluster.Configurator.HasProxyReadLeader(), proxy.UseSSL())
234+
err = psql.ReplaceWriter(misc.Unbracket(s.Host), s.Port, misc.Unbracket(cluster.oldMaster.Host), cluster.oldMaster.Port, cluster.Configurator.HasProxyReadLeader())
235235
if err != nil {
236236
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModProxySQL, LvlErr, "Failover ProxySQL could not set server %s Master (%s)", s.URL, err)
237237
} else {

router/proxysql/proxysql.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,20 @@ func (psql *ProxySQL) ReloadTLS() error {
236236
return err
237237
}
238238

239-
func (psql *ProxySQL) ReplaceWriter(host string, port string, oldhost string, oldport string, masterasreader bool, use_ssl string) error {
239+
func (psql *ProxySQL) CopyReaderToWriter(host string, port string) error {
240+
sql := fmt.Sprintf("REPLACE INTO mysql_servers (hostgroup_id, hostname, port, gtid_port, status, weight, compression, max_connections, max_replication_lag, use_ssl, max_latency_ms) SELECT '%s', hostname, port, gtid_port, status, weight, compression, max_connections, max_replication_lag, use_ssl, max_latency_ms FROM mysql_servers WHERE hostgroup_id = '%s' AND hostname = '%s' AND port = '%s'", psql.WriterHG, psql.ReaderHG, host, port)
241+
_, err := psql.Connection.Exec(sql)
242+
return err
243+
}
244+
245+
func (psql *ProxySQL) ReplaceWriter(host string, port string, oldhost string, oldport string, masterasreader bool) error {
240246

241247
if masterasreader {
242248
err := psql.DeleteAllWriters()
243249
if err != nil {
244250
return err
245251
}
246-
err = psql.AddServerAsWriter(host, port, use_ssl)
252+
err = psql.CopyReaderToWriter(host, port)
247253
return err
248254
} else {
249255
err := psql.SetReader(oldhost, oldport)

0 commit comments

Comments
 (0)