Skip to content

Commit 4563849

Browse files
committed
Fixed MySQLmultiple GTID failover rejoin, Can failed reading 1+n server_id as GTID_EXECUTED need to be trim from ciariage return and space from the putput of show slave status
1 parent 1464dbf commit 4563849

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

cluster/cluster_fail.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (cluster *Cluster) MasterFailover(fail bool) bool {
168168
}
169169
} else if cluster.master.DBVersion.IsMySQLOrPerconaGreater57() && cluster.master.HasGTIDReplication() {
170170
cluster.LogPrintf(LvlInfo, "MySQL GTID saving crash info for replication ExexecutedGtidSet %s", ms.ExecutedGtidSet.String)
171-
crash.FailoverIOGtid = gtid.NewMySQLList(strings.ToUpper(ms.ExecutedGtidSet.String))
171+
crash.FailoverIOGtid = gtid.NewMySQLList(strings.ToUpper(ms.ExecutedGtidSet.String), cluster.GetCrcTable())
172172
}
173173
cluster.master.FailoverSemiSyncSlaveStatus = cluster.master.SemiSyncSlaveStatus
174174
crash.FailoverSemiSyncSlaveStatus = cluster.master.SemiSyncSlaveStatus
@@ -1206,7 +1206,7 @@ func (cluster *Cluster) VMasterFailover(fail bool) bool {
12061206
crash.FailoverIOGtid = gtid.NewList(ms.GtidIOPos.String)
12071207
}
12081208
} else if cluster.master.DBVersion.IsMySQLOrPerconaGreater57() && cluster.master.HasGTIDReplication() {
1209-
crash.FailoverIOGtid = gtid.NewMySQLList(strings.ToUpper(ms.ExecutedGtidSet.String))
1209+
crash.FailoverIOGtid = gtid.NewMySQLList(strings.ToUpper(ms.ExecutedGtidSet.String), cluster.GetCrcTable())
12101210
}
12111211
cluster.master.FailoverSemiSyncSlaveStatus = cluster.master.SemiSyncSlaveStatus
12121212
crash.FailoverSemiSyncSlaveStatus = cluster.master.SemiSyncSlaveStatus

cluster/cluster_get.go

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"encoding/json"
1111
"errors"
1212
"fmt"
13+
"hash/crc64"
1314
"io/ioutil"
1415
"regexp"
1516
"sort"
@@ -25,6 +26,10 @@ import (
2526
"github.com/signal18/replication-manager/utils/state"
2627
)
2728

