Skip to content

fix(mysql): handle binlog incident event (resync required)#4435

Merged
dtunikov merged 2 commits into
mainfrom
fix/dbi-814/mysql-handle-binlog-incident-event
Jun 18, 2026
Merged

fix(mysql): handle binlog incident event (resync required)#4435
dtunikov merged 2 commits into
mainfrom
fix/dbi-814/mysql-handle-binlog-incident-event

Conversation

@dtunikov

@dtunikov dtunikov commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Handle MySQL binlog INCIDENT_EVENT (e.g. LOST_EVENTS) in the CDC pull loop. When the source emits an incident event, binlog events were lost from the stream and our CDC position can no longer be trusted — so we fail with a resync-required error rather than silently skipping the gap.

  • Detect INCIDENT_EVENT (decoded by go-mysql as GenericEvent, gated on the header event type) in PullRecords and return a new MySQLBinlogIncidentError.
  • Add parseIncidentEvent to extract the incident number and message from the event body.
  • Classify MySQLBinlogIncidentError as ErrorNotifyBinlogInvalid / BINLOG_INCIDENT in the alerting classifier.

🤖 Generated with Claude Code

@dtunikov dtunikov requested a review from a team as a code owner June 16, 2026 10:50
@claude

claude Bot commented Jun 16, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds explicit handling for MySQL binlog INCIDENT_EVENT (e.g. LOST_EVENTS) during CDC streaming so the connector fails fast with a resync-required error when the binlog stream has an unrecoverable gap, and ensures alerting classifies this condition as a binlog invalidation.

Changes:

  • Detect INCIDENT_EVENT in the MySQL CDC pull loop and return a new MySQLBinlogIncidentError (resync required).
  • Add parseIncidentEvent to extract incident number and message from the incident event payload.
  • Classify MySQLBinlogIncidentError as ErrorNotifyBinlogInvalid with code BINLOG_INCIDENT in the alerting classifier.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
flow/shared/exceptions/mysql.go Adds a dedicated error type for binlog incident events indicating resync is required.
flow/connectors/mysql/cdc.go Detects incident events during CDC streaming and parses incident details from the event payload.
flow/alerting/classifier.go Maps the new incident error to a binlog invalidation notification class/code.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread flow/connectors/mysql/cdc.go Outdated
Comment on lines +887 to +900
// parseIncidentEvent extracts the incident number and human-readable message from an
// Incident_log_event body: a little-endian uint16 incident number, a 1-byte message
// length, then the message. Best-effort: returns what it can if the body is truncated.
func parseIncidentEvent(data []byte) (uint16, string) {
if len(data) < 2 {
return 0, ""
}
incident := binary.LittleEndian.Uint16(data[:2])
if len(data) < 3 {
return incident, ""
}
end := min(3+int(data[2]), len(data))
return incident, string(data[3:end])
}
Comment thread flow/alerting/classifier.go
}
case *replication.GenericEvent:
// INCIDENT_EVENT (LOST_EVENTS) - fail and require resync
if event.Header.EventType == replication.INCIDENT_EVENT {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this tested manually? MySQL can trigger this event in a debug build. Sadly we can't do this in CI as binlog is global but with testcontainers, maybe one day

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oook, tried testing it locally, couldn't reproduce it under various conditions
most critical binlog issues are already being catched by:

case 1236: // ER_MASTER_FATAL_ERROR_READING_BINLOG

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's testable #4442

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to merge, then I'll merge from main

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@dtunikov dtunikov merged commit e584bca into main Jun 18, 2026
24 checks passed
@dtunikov dtunikov deleted the fix/dbi-814/mysql-handle-binlog-incident-event branch June 18, 2026 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants