Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#5273
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
lance6716 authored and ti-chi-bot committed Apr 27, 2022
1 parent f988cdf commit 397bcc6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions dm/syncer/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func (b *binlogPoint) rollback(schemaTracker *schema.Tracker, schema string) (is
b.flushedPoint.location.ResetSuffix()
b.savedPoint.location = b.flushedPoint.location
if b.savedPoint.ti == nil {
// TODO: if we forget to save table info for table checkpoint, this is also nil!
// And table checkpoint rollback to flushed point may also be nil!
return // for global checkpoint, no need to rollback the schema.
}

Expand Down
1 change: 1 addition & 0 deletions dm/syncer/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (s *Syncer) skipQueryEvent(qec *queryEventContext, ddlInfo *ddlInfo) (bool,
if err != nil {
s.tctx.L().Warn("track ddl failed", zap.Stringer("ddl info", ddlInfo))
}
s.saveTablePoint(table, *qec.lastLocation)
s.tctx.L().Warn("track skipped ddl and return empty string", zap.String("origin sql", qec.originSQL), zap.Stringer("ddl info", ddlInfo))
ddlInfo.originDDL = ""
return true, nil
Expand Down
18 changes: 15 additions & 3 deletions dm/syncer/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ import (
"database/sql"

"github.com/DATA-DOG/go-sqlmock"
"github.com/go-mysql-org/go-mysql/mysql"
"github.com/go-mysql-org/go-mysql/replication"
. "github.com/pingcap/check"
bf "github.com/pingcap/tidb-tools/pkg/binlog-filter"
"github.com/pingcap/tidb-tools/pkg/filter"
"github.com/pingcap/tidb/parser"
<<<<<<< HEAD
=======
"github.com/pingcap/tidb/util/filter"
"github.com/pingcap/tiflow/dm/pkg/binlog"
>>>>>>> 7744c05a7 (syncer(dm): save table checkpoint after a DDL is filtered (#5273))

"github.com/pingcap/tiflow/dm/dm/config"
"github.com/pingcap/tiflow/dm/pkg/conn"
Expand Down Expand Up @@ -69,6 +75,7 @@ func (s *testFilterSuite) TestSkipQueryEvent(c *C) {
syncer.ddlDBConn = &dbconn.DBConn{Cfg: syncer.cfg, BaseConn: s.baseConn}
syncer.schemaTracker, err = schema.NewTracker(context.Background(), syncer.cfg.Name, defaultTestSessionCfg, syncer.ddlDBConn)
c.Assert(err, IsNil)
defer syncer.schemaTracker.Close()
syncer.exprFilterGroup = NewExprFilterGroup(utils.NewSessionCtx(nil), nil)

// test binlog filter
Expand Down Expand Up @@ -126,11 +133,16 @@ func (s *testFilterSuite) TestSkipQueryEvent(c *C) {
}
p := parser.New()

loc := binlog.NewLocation(mysql.MySQLFlavor)

for _, ca := range cases {
qec := &queryEventContext{
eventContext: &eventContext{tctx: tcontext.Background()},
p: p,
ddlSchema: ca.schema,
eventContext: &eventContext{
tctx: tcontext.Background(),
lastLocation: &loc,
},
p: p,
ddlSchema: ca.schema,
}
ddlInfo, err := syncer.genDDLInfo(qec, ca.sql)
c.Assert(err, IsNil)
Expand Down
3 changes: 3 additions & 0 deletions dm/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3147,6 +3147,9 @@ func (s *Syncer) loadTableStructureFromDump(ctx context.Context) error {
zap.Error(err))
setFirstErr(err)
}
// TODO: we should save table checkpoint here, but considering when
// the first time of flushing checkpoint, user may encounter https://github.com/pingcap/tiflow/issues/5010
// we should fix that problem first.
}
}
return firstErr
Expand Down
9 changes: 8 additions & 1 deletion dm/tests/tracker_ignored_ddl/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,26 @@ function run() {
check_not_contains "ignore_1"
echo "increment1 check success"

# a not ignored DDL to trigger a checkpoint flush
run_sql_source1 "create table tracker_ignored_ddl.test (c int primary key);"

run_sql_file $cur/data/db.increment2.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Error 1054: Unknown column" 1

# force a resume, the error is still there, but we want to check https://github.com/pingcap/tiflow/issues/5272#issuecomment-1109283279
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"resume-task test"

# need operate tidb
run_sql_tidb "alter table $TEST_NAME.t1 add column ignore_1 int;"

# resume task
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"resume-task test" \
"\"result\": true" 2
sleep 1
sleep 3
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"stage\": \"Running\"" 2
Expand Down

0 comments on commit 397bcc6

Please sign in to comment.