Skip to content

Commit

Permalink
Use new terms for replication on MySQL 8.4.0 (#867)
Browse files Browse the repository at this point in the history
Co-authored-by: lance6716 <lance6716@gmail.com>
  • Loading branch information
dveeden and lance6716 committed May 7, 2024
1 parent 2525200 commit 8d4de0f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
7 changes: 6 additions & 1 deletion canal/sync.go
Expand Up @@ -309,7 +309,12 @@ func (c *Canal) WaitUntilPos(pos mysql.Position, timeout time.Duration) error {
}

func (c *Canal) GetMasterPos() (mysql.Position, error) {
rr, err := c.Execute("SHOW MASTER STATUS")
showBinlogStatus := "SHOW BINARY LOG STATUS"
if eq, err := c.conn.CompareServerVersion("8.4.0"); (err == nil) && (eq < 0) {
showBinlogStatus = "SHOW MASTER STATUS"
}

rr, err := c.Execute(showBinlogStatus)
if err != nil {
return mysql.Position{}, errors.Trace(err)
}
Expand Down
7 changes: 6 additions & 1 deletion replication/backup_test.go
Expand Up @@ -13,7 +13,12 @@ import (
func (t *testSyncerSuite) TestStartBackupEndInGivenTime() {
t.setupTest(mysql.MySQLFlavor)

t.testExecute("RESET MASTER")
resetBinaryLogs := "RESET BINARY LOGS AND GTIDS"
if eq, err := t.c.CompareServerVersion("8.4.0"); (err == nil) && (eq < 0) {
resetBinaryLogs = "RESET MASTER"
}

t.testExecute(resetBinaryLogs)

for times := 1; times <= 2; times++ {
t.testSync(nil)
Expand Down
17 changes: 14 additions & 3 deletions replication/replication_test.go
Expand Up @@ -304,15 +304,21 @@ func (t *testSyncerSuite) setupTest(flavor string) {

func (t *testSyncerSuite) testPositionSync() {
// get current master binlog file and position
r, err := t.c.Execute("SHOW MASTER STATUS")
showBinlogStatus := "SHOW BINARY LOG STATUS"
showReplicas := "SHOW REPLICAS"
if eq, err := t.c.CompareServerVersion("8.4.0"); (err == nil) && (eq < 0) {
showBinlogStatus = "SHOW MASTER STATUS"
showReplicas = "SHOW SLAVE HOSTS"
}
r, err := t.c.Execute(showBinlogStatus)
require.NoError(t.T(), err)
binFile, _ := r.GetString(0, 0)
binPos, _ := r.GetInt(0, 1)

s, err := t.b.StartSync(mysql.Position{Name: binFile, Pos: uint32(binPos)})
require.NoError(t.T(), err)

r, err = t.c.Execute("SHOW SLAVE HOSTS")
r, err = t.c.Execute(showReplicas)
require.NoError(t.T(), err)

// List of replicas must not be empty
Expand Down Expand Up @@ -406,7 +412,12 @@ func (t *testSyncerSuite) TestMysqlSemiPositionSync() {
func (t *testSyncerSuite) TestMysqlBinlogCodec() {
t.setupTest(mysql.MySQLFlavor)

t.testExecute("RESET MASTER")
resetBinaryLogs := "RESET BINARY LOGS AND GTIDS"
if eq, err := t.c.CompareServerVersion("8.4.0"); (err == nil) && (eq < 0) {
resetBinaryLogs = "RESET MASTER"
}

t.testExecute(resetBinaryLogs)

var wg sync.WaitGroup
wg.Add(1)
Expand Down

0 comments on commit 8d4de0f

Please sign in to comment.