Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syncer(dm): save table checkpoint after a DDL is filtered #5273

Merged
merged 4 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dm/syncer/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,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!
Copy link
Contributor

Choose a reason for hiding this comment

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

table point which rollbacks before can also be 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
14 changes: 11 additions & 3 deletions dm/syncer/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ 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/parser"
"github.com/pingcap/tidb/util/filter"
"github.com/pingcap/tiflow/dm/pkg/binlog"

"github.com/pingcap/tiflow/dm/dm/config"
"github.com/pingcap/tiflow/dm/pkg/conn"
Expand Down Expand Up @@ -69,6 +71,7 @@ func (s *testFilterSuite) TestSkipQueryEvent(c *C) {
syncer.ddlDBConn = dbconn.NewDBConn(syncer.cfg, 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 +129,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 @@ -3314,6 +3314,9 @@ func (s *Syncer) loadTableStructureFromDump(ctx context.Context) error {
zap.Error(err))
setFirstErr(err)
}
// TODO: we should save table checkpoint here, but considering when
lance6716 marked this conversation as resolved.
Show resolved Hide resolved
// 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" \
Comment on lines +49 to 50
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems the run_dm_ctl_with_retry already meets the requirements

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to wait some time to see if an error is going to happen

"query-status test" \
"\"stage\": \"Running\"" 2
Expand Down