diff --git a/go/mysql/binlog_dump.go b/go/mysql/binlog_dump.go index d6768056974..de91484fc64 100644 --- a/go/mysql/binlog_dump.go +++ b/go/mysql/binlog_dump.go @@ -72,21 +72,19 @@ 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 } - 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 - } + if gtid := string(data[pos : pos+int(dataSize)]); gtid != "" { + position, err = replication.DecodePosition(gtid) + if err != nil { + return logFile, logPos, position, err } } + if flags2&BinlogDumpNonBlock != 0 { + return logFile, logPos, position, io.EOF + } return logFile, logPos, position, nil } 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)