Skip to content

Commit

Permalink
Add extra parameter tout failover scripts passing string "failover" o…
Browse files Browse the repository at this point in the history
…r "switchover"
  • Loading branch information
svaroqui committed Nov 25, 2022
1 parent b114681 commit 07082c2
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions cluster/cluster_fail.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (cluster *Cluster) MasterFailover(fail bool) bool {
if cluster.Conf.MultiMaster == false {
cluster.slaves[key].delete(&cluster.slaves)
}
cluster.failoverPreScript()
cluster.failoverPreScript(fail)

// Phase 2: Reject updates and sync slaves on switchover
if fail == false {
Expand Down Expand Up @@ -249,7 +249,7 @@ func (cluster *Cluster) MasterFailover(fail bool) bool {
cluster.LogPrintf(LvlInfo, "Failover proxies")
cluster.failoverProxies()
cluster.failoverProxiesWaitMonitor()
cluster.failoverPostScript()
cluster.failoverPostScript(fail)
cluster.failoverEnableEventScheduler()
// Insert a bogus transaction in order to have a new GTID pos on master
cluster.LogPrintf(LvlInfo, "Inject fake transaction on new master %s ", cluster.master.URL)
Expand Down Expand Up @@ -540,26 +540,37 @@ func (cluster *Cluster) MasterFailover(fail bool) bool {
return true
}

func (cluster *Cluster) failoverPostScript() {
func (cluster *Cluster) failoverPostScript(fail bool) {
if cluster.Conf.PostScript != "" {

var out []byte
var err error

cluster.LogPrintf(LvlInfo, "Calling post-failover script")
out, err = exec.Command(cluster.Conf.PostScript, cluster.oldMaster.Host, cluster.GetMaster().Host, cluster.oldMaster.Port, cluster.GetMaster().Port, cluster.oldMaster.MxsServerName, cluster.GetMaster().MxsServerName).CombinedOutput()
failtype := "failover"
if !fail {
failtype = "switchover"
}
out, err = exec.Command(cluster.Conf.PostScript, cluster.oldMaster.Host, cluster.GetMaster().Host, cluster.oldMaster.Port, cluster.GetMaster().Port, cluster.oldMaster.MxsServerName, cluster.GetMaster().MxsServerName, failtype).CombinedOutput()
if err != nil {
cluster.LogPrintf(LvlErr, "%s", err)
}
cluster.LogPrintf(LvlInfo, "Post-failover script complete %s", string(out))
}
}

func (cluster *Cluster) failoverPreScript() {
func (cluster *Cluster) failoverPreScript(fail bool) {
// Call pre-failover script
if cluster.Conf.PreScript != "" {
failtype := "failover"
if !fail {
failtype = "switchover"
}

cluster.LogPrintf(LvlInfo, "Calling pre-failover script")
var out []byte
var err error
out, err = exec.Command(cluster.Conf.PreScript, cluster.oldMaster.Host, cluster.GetMaster().Host, cluster.oldMaster.Port, cluster.GetMaster().Port, cluster.oldMaster.MxsServerName, cluster.GetMaster().MxsServerName).CombinedOutput()
out, err = exec.Command(cluster.Conf.PreScript, cluster.oldMaster.Host, cluster.GetMaster().Host, cluster.oldMaster.Port, cluster.GetMaster().Port, cluster.oldMaster.MxsServerName, cluster.GetMaster().MxsServerName, failtype).CombinedOutput()
if err != nil {
cluster.LogPrintf(LvlErr, "%s", err)
}
Expand Down Expand Up @@ -1164,7 +1175,7 @@ func (cluster *Cluster) VMasterFailover(fail bool) bool {
}
cluster.vmaster = cluster.Servers[skey]
cluster.master = cluster.Servers[skey]
cluster.failoverPreScript()
cluster.failoverPreScript(fail)

// Phase 2: Reject updates and sync slaves on switchover
if fail == false {
Expand Down Expand Up @@ -1232,7 +1243,7 @@ func (cluster *Cluster) VMasterFailover(fail bool) bool {
cluster.failoverProxies()
cluster.failoverProxiesWaitMonitor()
cluster.failoverEnableEventScheduler()
cluster.failoverPostScript()
cluster.failoverPostScript(fail)
if cluster.Conf.FailEventStatus {
for _, v := range cluster.master.EventStatus {
if v.Status == 3 {
Expand Down

0 comments on commit 07082c2

Please sign in to comment.