Skip to content

Commit 46d49e9

Browse files
committed
replication: add uuid.
1 parent 8250ec4 commit 46d49e9

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

go.mod

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module github.com/siddontang/go-mysql
22

3+
go 1.14
4+
35
require (
46
github.com/BurntSushi/toml v0.3.1
57
github.com/go-sql-driver/mysql v1.4.1
@@ -15,3 +17,5 @@ require (
1517
github.com/sirupsen/logrus v1.4.1 // indirect
1618
golang.org/x/text v0.3.2 // indirect
1719
)
20+
21+
replace github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.4

replication/binlogsyncer.go

+15
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ type BinlogSyncerConfig struct {
4444
// Charset is for MySQL client character set
4545
Charset string
4646

47+
// the uuid of slave
48+
Uuid string
49+
4750
// SemiSyncEnabled enables semi-sync or not.
4851
SemiSyncEnabled bool
4952

@@ -271,6 +274,11 @@ func (b *BinlogSyncer) registerSlave() error {
271274
}
272275
}
273276

277+
slaveuuid := b.uuid()
278+
if _, err := b.c.Execute(fmt.Sprintf("SET @slave_uuid='%s'", slaveuuid)); err != nil {
279+
return errors.Errorf("failed to set SET @slave_uuid='%s': %v", slaveuuid, err)
280+
}
281+
274282
if b.cfg.Flavor == MariaDBFlavor {
275283
// Refer https://github.com/alibaba/canal/wiki/BinlogChange(MariaDB5&10)
276284
// Tell the server that we understand GTIDs by setting our slave capability
@@ -501,6 +509,13 @@ func (b *BinlogSyncer) localHostname() string {
501509
return b.cfg.Localhost
502510
}
503511

512+
func (b *BinlogSyncer) uuid() string {
513+
if len(b.cfg.Uuid) == 0 {
514+
return uuid.NewV1().String()
515+
}
516+
return b.cfg.Uuid
517+
}
518+
504519
func (b *BinlogSyncer) writeRegisterSlaveCommand() error {
505520
b.c.ResetSequence()
506521

0 commit comments

Comments
 (0)