Skip to content

Commit fd31578

Browse files
committed
fix(replication): calculate LogPos for non-artificial events in MariaDB 11.4+
1 parent 84c5e8e commit fd31578

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

replication/binlogsyncer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,16 @@ func (b *BinlogSyncer) handleEventAndACK(s *BinlogStreamer, e *BinlogEvent, need
861861
if e.Header.LogPos > 0 {
862862
// Some events like FormatDescriptionEvent return 0, ignore.
863863
b.nextPos.Pos = e.Header.LogPos
864+
} else if b.cfg.Flavor == mysql.MariaDBFlavor && (e.Header.Flags&LOG_EVENT_ARTIFICIAL_F) == 0 && e.Header.LogPos == 0 {
865+
// For MariaDB 11.4+, some events may have LogPos=0 but are still valid position updates
866+
// if they are not artificial events (marked with LOG_EVENT_ARTIFICIAL_F flag).
867+
// For such events, we calculate the next position dynamically.
868+
calculatedPos := b.nextPos.Pos + e.Header.EventSize
869+
e.Header.LogPos = calculatedPos
870+
b.nextPos.Pos = calculatedPos
871+
b.cfg.Logger.Debug("MariaDB event with LogPos=0 but not artificial, calculated position",
872+
slog.String("eventType", e.Header.EventType.String()),
873+
slog.Uint64("logPos", uint64(calculatedPos)))
864874
}
865875

866876
// Handle event types to update positions and GTID sets

0 commit comments

Comments
 (0)