Skip to content

Commit 5ba109a

Browse files
committed
Made the targeted‑skip variant: we now ignore SET TIMESTAMP / reset failures only when the downstream returns specific “bad value / unknown var” errors
1 parent d837830 commit 5ba109a

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed

cdc/sink/ddlsink/mysql/helper.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import (
2121
"strings"
2222
"time"
2323

24+
dmysql "github.com/go-sql-driver/mysql"
25+
"github.com/pingcap/errors"
2426
"github.com/pingcap/log"
27+
"github.com/pingcap/tidb/pkg/errno"
2528
timodel "github.com/pingcap/tidb/pkg/meta/model"
2629
"github.com/pingcap/tidb/pkg/parser"
2730
"github.com/pingcap/tidb/pkg/parser/ast"
@@ -40,6 +43,24 @@ func resetSessionTimestamp(ctx context.Context, tx *sql.Tx) error {
4043
return err
4144
}
4245

46+
func isIgnorableSessionTimestampErr(err error) bool {
47+
if err == nil {
48+
return false
49+
}
50+
mysqlErr, ok := errors.Cause(err).(*dmysql.MySQLError)
51+
if !ok {
52+
return false
53+
}
54+
switch mysqlErr.Number {
55+
case uint16(errno.ErrWrongValueForVar),
56+
uint16(errno.ErrTruncatedWrongValue),
57+
uint16(errno.ErrUnknownSystemVariable):
58+
return true
59+
default:
60+
return false
61+
}
62+
}
63+
4364
func formatUnixTimestamp(unixTimestamp float64) string {
4465
return strconv.FormatFloat(unixTimestamp, 'f', 6, 64)
4566
}

cdc/sink/ddlsink/mysql/mysql_ddl_sink.go

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,26 @@ func (m *DDLSink) execDDL(pctx context.Context, ddl *model.DDLEvent) error {
216216
if useSessionTimestamp {
217217
// set the session timestamp to match upstream DDL execution time
218218
if err := setSessionTimestamp(ctx, tx, ddlTimestamp); err != nil {
219-
log.Error("Fail to set session timestamp for DDL",
220-
zap.Float64("timestamp", ddlTimestamp),
221-
zap.Uint64("startTs", ddl.StartTs),
222-
zap.Uint64("commitTs", ddl.CommitTs),
223-
zap.String("query", ddl.Query),
224-
zap.Error(err))
225-
if rbErr := tx.Rollback(); rbErr != nil {
226-
log.Error("Failed to rollback", zap.String("changefeed", m.id.ID), zap.Error(rbErr))
219+
if isIgnorableSessionTimestampErr(err) {
220+
log.Warn("Fail to set session timestamp for DDL, continue without session timestamp",
221+
zap.Float64("timestamp", ddlTimestamp),
222+
zap.Uint64("startTs", ddl.StartTs),
223+
zap.Uint64("commitTs", ddl.CommitTs),
224+
zap.String("query", ddl.Query),
225+
zap.Error(err))
226+
useSessionTimestamp = false
227+
} else {
228+
log.Error("Fail to set session timestamp for DDL",
229+
zap.Float64("timestamp", ddlTimestamp),
230+
zap.Uint64("startTs", ddl.StartTs),
231+
zap.Uint64("commitTs", ddl.CommitTs),
232+
zap.String("query", ddl.Query),
233+
zap.Error(err))
234+
if rbErr := tx.Rollback(); rbErr != nil {
235+
log.Error("Failed to rollback", zap.String("changefeed", m.id.ID), zap.Error(rbErr))
236+
}
237+
return err
227238
}
228-
return err
229239
}
230240
}
231241

@@ -252,11 +262,18 @@ func (m *DDLSink) execDDL(pctx context.Context, ddl *model.DDLEvent) error {
252262
if useSessionTimestamp {
253263
// reset session timestamp after DDL execution to avoid affecting subsequent operations
254264
if err := resetSessionTimestamp(ctx, tx); err != nil {
255-
log.Error("Failed to reset session timestamp after DDL execution", zap.Error(err))
256-
if rbErr := tx.Rollback(); rbErr != nil {
257-
log.Error("Failed to rollback", zap.String("sql", ddl.Query), zap.Error(rbErr))
265+
if isIgnorableSessionTimestampErr(err) {
266+
log.Warn("Failed to reset session timestamp after DDL execution, continue",
267+
zap.String("namespace", m.id.Namespace),
268+
zap.String("changefeed", m.id.ID),
269+
zap.Error(err))
270+
} else {
271+
log.Error("Failed to reset session timestamp after DDL execution", zap.Error(err))
272+
if rbErr := tx.Rollback(); rbErr != nil {
273+
log.Error("Failed to rollback", zap.String("sql", ddl.Query), zap.Error(rbErr))
274+
}
275+
return errors.WrapError(errors.ErrMySQLTxnError, errors.WithMessage(err, fmt.Sprintf("Query info: %s; ", ddl.Query)))
258276
}
259-
return errors.WrapError(errors.ErrMySQLTxnError, errors.WithMessage(err, fmt.Sprintf("Query info: %s; ", ddl.Query)))
260277
}
261278
}
262279

0 commit comments

Comments
 (0)