Skip to content

Commit 569203c

Browse files
committed
Merge branch 'master' of github.com:huangjunwen/go-mysql
2 parents 7626785 + 9ddfbf2 commit 569203c

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

replication/event.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package replication
22

33
import (
44
"encoding/binary"
5+
"encoding/hex"
56
"fmt"
67
"io"
78
"strconv"
@@ -218,6 +219,55 @@ func (e *RotateEvent) Dump(w io.Writer) {
218219
fmt.Fprintln(w)
219220
}
220221

222+
type PreviousGTIDsEvent struct {
223+
GTIDSets string
224+
}
225+
226+
func (e *PreviousGTIDsEvent) Decode(data []byte) error {
227+
var previousGTIDSets []string
228+
pos := 0
229+
uuidCount := binary.LittleEndian.Uint16(data[pos:pos+8])
230+
pos += 8
231+
232+
for i := uint16(0);i < uuidCount; i++ {
233+
uuid := e.decodeUuid(data[pos:pos+16])
234+
pos += 16
235+
sliceCount := binary.LittleEndian.Uint16(data[pos:pos+8])
236+
pos += 8
237+
var intervals []string
238+
for i := uint16(0);i < sliceCount; i++ {
239+
start := e.decodeInterval(data[pos:pos+8])
240+
pos += 8
241+
stop := e.decodeInterval(data[pos:pos+8])
242+
pos += 8
243+
interval := ""
244+
if stop == start+1 {
245+
interval = fmt.Sprintf("%d",start)
246+
}else {
247+
interval = fmt.Sprintf("%d-%d",start,stop-1)
248+
}
249+
intervals = append(intervals,interval)
250+
}
251+
previousGTIDSets = append(previousGTIDSets,fmt.Sprintf("%s:%s",uuid,strings.Join(intervals,":")))
252+
}
253+
e.GTIDSets = fmt.Sprintf("%s",strings.Join(previousGTIDSets,","))
254+
return nil
255+
}
256+
257+
func (e *PreviousGTIDsEvent) Dump(w io.Writer) {
258+
fmt.Fprintf(w, "Previous GTID Event: %s\n", e.GTIDSets)
259+
fmt.Fprintln(w)
260+
}
261+
262+
func (e *PreviousGTIDsEvent) decodeUuid(data []byte) string {
263+
return fmt.Sprintf("%s-%s-%s-%s-%s",hex.EncodeToString(data[0:4]),hex.EncodeToString(data[4:6]),
264+
hex.EncodeToString(data[6:8]),hex.EncodeToString(data[8:10]),hex.EncodeToString(data[10:]))
265+
}
266+
267+
func (e *PreviousGTIDsEvent) decodeInterval(data []byte) uint64 {
268+
return binary.LittleEndian.Uint64(data)
269+
}
270+
221271
type XIDEvent struct {
222272
XID uint64
223273

replication/parser.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ func (p *BinlogParser) parseEvent(h *EventHeader, data []byte, rawData []byte) (
271271
ee := &MariadbGTIDEvent{}
272272
ee.GTID.ServerID = h.ServerID
273273
e = ee
274+
case PREVIOUS_GTIDS_EVENT:
275+
e = &PreviousGTIDsEvent{}
274276
default:
275277
e = &GenericEvent{}
276278
}

0 commit comments

Comments
 (0)