From 6e5a12ff4ae2b8f120f4e3e74a1c4b024d279184 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Mon, 20 Jan 2025 18:47:42 +0200 Subject: [PATCH 1/3] sendBinlogDumpCommand: apply BinlogThroughGTID flag Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/mysql/flavor_mysql.go | 9 ++++++++- go/mysql/replication/mysql56_gtid_set_test.go | 15 +++++++++++++++ go/mysql/replication_test.go | 4 +++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/go/mysql/flavor_mysql.go b/go/mysql/flavor_mysql.go index e405dc401ec..c5424259973 100644 --- a/go/mysql/flavor_mysql.go +++ b/go/mysql/flavor_mysql.go @@ -219,7 +219,14 @@ func (mysqlFlavor) sendBinlogDumpCommand(c *Conn, serverID uint32, binlogFilenam // Build the command. sidBlock := gtidSet.SIDBlock() - return c.WriteComBinlogDumpGTID(serverID, binlogFilename, 4, 0, sidBlock) + var flags2 uint16 + if binlogFilename != "" { + flags2 |= BinlogThroughPosition + } + if len(sidBlock) > 0 { + flags2 |= BinlogThroughGTID + } + return c.WriteComBinlogDumpGTID(serverID, binlogFilename, 4, flags2, sidBlock) } // setReplicationPositionCommands is part of the Flavor interface. diff --git a/go/mysql/replication/mysql56_gtid_set_test.go b/go/mysql/replication/mysql56_gtid_set_test.go index bc5d5a6d6ec..bf87a992d5d 100644 --- a/go/mysql/replication/mysql56_gtid_set_test.go +++ b/go/mysql/replication/mysql56_gtid_set_test.go @@ -854,3 +854,18 @@ func TestMysql56GTIDSet_RemoveUUID(t *testing.T) { }) } } + +func TestSIDs(t *testing.T) { + var set Mysql56GTIDSet // nil + sids := set.SIDs() + assert.NotNil(t, sids) + assert.Empty(t, sids) + + gtid := "8bc65cca-3fe4-11ed-bbfb-091034d48b3e:1:4-24" + gtidSet, err := ParseMysql56GTIDSet(gtid) + require.NoError(t, err) + sids = gtidSet.SIDs() + assert.NotNil(t, sids) + require.Len(t, sids, 1) + assert.Equal(t, "8bc65cca-3fe4-11ed-bbfb-091034d48b3e", sids[0].String()) +} diff --git a/go/mysql/replication_test.go b/go/mysql/replication_test.go index 680cb9e68dc..ded22d838f6 100644 --- a/go/mysql/replication_test.go +++ b/go/mysql/replication_test.go @@ -90,7 +90,9 @@ func TestComBinlogDumpGTID(t *testing.T) { t.Run("WriteComBinlogDumpGTID", func(t *testing.T) { // Write ComBinlogDumpGTID packet, read it, compare. - err := cConn.WriteComBinlogDumpGTID(0x01020304, "moofarm", 0x05060708090a0b0c, 0x0d0e, []byte{0xfa, 0xfb}) + var flags uint16 = 0x0d0e + assert.Equal(t, flags, flags|BinlogThroughGTID) + err := cConn.WriteComBinlogDumpGTID(0x01020304, "moofarm", 0x05060708090a0b0c, flags, []byte{0xfa, 0xfb}) assert.NoError(t, err) data, err := sConn.ReadPacket() require.NoError(t, err, "sConn.ReadPacket - ComBinlogDumpGTID failed: %v", err) From e7a7af811a905aa232f3d34477c0afe5ceac75a6 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Tue, 21 Jan 2025 18:03:37 +0200 Subject: [PATCH 2/3] ignore BinlogThroughGTID flag on server side Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/mysql/binlog_dump.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/go/mysql/binlog_dump.go b/go/mysql/binlog_dump.go index d6768056974..6152227136a 100644 --- a/go/mysql/binlog_dump.go +++ b/go/mysql/binlog_dump.go @@ -75,16 +75,14 @@ func (c *Conn) parseComBinlogDumpGTID(data []byte) (logFile string, logPos uint6 if flags2&BinlogDumpNonBlock != 0 { return logFile, logPos, position, io.EOF } - if flags2&BinlogThroughGTID != 0 { - dataSize, pos, ok := readUint32(data, pos) - if !ok { - return logFile, logPos, position, readPacketErr - } - if gtid := string(data[pos : pos+int(dataSize)]); gtid != "" { - position, err = replication.DecodePosition(gtid) - if err != nil { - return logFile, logPos, position, err - } + dataSize, pos, ok := readUint32(data, pos) + if !ok { + return logFile, logPos, position, readPacketErr + } + if gtid := string(data[pos : pos+int(dataSize)]); gtid != "" { + position, err = replication.DecodePosition(gtid) + if err != nil { + return logFile, logPos, position, err } } From bc6770bc3a3004bafbfc2e666887a296b27e2ff2 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Tue, 21 Jan 2025 18:05:07 +0200 Subject: [PATCH 3/3] reorder sequence Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/mysql/binlog_dump.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/go/mysql/binlog_dump.go b/go/mysql/binlog_dump.go index 6152227136a..de91484fc64 100644 --- a/go/mysql/binlog_dump.go +++ b/go/mysql/binlog_dump.go @@ -72,9 +72,6 @@ func (c *Conn) parseComBinlogDumpGTID(data []byte) (logFile string, logPos uint6 return logFile, logPos, position, readPacketErr } - if flags2&BinlogDumpNonBlock != 0 { - return logFile, logPos, position, io.EOF - } dataSize, pos, ok := readUint32(data, pos) if !ok { return logFile, logPos, position, readPacketErr @@ -85,6 +82,9 @@ func (c *Conn) parseComBinlogDumpGTID(data []byte) (logFile string, logPos uint6 return logFile, logPos, position, err } } + if flags2&BinlogDumpNonBlock != 0 { + return logFile, logPos, position, io.EOF + } return logFile, logPos, position, nil }