Skip to content

Commit

Permalink
skip the "cancled" ddl in ddl history (#1229) (#1230) (#1255)
Browse files Browse the repository at this point in the history
close #1228
  • Loading branch information
ti-chi-bot authored Jul 3, 2023
1 parent 8668095 commit 9f5e669
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 @@ -465,6 +465,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 @@ -504,8 +510,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 9f5e669

Please sign in to comment.