Skip to content

Commit 07082c2

Browse files
committed
Add extra parameter tout failover scripts passing string "failover" or "switchover"
1 parent b114681 commit 07082c2

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

cluster/cluster_fail.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (cluster *Cluster) MasterFailover(fail bool) bool {
126126
if cluster.Conf.MultiMaster == false {
127127
cluster.slaves[key].delete(&cluster.slaves)
128128
}
129-
cluster.failoverPreScript()
129+
cluster.failoverPreScript(fail)
130130

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

543-
func (cluster *Cluster) failoverPostScript() {
543+
func (cluster *Cluster) failoverPostScript(fail bool) {
544544
if cluster.Conf.PostScript != "" {
545+
545546
var out []byte
546547
var err error
548+
547549
cluster.LogPrintf(LvlInfo, "Calling post-failover script")
548-
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()
550+
failtype := "failover"
551+
if !fail {
552+
failtype = "switchover"
553+
}
554+
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()
549555
if err != nil {
550556
cluster.LogPrintf(LvlErr, "%s", err)
551557
}
552558
cluster.LogPrintf(LvlInfo, "Post-failover script complete %s", string(out))
553559
}
554560
}
555561

556-
func (cluster *Cluster) failoverPreScript() {
562+
func (cluster *Cluster) failoverPreScript(fail bool) {
557563
// Call pre-failover script
558564
if cluster.Conf.PreScript != "" {
565+
failtype := "failover"
566+
if !fail {
567+
failtype = "switchover"
568+
}
569+
559570
cluster.LogPrintf(LvlInfo, "Calling pre-failover script")
560571
var out []byte
561572
var err error
562-
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()
573+
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()
563574
if err != nil {
564575
cluster.LogPrintf(LvlErr, "%s", err)
565576
}
@@ -1164,7 +1175,7 @@ func (cluster *Cluster) VMasterFailover(fail bool) bool {
11641175
}
11651176
cluster.vmaster = cluster.Servers[skey]
11661177
cluster.master = cluster.Servers[skey]
1167-
cluster.failoverPreScript()
1178+
cluster.failoverPreScript(fail)
11681179

11691180
// Phase 2: Reject updates and sync slaves on switchover
11701181
if fail == false {
@@ -1232,7 +1243,7 @@ func (cluster *Cluster) VMasterFailover(fail bool) bool {
12321243
cluster.failoverProxies()
12331244
cluster.failoverProxiesWaitMonitor()
12341245
cluster.failoverEnableEventScheduler()
1235-
cluster.failoverPostScript()
1246+
cluster.failoverPostScript(fail)
12361247
if cluster.Conf.FailEventStatus {
12371248
for _, v := range cluster.master.EventStatus {
12381249
if v.Status == 3 {

0 commit comments

Comments
 (0)