Skip to content

Commit

Permalink
The next_position value in the binlog event header is 4 bytes
Browse files Browse the repository at this point in the history
Boy, MySQL SURE IS FUN!

Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Jan 7, 2025
1 parent bb933e0 commit 6731e1e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go/mysql/binlog_event_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (
// +----------------------------+
// | extra_headers 19 : x-19 |
// +============================+
// http://dev.mysql.com/doc/internals/en/event-header-fields.html
// https://dev.mysql.com/doc/dev/mysql-server/8.0.40/page_protocol_replication_binlog_event.html#sect_protocol_replication_binlog_event_header
type binlogEvent []byte

const (
Expand Down
5 changes: 3 additions & 2 deletions go/mysql/binlog_event_filepos.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ func (ev *filePosBinlogEvent) StripChecksum(f BinlogFormat) (BinlogEvent, []byte

// nextPosition returns the next file position of the binlog.
// If no information is available, it returns 0.
func (ev *filePosBinlogEvent) nextPosition(f BinlogFormat) uint64 {
func (ev *filePosBinlogEvent) nextPosition(f BinlogFormat) uint32 {
if f.HeaderLength <= 13 {
// Dead code. This is just a failsafe.
return 0
}
return binary.LittleEndian.Uint64(ev.Bytes()[13:21])
// The header only uses 4 bytes for the next_position.
return binary.LittleEndian.Uint32(ev.Bytes()[13:17])
}

// rotate implements BinlogEvent.Rotate().
Expand Down
6 changes: 3 additions & 3 deletions go/mysql/flavor_filepos.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,21 @@ func (flv *filePosFlavor) readBinlogEvent(c *Conn) (BinlogEvent, error) {
eDeleteRowsEventV0, eDeleteRowsEventV1, eDeleteRowsEventV2,
eUpdateRowsEventV0, eUpdateRowsEventV1, eUpdateRowsEventV2:
flv.savedEvent = event
return newFilePosGTIDEvent(flv.file, event.nextPosition(flv.format), event.Timestamp()), nil
return newFilePosGTIDEvent(flv.file, uint64(event.nextPosition(flv.format)), event.Timestamp()), nil
case eQueryEvent:
q, err := event.Query(flv.format)
if err == nil && strings.HasPrefix(q.SQL, "#") {
continue
}
flv.savedEvent = event
return newFilePosGTIDEvent(flv.file, event.nextPosition(flv.format), event.Timestamp()), nil
return newFilePosGTIDEvent(flv.file, uint64(event.nextPosition(flv.format)), event.Timestamp()), nil
default:
// For unrecognized events, send a fake "repair" event so that
// the position gets transmitted.
if !flv.format.IsZero() {
if v := event.nextPosition(flv.format); v != 0 {
flv.savedEvent = newFilePosQueryEvent("repair", event.Timestamp())
return newFilePosGTIDEvent(flv.file, v, event.Timestamp()), nil
return newFilePosGTIDEvent(flv.file, uint64(v), event.Timestamp()), nil
}
}
}
Expand Down

0 comments on commit 6731e1e

Please sign in to comment.