Skip to content

Commit 815a952

Browse files
committed
fix(canal): handle fake rotate events correctly for MariaDB 11.4
After upgrading to MariaDB 11.4, the canal module stopped detecting row updates within transactions due to incorrect handling of fake rotate events. MariaDB 11.4 does not set LogPos for certain events, causing these events to be ignored. This fix modifies the handling to consider fake rotate events only for ROTATE_EVENTs with timestamp = 0, aligning with MariaDB and MySQL documentation.
1 parent 2e5c5ac commit 815a952

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

canal/sync.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ func (c *Canal) runSyncBinlog() error {
4747
// Update the delay between the Canal and the Master before the handler hooks are called
4848
c.updateReplicationDelay(ev)
4949

50-
// If log pos equals zero then the received event is a fake rotate event and
51-
// contains only a name of the next binlog file
52-
// See https://github.com/mysql/mysql-server/blob/8e797a5d6eb3a87f16498edcb7261a75897babae/sql/rpl_binlog_sender.h#L235
53-
// and https://github.com/mysql/mysql-server/blob/8cc757da3d87bf4a1f07dcfb2d3c96fed3806870/sql/rpl_binlog_sender.cc#L899
54-
if ev.Header.LogPos == 0 {
55-
switch e := ev.Event.(type) {
56-
case *replication.RotateEvent:
50+
switch e := ev.Event.(type) {
51+
case *replication.RotateEvent:
52+
// If the timestamp equals zero, the received rotate event is a fake rotate event
53+
// and contains only the name of the next binlog file. Its log position should be
54+
// ignored.
55+
// See https://github.com/mysql/mysql-server/blob/8e797a5d6eb3a87f16498edcb7261a75897babae/sql/rpl_binlog_sender.h#L235
56+
// and https://github.com/mysql/mysql-server/blob/8cc757da3d87bf4a1f07dcfb2d3c96fed3806870/sql/rpl_binlog_sender.cc#L899
57+
if ev.Header.Timestamp == 0 {
5758
fakeRotateLogName := string(e.NextLogName)
5859
c.cfg.Logger.Infof("received fake rotate event, next log name is %s", e.NextLogName)
60+
5961
if fakeRotateLogName != c.master.Position().Name {
6062
c.cfg.Logger.Info("log name changed, the fake rotate event will be handled as a real rotate event")
6163
} else {
6264
continue
6365
}
64-
default:
65-
continue
6666
}
6767
}
6868

0 commit comments

Comments
 (0)