Skip to content

Commit

Permalink
parseComBinlogDumpGTID: GTID payload is always 5.6 flavor
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach committed Jan 22, 2025
1 parent aaee12a commit d4eff3f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
3 changes: 2 additions & 1 deletion go/mysql/binlog_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func (c *Conn) parseComBinlogDumpGTID(data []byte) (logFile string, logPos uint6
return logFile, logPos, position, readPacketErr
}
if gtid := string(data[pos : pos+int(dataSize)]); gtid != "" {
position, err = replication.DecodePosition(gtid)
// ComBinlogDumpGTID is a MySQL specific protocol. The GTID flavor is necessarily MySQL 56
position, _, err = replication.DecodePositionMySQL56(gtid)
if err != nil {
return logFile, logPos, position, err
}
Expand Down
44 changes: 41 additions & 3 deletions go/mysql/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql/replication"
"vitess.io/vitess/go/test/utils"

binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
Expand Down Expand Up @@ -88,14 +89,46 @@ func TestComBinlogDumpGTID(t *testing.T) {
cConn.Close()
}()

t.Run("WriteComBinlogDumpGTIDEmptyGTID", func(t *testing.T) {
// Write ComBinlogDumpGTID packet, read it, compare.
var flags uint16 = 0x0d0e
err := cConn.WriteComBinlogDumpGTID(0x01020304, "moofarm", 0x05060708090a0b0c, flags, []byte{})
assert.NoError(t, err)
data, err := sConn.ReadPacket()
require.NoError(t, err, "sConn.ReadPacket - ComBinlogDumpGTID failed: %v", err)
require.NotEmpty(t, data)
require.EqualValues(t, data[0], ComBinlogDumpGTID)

expectedData := []byte{
ComBinlogDumpGTID,
0x0e, 0x0d, // flags
0x04, 0x03, 0x02, 0x01, // server-id
0x07, 0x00, 0x00, 0x00, // binlog-filename-len
'm', 'o', 'o', 'f', 'a', 'r', 'm', // bilog-filename
0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06, 0x05, // binlog-pos
0x00, 0x00, 0x00, 0x00, // data-size is zero, no GTID payload
}
assert.Equal(t, expectedData, data)
logFile, logPos, pos, err := sConn.parseComBinlogDumpGTID(data)
require.NoError(t, err, "parseComBinlogDumpGTID failed: %v", err)
assert.Equal(t, "moofarm", logFile)
assert.Equal(t, uint64(0x05060708090a0b0c), logPos)
assert.True(t, pos.IsZero())
})

t.Run("WriteComBinlogDumpGTID", func(t *testing.T) {
// Write ComBinlogDumpGTID packet, read it, compare.
var flags uint16 = 0x0d0e
assert.Equal(t, flags, flags|BinlogThroughGTID)
err := cConn.WriteComBinlogDumpGTID(0x01020304, "moofarm", 0x05060708090a0b0c, flags, []byte{0xfa, 0xfb})
gtidSet, err := replication.ParseMysql56GTIDSet("16b1039f-22b6-11ed-b765-0a43f95f28a3:1-243")
require.NoError(t, err)
// dataSize := uint32(len(gtidSet.String()))
err = cConn.WriteComBinlogDumpGTID(0x01020304, "moofarm", 0x05060708090a0b0c, flags, []byte(gtidSet.String()))
assert.NoError(t, err)
data, err := sConn.ReadPacket()
require.NoError(t, err, "sConn.ReadPacket - ComBinlogDumpGTID failed: %v", err)
require.NotEmpty(t, data)
require.EqualValues(t, data[0], ComBinlogDumpGTID)

expectedData := []byte{
ComBinlogDumpGTID,
Expand All @@ -104,10 +137,15 @@ func TestComBinlogDumpGTID(t *testing.T) {
0x07, 0x00, 0x00, 0x00, // binlog-filename-len
'm', 'o', 'o', 'f', 'a', 'r', 'm', // bilog-filename
0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06, 0x05, // binlog-pos
0x02, 0x00, 0x00, 0x00, // data-size
0xfa, 0xfb, // data
0x02a, 0x00, 0x00, 0x00, // data-size
0x31, 0x36, 0x62, 0x31, 0x30, 0x33, 0x39, 0x66, 0x2d, 0x32, 0x32, 0x62, 0x36, 0x2d, 0x31, 0x31, 0x65, 0x64, 0x2d, 0x62, 0x37, 0x36, 0x35, 0x2d, 0x30, 0x61, 0x34, 0x33, 0x66, 0x39, 0x35, 0x66, 0x32, 0x38, 0x61, 0x33, 0x3a, 0x31, 0x2d, 0x32, 0x34, 0x33, // data
}
assert.Equal(t, expectedData, data)
logFile, logPos, pos, err := sConn.parseComBinlogDumpGTID(data)
require.NoError(t, err, "parseComBinlogDumpGTID failed: %v", err)
assert.Equal(t, "moofarm", logFile)
assert.Equal(t, uint64(0x05060708090a0b0c), logPos)
assert.Equal(t, gtidSet, pos.GTIDSet)
})

sConn.sequence = 0
Expand Down

0 comments on commit d4eff3f

Please sign in to comment.