Skip to content

Commit 80555c2

Browse files
committed
classify event checksum mysql error
1 parent cd189a0 commit 80555c2

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

flow/alerting/classifier.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
chproto "github.com/ClickHouse/ch-go/proto"
1818
"github.com/ClickHouse/clickhouse-go/v2"
1919
"github.com/go-mysql-org/go-mysql/mysql"
20+
"github.com/go-mysql-org/go-mysql/replication"
2021
"github.com/jackc/pgerrcode"
2122
"github.com/jackc/pgx/v5/pgconn"
2223
"go.mongodb.org/mongo-driver/v2/mongo"
@@ -1129,6 +1130,13 @@ func GetErrorClass(ctx context.Context, err error) (ErrorClass, ErrorInfo) {
11291130
}
11301131
}
11311132

1133+
if strings.Contains(err.Error(), replication.ErrChecksumMismatch.Error()) {
1134+
return ErrorNotifyBinlogInvalid, ErrorInfo{
1135+
Source: ErrorSourceMySQL,
1136+
Code: "BINLOG_CHECKSUM_MISMATCH",
1137+
}
1138+
}
1139+
11321140
if mysqlExecuteError, ok := errors.AsType[*exceptions.MySQLExecuteError](err); ok {
11331141
errClass := ErrorOther
11341142
if mysqlExecuteError.Retryable {

flow/alerting/classifier_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
chproto "github.com/ClickHouse/ch-go/proto"
1616
"github.com/ClickHouse/clickhouse-go/v2"
1717
"github.com/go-mysql-org/go-mysql/mysql"
18+
"github.com/go-mysql-org/go-mysql/replication"
1819
"github.com/jackc/pgerrcode"
1920
"github.com/jackc/pgx/v5"
2021
"github.com/jackc/pgx/v5/pgconn"
@@ -907,6 +908,18 @@ func TestMySQLBinlogEventExceededMaxAllowedPacket(t *testing.T) {
907908
}, errInfo, "Unexpected error info")
908909
}
909910

911+
func TestMySQLBinlogChecksumMismatch(t *testing.T) {
912+
// go-mysql flattens ErrChecksumMismatch into the message; PullRecords wraps it as a MySQLExecuteError.
913+
err := exceptions.NewMySQLExecuteError(
914+
fmt.Errorf("failed checksum for WriteRowsEventV2, log pos 12345: %v", replication.ErrChecksumMismatch))
915+
errorClass, errInfo := GetErrorClass(t.Context(), fmt.Errorf("failed in pull records: %w", err))
916+
assert.Equal(t, ErrorNotifyBinlogInvalid, errorClass, "Unexpected error class")
917+
assert.Equal(t, ErrorInfo{
918+
Source: ErrorSourceMySQL,
919+
Code: "BINLOG_CHECKSUM_MISMATCH",
920+
}, errInfo, "Unexpected error info")
921+
}
922+
910923
func TestMySQLExecuteError(t *testing.T) {
911924
err := exceptions.NewMySQLExecuteError(
912925
tls.RecordHeaderError{Msg: "first record does not look like a TLS handshake"})

flow/connectors/mysql/cdc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ func (c *MySqlConnector) startSyncer(ctx context.Context, env map[string]string)
354354
DisableRetrySync: true,
355355
UseDecimal: true,
356356
ParseTime: true,
357+
VerifyChecksum: true,
357358
TLSConfig: tlsConfig,
358359
HeartbeatPeriod: c.binlogHeartbeatPeriod,
359360
EventCacheCount: eventCacheCount,

0 commit comments

Comments
 (0)