Skip to content

Commit 6d1c07f

Browse files
authored
fix(mysql): classify event checksum error (#4537)
verify event checksum and throw binlon invalid error if invalid
1 parent 557c1ad commit 6d1c07f

3 files changed

Lines changed: 21 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: 12 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,17 @@ func TestMySQLBinlogEventExceededMaxAllowedPacket(t *testing.T) {
907908
}, errInfo, "Unexpected error info")
908909
}
909910

911+
func TestMySQLBinlogChecksumMismatch(t *testing.T) {
912+
err := exceptions.NewMySQLExecuteError(
913+
fmt.Errorf("failed checksum for WriteRowsEventV2, log pos 12345: %v", replication.ErrChecksumMismatch))
914+
errorClass, errInfo := GetErrorClass(t.Context(), fmt.Errorf("failed in pull records: %w", err))
915+
assert.Equal(t, ErrorNotifyBinlogInvalid, errorClass, "Unexpected error class")
916+
assert.Equal(t, ErrorInfo{
917+
Source: ErrorSourceMySQL,
918+
Code: "BINLOG_CHECKSUM_MISMATCH",
919+
}, errInfo, "Unexpected error info")
920+
}
921+
910922
func TestMySQLExecuteError(t *testing.T) {
911923
err := exceptions.NewMySQLExecuteError(
912924
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
@@ -350,6 +350,7 @@ func (c *MySqlConnector) startSyncer(ctx context.Context, env map[string]string)
350350
DisableRetrySync: true,
351351
UseDecimal: true,
352352
ParseTime: true,
353+
VerifyChecksum: true,
353354
TLSConfig: tlsConfig,
354355
HeartbeatPeriod: c.binlogHeartbeatPeriod,
355356
EventCacheCount: eventCacheCount,

0 commit comments

Comments
 (0)