From d0108bfec1eec60d8bd17e6f6db6af772d2eb600 Mon Sep 17 00:00:00 2001 From: Fizic Date: Tue, 19 Mar 2024 14:02:23 +0300 Subject: [PATCH 1/6] fix: checking for split brain --- internal/app/app.go | 8 +++++++- internal/app/util.go | 21 +++++++++++++++++++++ internal/mysql/data.go | 4 ++++ internal/mysql/gtids/wrapper.go | 6 +++--- internal/mysql/node.go | 15 +++++++++++++-- internal/mysql/queries.go | 2 ++ 6 files changed, 50 insertions(+), 6 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index 66f29f17..16462cd2 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -827,6 +827,12 @@ func (app *App) calcActiveNodes(clusterState, clusterStateDcs map[string]*NodeSt app.logger.Warnf("failed to get master status %v", err) return nil, err } + muuid, err := masterNode.UUID() + if err != nil { + app.logger.Warnf("failed to get master uuid %v", err) + return nil, err + } + for host, node := range clusterState { if host == master { activeNodes = append(activeNodes, master) @@ -869,7 +875,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, muuid) { 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..7c3dca9a 100644 --- a/internal/app/util.go +++ b/internal/app/util.go @@ -4,6 +4,8 @@ import ( "fmt" "time" + gomysql "github.com/go-mysql-org/go-mysql/mysql" + "github.com/google/uuid" "github.com/yandex/mysync/internal/log" "github.com/yandex/mysync/internal/mysql" "github.com/yandex/mysync/internal/mysql/gtids" @@ -233,6 +235,25 @@ func isGTIDLessOrEqual(slaveGtidSet, masterGtidSet gtids.GTIDSet) bool { return masterGtidSet.Contain(slaveGtidSet) || masterGtidSet.Equal(slaveGtidSet) } +func isSplitBrained(slaveGtidSet, masterGtidSet *gomysql.MysqlGTIDSet, masterUUID uuid.UUID) bool { + for _, MasterSet := range masterGtidSet.Sets { + slaveSet, ok := slaveGtidSet.Sets[MasterSet.SID.String()] + if !ok { + continue + } + if MasterSet.Contain(slaveSet) || MasterSet == slaveSet { + continue + } + + if MasterSet.SID == masterUUID { + continue + } + + return false + } + return true +} + func validatePriority(priority *int64) error { if priority == nil || *priority >= 0 { return nil diff --git a/internal/mysql/data.go b/internal/mysql/data.go index fedc605c..8f480073 100644 --- a/internal/mysql/data.go +++ b/internal/mysql/data.go @@ -28,6 +28,10 @@ type readOnlyResult struct { SuperReadOnly int `db:"SuperReadOnly"` } +type ServerUUIDResult struct { + ServerUUID string `db:"server_uuid"` +} + // CascadeNodeConfiguration is a dcs node configuration for cascade mysql replica type CascadeNodeConfiguration struct { // StreamFrom - is a host to stream from. Can be changed from CLI. diff --git a/internal/mysql/gtids/wrapper.go b/internal/mysql/gtids/wrapper.go index 8933d6a7..160867e6 100644 --- a/internal/mysql/gtids/wrapper.go +++ b/internal/mysql/gtids/wrapper.go @@ -6,10 +6,10 @@ import ( type GTIDSet = mysql.GTIDSet -func ParseGtidSet(gtidset string) mysql.GTIDSet { - parsed, err := mysql.ParseGTIDSet(mysql.MySQLFlavor, gtidset) +func ParseGtidSet(gtidset string) *mysql.MysqlGTIDSet { + parsed, err := mysql.ParseMysqlGTIDSet(gtidset) if err != nil { panic(err) } - return parsed + return parsed.(*mysql.MysqlGTIDSet) } diff --git a/internal/mysql/node.go b/internal/mysql/node.go index 5edb5e3f..82606995 100644 --- a/internal/mysql/node.go +++ b/internal/mysql/node.go @@ -17,10 +17,11 @@ import ( "syscall" "time" + mysql2 "github.com/go-mysql-org/go-mysql/mysql" "github.com/go-sql-driver/mysql" + "github.com/google/uuid" "github.com/jmoiron/sqlx" "github.com/shirou/gopsutil/v3/process" - "github.com/yandex/mysync/internal/config" "github.com/yandex/mysync/internal/log" "github.com/yandex/mysync/internal/mysql/gtids" @@ -578,7 +579,7 @@ func (n *Node) GTIDExecuted() (*GTIDExecuted, error) { } // GTIDExecuted returns global transaction id executed -func (n *Node) GTIDExecutedParsed() (gtids.GTIDSet, error) { +func (n *Node) GTIDExecutedParsed() (*mysql2.MysqlGTIDSet, error) { gtid, err := n.GTIDExecuted() if err != nil { return nil, err @@ -602,6 +603,16 @@ func (n *Node) GetBinlogs() ([]Binlog, error) { return binlogs, err } +// UUID returns server_uuid +func (n *Node) UUID() (uuid.UUID, error) { + var r ServerUUIDResult + err := n.queryRow(queryGetUUID, nil, &r) + if err != nil { + return uuid.UUID{}, err + } + return uuid.Parse(r.ServerUUID) +} + // IsReadOnly returns (true, true) if MySQL Node in (read-only, super-read-only) mode func (n *Node) IsReadOnly() (bool, bool, error) { var ror readOnlyResult diff --git a/internal/mysql/queries.go b/internal/mysql/queries.go index 4e0288cd..f5c596ba 100644 --- a/internal/mysql/queries.go +++ b/internal/mysql/queries.go @@ -6,6 +6,7 @@ const ( queryReplicaStatus = "replica_status" queryGetVersion = "get_version" queryGTIDExecuted = "gtid_executed" + queryGetUUID = "get_uuid" queryShowBinaryLogs = "binary_logs" queryReplicationLag = "replication_lag" querySlaveHosts = "slave_hosts" @@ -53,6 +54,7 @@ var DefaultQueries = map[string]string{ queryReplicaStatus: `SHOW REPLICA STATUS FOR CHANNEL :channel`, queryGetVersion: `SELECT sys.version_major() AS MajorVersion, sys.version_minor() AS MinorVersion, sys.version_patch() AS PatchVersion`, queryGTIDExecuted: `SELECT @@GLOBAL.gtid_executed as Executed_Gtid_Set`, + queryGetUUID: `SELECT @@server_uuid as server_uuid`, queryShowBinaryLogs: `SHOW BINARY LOGS`, querySlaveHosts: `SHOW SLAVE HOSTS`, queryReplicationLag: ``, From 185eaafffc4ed61354d815ca77302297541adbcb Mon Sep 17 00:00:00 2001 From: Fizic Date: Tue, 19 Mar 2024 15:19:30 +0300 Subject: [PATCH 2/6] fix: issues --- internal/app/util.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/app/util.go b/internal/app/util.go index 7c3dca9a..1b71b020 100644 --- a/internal/app/util.go +++ b/internal/app/util.go @@ -249,9 +249,9 @@ func isSplitBrained(slaveGtidSet, masterGtidSet *gomysql.MysqlGTIDSet, masterUUI continue } - return false + return true } - return true + return false } func validatePriority(priority *int64) error { From 98bfdbf628c95a381598b86070e5c52b25af4e0d Mon Sep 17 00:00:00 2001 From: Fizic Date: Tue, 19 Mar 2024 16:11:50 +0300 Subject: [PATCH 3/6] feat: tests; add: new condition --- internal/app/util.go | 15 ++++++++---- internal/app/util_test.go | 49 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/internal/app/util.go b/internal/app/util.go index 1b71b020..bedda991 100644 --- a/internal/app/util.go +++ b/internal/app/util.go @@ -236,21 +236,28 @@ func isGTIDLessOrEqual(slaveGtidSet, masterGtidSet gtids.GTIDSet) bool { } func isSplitBrained(slaveGtidSet, masterGtidSet *gomysql.MysqlGTIDSet, masterUUID uuid.UUID) bool { - for _, MasterSet := range masterGtidSet.Sets { - slaveSet, ok := slaveGtidSet.Sets[MasterSet.SID.String()] + for _, masterSet := range masterGtidSet.Sets { + slaveSet, ok := slaveGtidSet.Sets[masterSet.SID.String()] if !ok { continue } - if MasterSet.Contain(slaveSet) || MasterSet == slaveSet { + if masterSet.Contain(slaveSet) || masterSet == slaveSet { continue } - if MasterSet.SID == masterUUID { + if masterSet.SID == masterUUID { continue } return true } + + for _, slaveSet := range slaveGtidSet.Sets { + if _, ok := masterGtidSet.Sets[slaveSet.SID.String()]; !ok { + return true + } + } + return false } diff --git a/internal/app/util_test.go b/internal/app/util_test.go index 8a71e8cb..015b90be 100644 --- a/internal/app/util_test.go +++ b/internal/app/util_test.go @@ -327,3 +327,52 @@ func getLogger() *log.Logger { } return l } + +func TestIsSplitBrained(t *testing.T) { + masterGTID, _ := gomysql.ParseMysqlGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-100," + + "09978591-5754-4710-BF67-062880ABE1B4:1-100," + + "AA6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-100") + masterMySQLGTID := masterGTID.(*gomysql.MysqlGTIDSet) + masterUUID := masterMySQLGTID.Sets["6dbc0b04-4b09-43dc-86cc-9af852ded919"].SID + + // equal gtids + slaveGTID, _ := gomysql.ParseMysqlGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-101," + + "09978591-5754-4710-BF67-062880ABE1B4:1-100," + + "AA6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-100") + slaveMySQLGTID := slaveGTID.(*gomysql.MysqlGTIDSet) + ok := isSplitBrained(slaveMySQLGTID, masterMySQLGTID, masterUUID) + require.False(t, ok) + + // the replica is lagging behind the master + slaveGTID, _ = gomysql.ParseMysqlGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-99," + + "09978591-5754-4710-BF67-062880ABE1B4:1-100," + + "AA6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-100") + slaveMySQLGTID = slaveGTID.(*gomysql.MysqlGTIDSet) + ok = isSplitBrained(slaveMySQLGTID, masterMySQLGTID, masterUUID) + require.False(t, ok) + + // the replica applied the transaction from the master before the master + slaveGTID, _ = gomysql.ParseMysqlGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-101," + + "09978591-5754-4710-BF67-062880ABE1B4:1-100," + + "AA6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-100") + slaveMySQLGTID = slaveGTID.(*gomysql.MysqlGTIDSet) + ok = isSplitBrained(slaveMySQLGTID, masterMySQLGTID, masterUUID) + require.False(t, ok) + + // the replica applied a transaction not from the master + slaveGTID, _ = gomysql.ParseMysqlGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-100," + + "09978591-5754-4710-BF67-062880ABE1B4:1-100," + + "AA6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-101") + slaveMySQLGTID = slaveGTID.(*gomysql.MysqlGTIDSet) + ok = isSplitBrained(slaveMySQLGTID, masterMySQLGTID, masterUUID) + require.True(t, ok) + + // the replica applied a new transaction not from the master + slaveGTID, _ = gomysql.ParseMysqlGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-101," + + "09978591-5754-4710-BF67-062880ABE1B4:1-100," + + "AA6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-100," + + "BB6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-100") + slaveMySQLGTID = slaveGTID.(*gomysql.MysqlGTIDSet) + ok = isSplitBrained(slaveMySQLGTID, masterMySQLGTID, masterUUID) + require.True(t, ok) +} From afab05fc20e994b6337aaf0e215e6e52d9981c9a Mon Sep 17 00:00:00 2001 From: Fizic Date: Wed, 20 Mar 2024 11:34:01 +0300 Subject: [PATCH 4/6] fix: issues; feat: caching uuid --- internal/app/util.go | 12 +++++++----- internal/mysql/gtids/wrapper.go | 6 +++--- internal/mysql/node.go | 7 +++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/internal/app/util.go b/internal/app/util.go index bedda991..00efe36e 100644 --- a/internal/app/util.go +++ b/internal/app/util.go @@ -235,9 +235,11 @@ func isGTIDLessOrEqual(slaveGtidSet, masterGtidSet gtids.GTIDSet) bool { return masterGtidSet.Contain(slaveGtidSet) || masterGtidSet.Equal(slaveGtidSet) } -func isSplitBrained(slaveGtidSet, masterGtidSet *gomysql.MysqlGTIDSet, masterUUID uuid.UUID) bool { - for _, masterSet := range masterGtidSet.Sets { - slaveSet, ok := slaveGtidSet.Sets[masterSet.SID.String()] +func isSplitBrained(slaveGtidSet, masterGtidSet gtids.GTIDSet, masterUUID uuid.UUID) bool { + mysqlSlaveGtidSet := slaveGtidSet.(*gomysql.MysqlGTIDSet) + mysqlMasterGtidSet := masterGtidSet.(*gomysql.MysqlGTIDSet) + for _, masterSet := range mysqlMasterGtidSet.Sets { + slaveSet, ok := mysqlSlaveGtidSet.Sets[masterSet.SID.String()] if !ok { continue } @@ -252,8 +254,8 @@ func isSplitBrained(slaveGtidSet, masterGtidSet *gomysql.MysqlGTIDSet, masterUUI return true } - for _, slaveSet := range slaveGtidSet.Sets { - if _, ok := masterGtidSet.Sets[slaveSet.SID.String()]; !ok { + for _, slaveSet := range mysqlSlaveGtidSet.Sets { + if _, ok := mysqlMasterGtidSet.Sets[slaveSet.SID.String()]; !ok { return true } } diff --git a/internal/mysql/gtids/wrapper.go b/internal/mysql/gtids/wrapper.go index 160867e6..8933d6a7 100644 --- a/internal/mysql/gtids/wrapper.go +++ b/internal/mysql/gtids/wrapper.go @@ -6,10 +6,10 @@ import ( type GTIDSet = mysql.GTIDSet -func ParseGtidSet(gtidset string) *mysql.MysqlGTIDSet { - parsed, err := mysql.ParseMysqlGTIDSet(gtidset) +func ParseGtidSet(gtidset string) mysql.GTIDSet { + parsed, err := mysql.ParseGTIDSet(mysql.MySQLFlavor, gtidset) if err != nil { panic(err) } - return parsed.(*mysql.MysqlGTIDSet) + return parsed } diff --git a/internal/mysql/node.go b/internal/mysql/node.go index 82606995..88e57872 100644 --- a/internal/mysql/node.go +++ b/internal/mysql/node.go @@ -17,7 +17,6 @@ import ( "syscall" "time" - mysql2 "github.com/go-mysql-org/go-mysql/mysql" "github.com/go-sql-driver/mysql" "github.com/google/uuid" "github.com/jmoiron/sqlx" @@ -35,6 +34,7 @@ type Node struct { db *sqlx.DB version *Version host string + uuid uuid.UUID } var ( @@ -579,7 +579,7 @@ func (n *Node) GTIDExecuted() (*GTIDExecuted, error) { } // GTIDExecuted returns global transaction id executed -func (n *Node) GTIDExecutedParsed() (*mysql2.MysqlGTIDSet, error) { +func (n *Node) GTIDExecutedParsed() (gtids.GTIDSet, error) { gtid, err := n.GTIDExecuted() if err != nil { return nil, err @@ -605,6 +605,9 @@ func (n *Node) GetBinlogs() ([]Binlog, error) { // UUID returns server_uuid func (n *Node) UUID() (uuid.UUID, error) { + if n.uuid.ID() != 0 { + return n.uuid, nil + } var r ServerUUIDResult err := n.queryRow(queryGetUUID, nil, &r) if err != nil { From f565a46662e7b9e333b4589528cc1cbd8bb60897 Mon Sep 17 00:00:00 2001 From: Fizic Date: Wed, 20 Mar 2024 13:19:13 +0300 Subject: [PATCH 5/6] fix: issues --- internal/app/util.go | 13 ++++--------- internal/app/util_test.go | 36 ++++++++++++++++++------------------ internal/mysql/node.go | 7 ++++++- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/internal/app/util.go b/internal/app/util.go index 00efe36e..890a55d1 100644 --- a/internal/app/util.go +++ b/internal/app/util.go @@ -238,11 +238,12 @@ func isGTIDLessOrEqual(slaveGtidSet, masterGtidSet gtids.GTIDSet) bool { func isSplitBrained(slaveGtidSet, masterGtidSet gtids.GTIDSet, masterUUID uuid.UUID) bool { mysqlSlaveGtidSet := slaveGtidSet.(*gomysql.MysqlGTIDSet) mysqlMasterGtidSet := masterGtidSet.(*gomysql.MysqlGTIDSet) - for _, masterSet := range mysqlMasterGtidSet.Sets { - slaveSet, ok := mysqlSlaveGtidSet.Sets[masterSet.SID.String()] + for _, slaveSet := range mysqlSlaveGtidSet.Sets { + masterSet, ok := mysqlMasterGtidSet.Sets[slaveSet.SID.String()] if !ok { - continue + return true } + if masterSet.Contain(slaveSet) || masterSet == slaveSet { continue } @@ -254,12 +255,6 @@ func isSplitBrained(slaveGtidSet, masterGtidSet gtids.GTIDSet, masterUUID uuid.U return true } - for _, slaveSet := range mysqlSlaveGtidSet.Sets { - if _, ok := mysqlMasterGtidSet.Sets[slaveSet.SID.String()]; !ok { - return true - } - } - return false } diff --git a/internal/app/util_test.go b/internal/app/util_test.go index 015b90be..aa7c872d 100644 --- a/internal/app/util_test.go +++ b/internal/app/util_test.go @@ -329,50 +329,50 @@ func getLogger() *log.Logger { } func TestIsSplitBrained(t *testing.T) { - masterGTID, _ := gomysql.ParseMysqlGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-100," + + masterGTID := mustGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-100," + "09978591-5754-4710-BF67-062880ABE1B4:1-100," + "AA6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-100") - masterMySQLGTID := masterGTID.(*gomysql.MysqlGTIDSet) - masterUUID := masterMySQLGTID.Sets["6dbc0b04-4b09-43dc-86cc-9af852ded919"].SID + masterUUID := masterGTID.(*gomysql.MysqlGTIDSet).Sets["6dbc0b04-4b09-43dc-86cc-9af852ded919"].SID // equal gtids - slaveGTID, _ := gomysql.ParseMysqlGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-101," + + slaveGTID := mustGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-101," + "09978591-5754-4710-BF67-062880ABE1B4:1-100," + "AA6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-100") - slaveMySQLGTID := slaveGTID.(*gomysql.MysqlGTIDSet) - ok := isSplitBrained(slaveMySQLGTID, masterMySQLGTID, masterUUID) + ok := isSplitBrained(slaveGTID, masterGTID, masterUUID) require.False(t, ok) // the replica is lagging behind the master - slaveGTID, _ = gomysql.ParseMysqlGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-99," + + slaveGTID = mustGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-99," + "09978591-5754-4710-BF67-062880ABE1B4:1-100," + "AA6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-100") - slaveMySQLGTID = slaveGTID.(*gomysql.MysqlGTIDSet) - ok = isSplitBrained(slaveMySQLGTID, masterMySQLGTID, masterUUID) + ok = isSplitBrained(slaveGTID, masterGTID, masterUUID) + require.False(t, ok) + + // the replica is lagging behind the new master + slaveGTID = mustGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-100," + + "09978591-5754-4710-BF67-062880ABE1B4:1-100") + ok = isSplitBrained(slaveGTID, masterGTID, masterUUID) require.False(t, ok) // the replica applied the transaction from the master before the master - slaveGTID, _ = gomysql.ParseMysqlGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-101," + + slaveGTID = mustGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-101," + "09978591-5754-4710-BF67-062880ABE1B4:1-100," + "AA6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-100") - slaveMySQLGTID = slaveGTID.(*gomysql.MysqlGTIDSet) - ok = isSplitBrained(slaveMySQLGTID, masterMySQLGTID, masterUUID) + ok = isSplitBrained(slaveGTID, masterGTID, masterUUID) require.False(t, ok) // the replica applied a transaction not from the master - slaveGTID, _ = gomysql.ParseMysqlGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-100," + + slaveGTID = mustGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-100," + "09978591-5754-4710-BF67-062880ABE1B4:1-100," + "AA6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-101") - slaveMySQLGTID = slaveGTID.(*gomysql.MysqlGTIDSet) - ok = isSplitBrained(slaveMySQLGTID, masterMySQLGTID, masterUUID) + ok = isSplitBrained(slaveGTID, masterGTID, masterUUID) require.True(t, ok) // the replica applied a new transaction not from the master - slaveGTID, _ = gomysql.ParseMysqlGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-101," + + slaveGTID = mustGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-101," + "09978591-5754-4710-BF67-062880ABE1B4:1-100," + "AA6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-100," + "BB6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-100") - slaveMySQLGTID = slaveGTID.(*gomysql.MysqlGTIDSet) - ok = isSplitBrained(slaveMySQLGTID, masterMySQLGTID, masterUUID) + ok = isSplitBrained(slaveGTID, masterGTID, masterUUID) require.True(t, ok) } diff --git a/internal/mysql/node.go b/internal/mysql/node.go index 88e57872..7f4cea0e 100644 --- a/internal/mysql/node.go +++ b/internal/mysql/node.go @@ -613,7 +613,12 @@ func (n *Node) UUID() (uuid.UUID, error) { if err != nil { return uuid.UUID{}, err } - return uuid.Parse(r.ServerUUID) + v, err := uuid.Parse(r.ServerUUID) + if err != nil { + return uuid.UUID{}, err + } + n.uuid = v + return v, err } // IsReadOnly returns (true, true) if MySQL Node in (read-only, super-read-only) mode From 1ab361211f59f19783995c7a607aaffc4172853a Mon Sep 17 00:00:00 2001 From: Fizic Date: Wed, 20 Mar 2024 15:50:54 +0300 Subject: [PATCH 6/6] fix: issues --- internal/app/util.go | 2 +- internal/app/util_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/app/util.go b/internal/app/util.go index 890a55d1..3e878b98 100644 --- a/internal/app/util.go +++ b/internal/app/util.go @@ -244,7 +244,7 @@ func isSplitBrained(slaveGtidSet, masterGtidSet gtids.GTIDSet, masterUUID uuid.U return true } - if masterSet.Contain(slaveSet) || masterSet == slaveSet { + if masterSet.Contain(slaveSet) { continue } diff --git a/internal/app/util_test.go b/internal/app/util_test.go index aa7c872d..efc21df0 100644 --- a/internal/app/util_test.go +++ b/internal/app/util_test.go @@ -335,7 +335,7 @@ func TestIsSplitBrained(t *testing.T) { masterUUID := masterGTID.(*gomysql.MysqlGTIDSet).Sets["6dbc0b04-4b09-43dc-86cc-9af852ded919"].SID // equal gtids - slaveGTID := mustGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-101," + + slaveGTID := mustGTIDSet("6DBC0B04-4B09-43DC-86CC-9AF852DED919:1-100," + "09978591-5754-4710-BF67-062880ABE1B4:1-100," + "AA6890C8-69F8-4BC4-B3A5-5D3FEA8C28CF:1-100") ok := isSplitBrained(slaveGTID, masterGTID, masterUUID)