From 52e4624747538643ccc09b3a1151ecbb0e94e5a0 Mon Sep 17 00:00:00 2001 From: Fizic Date: Tue, 12 Mar 2024 16:08:30 +0300 Subject: [PATCH] fix: split brain when replica applied the transaction earlier --- internal/app/app.go | 2 +- internal/app/util.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/app/app.go b/internal/app/app.go index 66f29f17..42c742f5 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -869,7 +869,7 @@ func (app *App) calcActiveNodes(clusterState, clusterStateDcs map[string]*NodeSt continue } sgtids := gtids.ParseGtidSet(sstatus.ExecutedGtidSet) - if !(sstatus.ReplicationState == mysql.ReplicationRunning && isGTIDLessOrEqual(sgtids, mgtids)) { + if !(sstatus.ReplicationState == mysql.ReplicationRunning && isSplitBrained(sgtids, mgtids)) { app.logger.Errorf("calc active nodes: %s is not replicating or splitbrained, deleting from active...", host) continue } diff --git a/internal/app/util.go b/internal/app/util.go index 4cb79076..6a99038c 100644 --- a/internal/app/util.go +++ b/internal/app/util.go @@ -233,6 +233,10 @@ func isGTIDLessOrEqual(slaveGtidSet, masterGtidSet gtids.GTIDSet) bool { return masterGtidSet.Contain(slaveGtidSet) || masterGtidSet.Equal(slaveGtidSet) } +func isSplitBrained(firstGtidSet, secondGtidSet gtids.GTIDSet) bool { + return firstGtidSet.Contain(secondGtidSet) || secondGtidSet.Contain(firstGtidSet) || firstGtidSet.Equal(secondGtidSet) +} + func validatePriority(priority *int64) error { if priority == nil || *priority >= 0 { return nil