Skip to content

Commit 06f9327

Browse files
authored
Merge pull request #656 from lance6716/fix-show-slave-hosts
Set slave_uuid and replica_uuid
2 parents 0c0b817 + 169bae9 commit 06f9327

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

replication/binlogsyncer.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010
"sync"
1111
"time"
1212

13-
"github.com/go-mysql-org/go-mysql/client"
14-
. "github.com/go-mysql-org/go-mysql/mysql"
1513
"github.com/pingcap/errors"
1614
uuid "github.com/satori/go.uuid"
1715
"github.com/siddontang/go-log/log"
16+
17+
"github.com/go-mysql-org/go-mysql/client"
18+
. "github.com/go-mysql-org/go-mysql/mysql"
1819
)
1920

2021
var (
@@ -311,6 +312,12 @@ func (b *BinlogSyncer) registerSlave() error {
311312
return errors.Trace(err)
312313
}
313314

315+
serverUUID := uuid.NewV1()
316+
if _, err = b.c.Execute(fmt.Sprintf("SET @slave_uuid = '%s', @replica_uuid = '%s'", serverUUID, serverUUID)); err != nil {
317+
log.Errorf("failed to set @slave_uuid = '%s', err: %v", serverUUID, err)
318+
return errors.Trace(err)
319+
}
320+
314321
return nil
315322
}
316323

replication/replication_test.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import (
1010
"testing"
1111
"time"
1212

13-
"github.com/go-mysql-org/go-mysql/client"
14-
"github.com/go-mysql-org/go-mysql/mysql"
1513
. "github.com/pingcap/check"
1614
uuid "github.com/satori/go.uuid"
15+
16+
"github.com/go-mysql-org/go-mysql/client"
17+
"github.com/go-mysql-org/go-mysql/mysql"
1718
)
1819

1920
// Use docker mysql to test, mysql is 3306, mariadb is 3316
@@ -37,7 +38,6 @@ type testSyncerSuite struct {
3738
var _ = Suite(&testSyncerSuite{})
3839

3940
func (t *testSyncerSuite) SetUpSuite(c *C) {
40-
4141
}
4242

4343
func (t *testSyncerSuite) TearDownSuite(c *C) {
@@ -274,8 +274,8 @@ func (t *testSyncerSuite) setupTest(c *C, flavor string) {
274274
c.Skip(err.Error())
275275
}
276276

277-
// _, err = t.c.Execute("CREATE DATABASE IF NOT EXISTS test")
278-
// c.Assert(err, IsNil)
277+
_, err = t.c.Execute("CREATE DATABASE IF NOT EXISTS test")
278+
c.Assert(err, IsNil)
279279

280280
_, err = t.c.Execute("USE test")
281281
c.Assert(err, IsNil)
@@ -307,6 +307,12 @@ func (t *testSyncerSuite) testPositionSync(c *C) {
307307
s, err := t.b.StartSync(mysql.Position{Name: binFile, Pos: uint32(binPos)})
308308
c.Assert(err, IsNil)
309309

310+
// check we have set Slave_UUID
311+
r, err = t.c.Execute("SHOW SLAVE HOSTS")
312+
c.Assert(err, IsNil)
313+
slaveUUID, _ := r.GetString(0, 4)
314+
c.Assert(slaveUUID, HasLen, 36)
315+
310316
// Test re-sync.
311317
time.Sleep(100 * time.Millisecond)
312318
_ = t.b.c.SetReadDeadline(time.Now().Add(time.Millisecond))

0 commit comments

Comments
 (0)