Skip to content

Set slave_uuid and replica_uuid #656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions replication/binlogsyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
"sync"
"time"

"github.com/go-mysql-org/go-mysql/client"
. "github.com/go-mysql-org/go-mysql/mysql"
"github.com/pingcap/errors"
uuid "github.com/satori/go.uuid"
"github.com/siddontang/go-log/log"

"github.com/go-mysql-org/go-mysql/client"
. "github.com/go-mysql-org/go-mysql/mysql"
)

var (
Expand Down Expand Up @@ -311,6 +312,12 @@ func (b *BinlogSyncer) registerSlave() error {
return errors.Trace(err)
}

serverUUID := uuid.NewV1()
if _, err = b.c.Execute(fmt.Sprintf("SET @slave_uuid = '%s', @replica_uuid = '%s'", serverUUID, serverUUID)); err != nil {
log.Errorf("failed to set @slave_uuid = '%s', err: %v", serverUUID, err)
return errors.Trace(err)
}

return nil
}

Expand Down
16 changes: 11 additions & 5 deletions replication/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"testing"
"time"

"github.com/go-mysql-org/go-mysql/client"
"github.com/go-mysql-org/go-mysql/mysql"
. "github.com/pingcap/check"
uuid "github.com/satori/go.uuid"

"github.com/go-mysql-org/go-mysql/client"
"github.com/go-mysql-org/go-mysql/mysql"
)

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

func (t *testSyncerSuite) SetUpSuite(c *C) {

}

func (t *testSyncerSuite) TearDownSuite(c *C) {
Expand Down Expand Up @@ -274,8 +274,8 @@ func (t *testSyncerSuite) setupTest(c *C, flavor string) {
c.Skip(err.Error())
}

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

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

// check we have set Slave_UUID
r, err = t.c.Execute("SHOW SLAVE HOSTS")
c.Assert(err, IsNil)
slaveUUID, _ := r.GetString(0, 4)
c.Assert(slaveUUID, HasLen, 36)

// Test re-sync.
time.Sleep(100 * time.Millisecond)
_ = t.b.c.SetReadDeadline(time.Now().Add(time.Millisecond))
Expand Down