Skip to content

Canal: Wrong binlog position after MariaDB is restarted #406

@mefcorvi

Description

@mefcorvi

STR

  1. Start syncing
  2. Stop MariaDB
  3. Start MariaDB
  4. Ensure that canal is reconnected.
  5. Commit some transaction in the database.

Expected

Binlog position is correct in the OnXID handler.

Actual

pos.Pos is updated to the new position, but pos.Name is wrong.

Environment

MariaDB 10.3.14

MariaDB creates a new binlog file on start and sends fake rotate events with a new binlog filename and position. These events are ignored in canal as a consequence of the #397 so Pos is updated with LogPos from headers of the received events but Name stays the same as before reconnection.

I believe that issue should be reproducible with MySQL but I don't have one to verify this.

Logs

[info] sync.go:57 MariadbGTIDEvent: 1841
[info] sync.go:66 CurPos: (mysql-bin.000017, 1841)
[info] sync.go:57 QueryEvent: 2201
[info] sync.go:66 CurPos: (mysql-bin.000017, 2201)
[info] binlogsyncer.go:698 receive EOF packet, retry ReadPacket
[error] binlogsyncer.go:639 connection was bad
[info] binlogsyncer.go:581 begin to re-sync from (mysql-bin.000017, 2201)
...
[info] binlogsyncer.go:211 register slave for master server mysql:3306
[error] binlogsyncer.go:239 kill connection 17 error ERROR 1094 (HY000): Unknown thread id: 17
[info] binlogsyncer.go:245 kill last connection id 17
[info] binlogsyncer.go:731 rotate to (mysql-bin.000017, 2201)
[info] binlogsyncer.go:731 rotate to (mysql-bin.000018, 4)
[info] sync.go:57 RotateEvent: 0
[info] sync.go:57 FormatDescriptionEvent: 0
[info] sync.go:57 StopEvent: 2224
[info] sync.go:66 CurPos: (mysql-bin.000017, 2224)
[info] sync.go:57 RotateEvent: 0
[info] sync.go:57 FormatDescriptionEvent: 256
[info] sync.go:66 CurPos: (mysql-bin.000017, 256)
[info] sync.go:57 MariadbGTIDListEvent: 299
[info] sync.go:66 CurPos: (mysql-bin.000017, 299)
[info] sync.go:57 MariadbBinLogCheckPointEvent: 342
[info] sync.go:66 CurPos: (mysql-bin.000017, 342)
[info] sync.go:57 MariadbGTIDEvent: 384
[info] sync.go:66 CurPos: (mysql-bin.000017, 384)
[info] sync.go:57 TableMapEvent: 502
[info] sync.go:66 CurPos: (mysql-bin.000017, 502)
[info] sync.go:57 DeleteRowsEventV1: 616
[info] sync.go:66 CurPos: (mysql-bin.000017, 616)
[info] sync.go:57 XIDEvent: 647
[info] sync.go:66 CurPos: (mysql-bin.000017, 647)

CurPos must be (mysql-bin.000018, 647) for XIDEvent.

Events and log pos are written by log.Infof("%v: %v", ev.Header.EventType, ev.Header.LogPos) before checking for header's LogPos and log.Infof("CurPos: %v", pos) before the switch.

To be honest I'm not sure how ignoring fake rotate events helps to mitigate issue in #396
Probably @csuzhangxc or @lintanghui can shed some light on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions