Skip to content

Commit

Permalink
changefeed (ticdc): fix data lost when pause and resume changefeed wh…
Browse files Browse the repository at this point in the history
…ile executing DDL. (#7683)

close #7682
  • Loading branch information
asddongmen authored Nov 22, 2022
1 parent c680d35 commit 719d270
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion cdc/owner/changefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,12 @@ LOOP:
return errors.Trace(err)
}

// we must clean cached ddl and tables in changefeed initialization
// otherwise, the changefeed will loss tables that are needed to be replicated
// ref: https://github.com/pingcap/tiflow/issues/7682
c.ddlEventCache = nil
c.currentTables = nil

cancelCtx, cancel := cdcContext.WithCancel(ctx)
c.cancel = cancel

Expand Down Expand Up @@ -609,7 +615,9 @@ func (c *changefeed) releaseResources(ctx cdcContext.Context) {
log.Info("changefeed closed",
zap.String("namespace", c.id.Namespace),
zap.String("changefeed", c.id.ID),
zap.Stringer("info", c.state.Info), zap.Bool("isRemoved", c.isRemoved))
zap.Any("status", c.state.Status),
zap.Stringer("info", c.state.Info),
zap.Bool("isRemoved", c.isRemoved))
}

func (c *changefeed) cleanupMetrics() {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/batch_update_to_no_batch/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function run() {
# pause changefeed
run_cdc_cli changefeed pause -c ${changefeed_id}
# update changefeed to no batch dml mode
run_cdc_cli changefeed update -c ${changefeed_id} --sink-uri="mysql://root@127.0.0.1:3306/?batch-dml-enable=true" --no-confirm
run_cdc_cli changefeed update -c ${changefeed_id} --sink-uri="mysql://root@127.0.0.1:3306/?batch-dml-enable=false" --no-confirm
# resume changefeed
run_cdc_cli changefeed resume -c ${changefeed_id}

Expand All @@ -53,7 +53,7 @@ function run() {
# pause changefeed
run_cdc_cli changefeed pause -c ${changefeed_id}
# update changefeed to no batch dml mode
run_cdc_cli changefeed update -c ${changefeed_id} --sink-uri="mysql://root@127.0.0.1:3306/?batch-dml-enable=false" --no-confirm
run_cdc_cli changefeed update -c ${changefeed_id} --sink-uri="mysql://root@127.0.0.1:3306/?batch-dml-enable=true" --no-confirm
# resume changefeed
run_cdc_cli changefeed resume -c ${changefeed_id}

Expand Down

0 comments on commit 719d270

Please sign in to comment.