Skip to content

Commit 08cec2c

Browse files
csuzhangxcsiddontang
authored andcommitted
replication: fix MariadbGTIDListEvent Decode with multi GTIDs (go-mysql-org#365)
1 parent 58596aa commit 08cec2c

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

replication/event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ func (e *MariadbGTIDListEvent) Decode(data []byte) error {
476476
e.GTIDs[i].ServerID = binary.LittleEndian.Uint32(data[pos:])
477477
pos += 4
478478
e.GTIDs[i].SequenceNumber = binary.LittleEndian.Uint64(data[pos:])
479+
pos += 8
479480
}
480481

481482
return nil

replication/event_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package replication
2+
3+
import (
4+
. "github.com/pingcap/check"
5+
)
6+
7+
func (_ *testDecodeSuite) TestMariadbGTIDListEvent(c *C) {
8+
// single GTID, 1-2-3
9+
data := []byte{1, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0}
10+
ev := MariadbGTIDListEvent{}
11+
err := ev.Decode(data)
12+
c.Assert(err, IsNil)
13+
c.Assert(len(ev.GTIDs), Equals, 1)
14+
c.Assert(ev.GTIDs[0].DomainID, Equals, uint32(1))
15+
c.Assert(ev.GTIDs[0].ServerID, Equals, uint32(2))
16+
c.Assert(ev.GTIDs[0].SequenceNumber, Equals, uint64(3))
17+
18+
// multi GTIDs, 1-2-3,4-5-6,7-8-9
19+
data = []byte{3, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0}
20+
ev = MariadbGTIDListEvent{}
21+
err = ev.Decode(data)
22+
c.Assert(err, IsNil)
23+
c.Assert(len(ev.GTIDs), Equals, 3)
24+
for i := 0; i < 3; i++ {
25+
c.Assert(ev.GTIDs[i].DomainID, Equals, uint32(1+3*i))
26+
c.Assert(ev.GTIDs[i].ServerID, Equals, uint32(2+3*i))
27+
c.Assert(ev.GTIDs[i].SequenceNumber, Equals, uint64(3+3*i))
28+
}
29+
}

0 commit comments

Comments
 (0)