Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix binlog end log pos over lost data #1367

Merged
merged 14 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions go/binlog/gomysql_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ func (this *GoMySQLReader) GetCurrentBinlogCoordinates() *mysql.BinlogCoordinate

// StreamEvents
func (this *GoMySQLReader) handleRowsEvent(ev *replication.BinlogEvent, rowsEvent *replication.RowsEvent, entriesChannel chan<- *BinlogEntry) error {
if err := func() error {
if this.LastAppliedRowsEventHint.IsEmpty() {
return nil
}

if this.currentCoordinates.LogFile != this.LastAppliedRowsEventHint.LogFile {
return nil
}

if this.LastAppliedRowsEventHint.LogPos+this.currentCoordinates.EventSize >= 1<<32 {
// Unexpected rows event, the previous binlog log_pos + current binlog event_size is overflow 4 bytes
return fmt.Errorf("Unexpected rows event at %+v, the binlog end_log_pos is overflow 4 bytes", this.currentCoordinates)
}
return nil
}(); err != nil {
return err
}

if this.currentCoordinates.SmallerThanOrEquals(&this.LastAppliedRowsEventHint) {
this.migrationContext.Log.Debugf("Skipping handled query at %+v", this.currentCoordinates)
return nil
Expand Down Expand Up @@ -141,6 +159,7 @@ func (this *GoMySQLReader) StreamEvents(canStopStreaming func() bool, entriesCha
this.currentCoordinatesMutex.Lock()
defer this.currentCoordinatesMutex.Unlock()
this.currentCoordinates.LogPos = int64(ev.Header.LogPos)
this.currentCoordinates.EventSize = int64(ev.Header.EventSize)
}()

switch binlogEvent := ev.Event.(type) {
Expand Down
5 changes: 3 additions & 2 deletions go/mysql/binlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (

// BinlogCoordinates described binary log coordinates in the form of log file & log position.
type BinlogCoordinates struct {
LogFile string
LogPos int64
LogFile string
LogPos int64
EventSize int64
}

// ParseInstanceKey will parse an InstanceKey from a string representation such as 127.0.0.1:3306
Expand Down
Loading