Skip to content

Commit

Permalink
skip the "cancled" ddl in ddl history (#1229) (#1232)
Browse files Browse the repository at this point in the history
close #1228
  • Loading branch information
ti-chi-bot authored May 23, 2023
1 parent 589d79b commit a945b00
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drainer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,12 @@ ForLoop:
schema, table string
)
sql := b.job.Query

if b.job.BinlogInfo.SchemaVersion == 0 {
log.Info("skip ddl due to the failed ddl", zap.String("sql", sql), zap.Int64("commit ts", commitTS))
appendFakeBinlogIfNeeded(nil, commitTS)
continue
}
schema, table, err = s.schema.getSchemaTableAndDelete(b.job.BinlogInfo.SchemaVersion)
if err != nil {
err = errors.Trace(err)
Expand Down Expand Up @@ -505,8 +511,7 @@ ForLoop:
}
}
} else {
log.Info("skip ddl by SyncDDL setting to false", zap.String("schema", schema), zap.String("table", table),
zap.String("sql", sql), zap.Int64("commit ts", commitTS))
log.Info("skip ddl by SyncDDL setting to false", zap.String("sql", sql), zap.Int64("commit ts", commitTS))
// A empty sql force it to evict the downstream table info.
if s.cfg.DestDBType == "tidb" || s.cfg.DestDBType == "mysql" || s.cfg.DestDBType == "oracle" {
shouldSkip = true
Expand Down
28 changes: 28 additions & 0 deletions drainer/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,34 @@ func (s *syncerSuite) TestNewSyncer(c *check.C) {
job: job,
})

// Add failed ddl
commitTS++
jobID++
binlog = &pb.Binlog{
Tp: pb.BinlogType_Commit,
CommitTs: commitTS,
DdlQuery: []byte("alter table test.test add column a int"),
DdlJobId: jobID,
}
job = &model.Job{
ID: jobID,
SchemaID: 1, // must be the previous create schema id of `test`
Type: model.ActionAddColumn,
State: model.JobStateSynced,
Query: "create table test.test(id int)",
BinlogInfo: &model.HistoryInfo{
SchemaVersion: 0,
TableInfo: &model.TableInfo{
ID: testTableID,
Name: model.CIStr{O: "test", L: "test"},
},
},
}
syncer.Add(&binlogItem{
binlog: binlog,
job: job,
})

// Add dml
commitTS++
binlog = &pb.Binlog{
Expand Down

0 comments on commit a945b00

Please sign in to comment.