Skip to content

Commit

Permalink
Move {n|N}extPosition to uint64
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
mattlord committed Jan 8, 2025
1 parent 347d371 commit 7a45ff5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go/mysql/binlog_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type BinlogEvent interface {
IsValid() bool

// General protocol events.
NextPosition() uint32
NextPosition() uint64

// IsFormatDescription returns true if this is a
// FORMAT_DESCRIPTION_EVENT. Do not call StripChecksum before
Expand Down
5 changes: 3 additions & 2 deletions go/mysql/binlog_event_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ func (ev binlogEvent) Length() uint32 {
}

// NextPosition returns the nextPosition field from the header
func (ev binlogEvent) NextPosition() uint32 {
return binary.LittleEndian.Uint32(ev.Bytes()[13 : 13+4])
func (ev binlogEvent) NextPosition() uint64 {
// Only 4 bytes are used for the next_position field in the header.
return uint64(binary.LittleEndian.Uint32(ev.Bytes()[13 : 13+4]))
}

// IsFormatDescription implements BinlogEvent.IsFormatDescription().
Expand Down
6 changes: 3 additions & 3 deletions go/mysql/binlog_event_filepos.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +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) uint32 {
func (ev *filePosBinlogEvent) nextPosition(f BinlogFormat) uint64 {
if f.HeaderLength <= 13 {
// Dead code. This is just a failsafe.
return 0
}
// The header only uses 4 bytes for the next_position.
return binary.LittleEndian.Uint32(ev.Bytes()[13:17])
return uint64(binary.LittleEndian.Uint32(ev.Bytes()[13:17]))
}

// rotate implements BinlogEvent.Rotate().
Expand Down Expand Up @@ -140,7 +140,7 @@ type filePosFakeEvent struct {
timestamp uint32
}

func (ev filePosFakeEvent) NextPosition() uint32 {
func (ev filePosFakeEvent) NextPosition() uint64 {
return 0
}

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, uint64(event.nextPosition(flv.format)), event.Timestamp()), nil
return newFilePosGTIDEvent(flv.file, 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, uint64(event.nextPosition(flv.format)), event.Timestamp()), nil
return newFilePosGTIDEvent(flv.file, 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, uint64(v), event.Timestamp()), nil
return newFilePosGTIDEvent(flv.file, v, event.Timestamp()), nil
}
}
}
Expand Down

0 comments on commit 7a45ff5

Please sign in to comment.