Skip to content

Commit

Permalink
sendBinlogDumpCommand: apply BinlogThroughGTID flag (#17580)
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach authored Jan 22, 2025
1 parent 9743929 commit aaee12a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
22 changes: 10 additions & 12 deletions go/mysql/binlog_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
9 changes: 8 additions & 1 deletion go/mysql/flavor_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions go/mysql/replication/mysql56_gtid_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
4 changes: 3 additions & 1 deletion go/mysql/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit aaee12a

Please sign in to comment.