Skip to content

Commit 392e4ca

Browse files
authored
Merge pull request #753 from gaojijun/master
handle fake rotate event as real if binlog filename changed
2 parents 8206ccd + bf4f639 commit 392e4ca

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

canal/sync.go

+8-13
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ func (c *Canal) runSyncBinlog() error {
4343
savePos := false
4444
force := false
4545

46-
// The name of the binlog file received in the fake rotate event.
47-
// It must be preserved until the new position is saved.
48-
fakeRotateLogName := ""
49-
5046
for {
5147
ev, err := s.GetEvent(c.ctx)
5248
if err != nil {
@@ -63,11 +59,16 @@ func (c *Canal) runSyncBinlog() error {
6359
if ev.Header.LogPos == 0 {
6460
switch e := ev.Event.(type) {
6561
case *replication.RotateEvent:
66-
fakeRotateLogName = string(e.NextLogName)
62+
fakeRotateLogName := string(e.NextLogName)
6763
c.cfg.Logger.Infof("received fake rotate event, next log name is %s", e.NextLogName)
64+
if fakeRotateLogName != c.master.Position().Name {
65+
c.cfg.Logger.Info("log name changed, the fake rotate event will be handled as a real rotate event")
66+
} else {
67+
continue
68+
}
69+
default:
70+
continue
6871
}
69-
70-
continue
7172
}
7273

7374
savePos = false
@@ -79,11 +80,6 @@ func (c *Canal) runSyncBinlog() error {
7980
// next binlog pos
8081
pos.Pos = ev.Header.LogPos
8182

82-
// new file name received in the fake rotate event
83-
if fakeRotateLogName != "" {
84-
pos.Name = fakeRotateLogName
85-
}
86-
8783
// We only save position with RotateEvent and XIDEvent.
8884
// For RowsEvent, we can't save the position until meeting XIDEvent
8985
// which tells the whole transaction is over.
@@ -174,7 +170,6 @@ func (c *Canal) runSyncBinlog() error {
174170
if savePos {
175171
c.master.Update(pos)
176172
c.master.UpdateTimestamp(ev.Header.Timestamp)
177-
fakeRotateLogName = ""
178173

179174
if err := c.eventHandler.OnPosSynced(ev.Header, pos, c.master.GTIDSet(), force); err != nil {
180175
return errors.Trace(err)

0 commit comments

Comments
 (0)