29+
func (cluster *Cluster) GetCrcTable() *crc64.Table {
30+
return cluster.crcTable
31+
}
32+
2833
func (cluster *Cluster) getDumpParameter() string {
2934
dump_param := cluster.Conf.BackupMysqldumpOptions
3035
if cluster.master != nil {

cluster/srv.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ type ServerMonitor struct {
166166
Datadir string `json:"datadir"`
167167
SlapOSDatadir string `json:"slaposDatadir"`
168168
PostgressDB string `json:"postgressDB"`
169-
CrcTable *crc64.Table `json:"-"`
170169
TLSConfigUsed string `json:"tlsConfigUsed"` //used to track TLS config during key rotation
171170
SSTPort string `json:"sstPort"` //used to send data to dbjobs
172171
Agent string `json:"agent"` //used to provision service in orchestrator
@@ -229,10 +228,9 @@ func (cluster *Cluster) newServerMonitor(url string, user string, pass string, c
229228
}
230229
url = server.Name + server.Domain + ":3306"
231230
}
232-
server.CrcTable = crc64.MakeTable(crc64.ECMA)
233231
var sid uint64
234232
//will be overide in Refresh with show variables server_id, used for provisionning configurator for server_id
235-
sid, err = strconv.ParseUint(strconv.FormatUint(crc64.Checksum([]byte(server.Name+server.Port), server.CrcTable), 10), 10, 64)
233+
sid, err = strconv.ParseUint(strconv.FormatUint(crc64.Checksum([]byte(server.Name+server.Port), server.GetCluster().GetCrcTable()), 10), 10, 64)
236234
server.ServerID = sid
237235
server.Id = fmt.Sprintf("%s%d", "db", sid)
238236

@@ -629,11 +627,12 @@ func (server *ServerMonitor) Refresh() error {
629627
}
630628

631629
} else {
632-
server.GTIDBinlogPos = gtid.NewMySQLList(server.Variables["GTID_EXECUTED"])
630+
server.GTIDBinlogPos = gtid.NewMySQLList(server.Variables["GTID_EXECUTED"], server.GetCluster().GetCrcTable())
633631
server.GTIDExecuted = server.Variables["GTID_EXECUTED"]
634-
server.CurrentGtid = gtid.NewMySQLList(server.Variables["GTID_EXECUTED"])
632+
server.CurrentGtid = server.GTIDBinlogPos
635633
server.SlaveGtid = gtid.NewList(server.Variables["GTID_SLAVE_POS"])
636-
server.HashUUID = crc64.Checksum([]byte(strings.ToUpper(server.Variables["SERVER_UUID"])), server.CrcTable)
634+
server.HashUUID = crc64.Checksum([]byte(strings.ToUpper(server.Variables["SERVER_UUID"])), server.GetCluster().GetCrcTable())
635+
// fmt.Fprintf(os.Stdout, "gniac2 "+strings.ToUpper(server.Variables["SERVER_UUID"])+" "+strconv.FormatUint(server.HashUUID, 10))
637636
}
638637

639638
var sid uint64
@@ -769,7 +768,7 @@ func (server *ServerMonitor) Refresh() error {
769768
if server.DBVersion.IsPPostgreSQL() {
770769
//PostgresQL as no server_id concept mimic via internal server id for topology detection
771770
var sid uint64
772-
sid, err = strconv.ParseUint(strconv.FormatUint(crc64.Checksum([]byte(server.SlaveStatus.MasterHost.String+server.SlaveStatus.MasterPort.String), server.ClusterGroup.crcTable), 10), 10, 64)
771+
sid, err = strconv.ParseUint(strconv.FormatUint(crc64.Checksum([]byte(server.SlaveStatus.MasterHost.String+server.SlaveStatus.MasterPort.String), server.ClusterGroup.GetCrcTable()), 10), 10, 64)
773772
if err != nil {
774773
server.ClusterGroup.LogPrintf(LvlWarn, "PG Could not assign server_id s", err)
775774
}

cluster/srv_get.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (server *ServerMonitor) GetUniversalGtidServerID() uint64 {
3838
}
3939
if server.DBVersion.IsMySQLOrPerconaGreater57() {
4040
server.ClusterGroup.LogPrintf("INFO", " %s %s", server.Variables["SERVER_UUID"], server.URL)
41-
return crc64.Checksum([]byte(strings.ToUpper(server.Variables["SERVER_UUID"])), server.CrcTable)
41+
return crc64.Checksum([]byte(strings.ToUpper(server.Variables["SERVER_UUID"])), server.GetCluster().GetCrcTable())
4242

4343
}
4444
return 0

utils/gtid/gtid.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ package gtid
1212
import (
1313
"fmt"
1414
"hash/crc64"
15+
"regexp"
1516
"sort"
1617
"strconv"
1718
"strings"
@@ -100,14 +101,18 @@ func NewList(s string) *List {
100101
return gl
101102
}
102103

103-
func NewMySQLList(s string) *List {
104+
func NewMySQLList(s string, crcTable *crc64.Table) *List {
104105
gl := new(List)
105106
if s == "" {
106107
return gl
107108
}
109+
110+
var re = regexp.MustCompile(`\r\n|[\r\n\v\f\x{0085}\x{2028}\x{2029}]`)
111+
112+
s = re.ReplaceAllString(s, "")
108113
l := strings.Split(strings.ReplaceAll(s, " ", ""), ",")
109114
for _, g := range l {
110-
gtid := NewMySQLGtid(g)
115+
gtid := NewMySQLGtid(g, crcTable)
111116
*gl = append(*gl, *gtid)
112117
}
113118
return gl
@@ -123,10 +128,9 @@ func NewGtid(s string) *Gtid {
123128
return g
124129
}
125130

126-
func NewMySQLGtid(s string) *Gtid {
131+
func NewMySQLGtid(s string, crcTable *crc64.Table) *Gtid {
127132
g := new(Gtid)
128133
f := strings.Split(s, ":")
129-
crcTable := crc64.MakeTable(crc64.ECMA)
130134
seq := "1"
131135
if strings.Contains(f[1], "-") {
132136
e := strings.Split(f[1], "-")
@@ -138,7 +142,7 @@ func NewMySQLGtid(s string) *Gtid {
138142

139143
g.ServerID = crc64.Checksum([]byte(strings.ToUpper(f[0])), crcTable)
140144
g.SeqNo, _ = strconv.ParseUint(seq, 10, 64)
141-
// fmt.Fprintf(os.Stdout, "gniac new MySQL GTID : "+f[0]+" "+strconv.FormatUint(g.ServerID, 10))
145+
//fmt.Fprintf(os.Stdout, "gniac new MySQL GTID : "+f[0]+" "+strconv.FormatUint(g.ServerID, 10))
142146

143147
return g
144148
}

0 commit comments

Comments
 (0)