diff --git a/replication/const.go b/replication/const.go index 6230257fc..ce7b98b41 100644 --- a/replication/const.go +++ b/replication/const.go @@ -217,3 +217,11 @@ const ( TABLE_MAP_OPT_META_ENUM_AND_SET_DEFAULT_CHARSET TABLE_MAP_OPT_META_ENUM_AND_SET_COLUMN_CHARSET ) + +type IntVarEventType byte + +const ( + INVALID IntVarEventType = iota + LAST_INSERT_ID + INSERT_ID +) diff --git a/replication/event.go b/replication/event.go index 90b38d371..9111691d2 100644 --- a/replication/event.go +++ b/replication/event.go @@ -643,3 +643,19 @@ func (e *MariadbGTIDListEvent) Dump(w io.Writer) { fmt.Fprintf(w, "Lists: %v\n", e.GTIDs) fmt.Fprintln(w) } + +type IntVarEvent struct { + Type IntVarEventType + Value uint64 +} + +func (i *IntVarEvent) Decode(data []byte) error { + i.Type = IntVarEventType(data[0]) + i.Value = binary.LittleEndian.Uint64(data[1:]) + return nil +} + +func (i *IntVarEvent) Dump(w io.Writer) { + fmt.Fprintf(w, "Type: %d\n", i.Type) + fmt.Fprintf(w, "Value: %d\n", i.Value) +} diff --git a/replication/event_test.go b/replication/event_test.go index 25add805f..509df8b5c 100644 --- a/replication/event_test.go +++ b/replication/event_test.go @@ -97,3 +97,21 @@ func (_ *testDecodeSuite) TestGTIDEventMysql8NewFields(c *C) { c.Assert(ev.OriginalServerVersion, Equals, tc.expectOriginalServerVersion) } } + +func (_ *testDecodeSuite) TestIntVarEvent(c *C) { + // IntVarEvent Type LastInsertID, Value 13 + data := []byte{1, 13, 0, 0, 0, 0, 0, 0, 0} + ev := IntVarEvent{} + err := ev.Decode(data) + c.Assert(err, IsNil) + c.Assert(ev.Type, Equals, LAST_INSERT_ID) + c.Assert(ev.Value, Equals, uint64(13)) + + // IntVarEvent Type InsertID, Value 23 + data = []byte{2, 23, 0, 0, 0, 0, 0, 0, 0} + ev = IntVarEvent{} + err = ev.Decode(data) + c.Assert(err, IsNil) + c.Assert(ev.Type, Equals, INSERT_ID) + c.Assert(ev.Value, Equals, uint64(23)) +} diff --git a/replication/generic_event.go b/replication/generic_event.go index b0fa83a3b..ac55703cc 100644 --- a/replication/generic_event.go +++ b/replication/generic_event.go @@ -141,11 +141,6 @@ func (e *GenericEvent) Decode(data []byte) error { // Seed2 uint64 // } -// type IntVarEvent struct { -// Type uint8 -// Value uint64 -// } - // type UserVarEvent struct { // NameLength uint32 // Name []byte diff --git a/replication/parser.go b/replication/parser.go index 77eb7e9aa..5d8c32eec 100644 --- a/replication/parser.go +++ b/replication/parser.go @@ -281,6 +281,8 @@ func (p *BinlogParser) parseEvent(h *EventHeader, data []byte, rawData []byte) ( e = ee case PREVIOUS_GTIDS_EVENT: e = &PreviousGTIDsEvent{} + case INTVAR_EVENT: + e = &IntVarEvent{} default: e = &GenericEvent{} }