Skip to content

kafka-consumer(ticdc): tolerate replayed resolved and DDL events (#12596)#12620

Open
ti-chi-bot wants to merge 1 commit into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-12596-to-release-8.5
Open

kafka-consumer(ticdc): tolerate replayed resolved and DDL events (#12596)#12620
ti-chi-bot wants to merge 1 commit into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-12596-to-release-8.5

Conversation

@ti-chi-bot
Copy link
Copy Markdown
Member

This is an automated cherry-pick of #12596

What problem does this PR solve?

Issue Number: close #12595

What is changed and how it works?

  • treat replayed resolved/checkpoint fallback in cmd/kafka-consumer as duplicate delivery instead of a fatal error
  • deduplicate replayed DDL events by logical DDL identity instead of pointer identity
  • add regression tests covering replayed resolved/checkpoint handling and equivalent versus split DDL events

Check List

Tests

  • Unit test
  • Manual test

Questions

Will it cause performance regression or break compatibility?

No. This only makes the standalone Kafka consumer tolerate duplicate MQ delivery in line with TiCDC's at-least-once behavior.

Do you need to update user documentation, design documentation or monitoring documentation?

No.

Release note

Fix `cdc_kafka_consumer` to tolerate replayed resolved/checkpoint and equivalent DDL messages under duplicate MQ delivery.

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR. labels Apr 24, 2026
@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 24, 2026

This cherry pick PR is for a release branch and has not yet been approved by triage owners.
Adding the do-not-merge/cherry-pick-not-approved label.

To merge this cherry pick:

  1. It must be LGTMed and approved by the reviewers firstly.
  2. For pull requests to TiDB-x branches, it must have no failed tests.
  3. AFTER it has lgtm and approved labels, please wait for the cherry-pick merging approval from triage owners.
Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot
Copy link
Copy Markdown
Member Author

@wlwilliamx This PR has conflicts, I have hold it.
Please resolve them or ask others to resolve them, then comment /unhold to remove the hold label.

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 24, 2026

@ti-chi-bot: ## If you want to know how to resolve it, please read the guide in TiDB Dev Guide.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 24, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign benjamin2037 for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements logic to tolerate replayed resolved and DDL events in the Kafka consumer by introducing DDL deduplication and watermark fallback handling. The review identifies critical issues including multiple unresolved merge conflict markers throughout the code, a missing field in the partitionProgress struct, and potential data races due to non-atomic access of shared state.

Comment on lines +80 to +87
<<<<<<< HEAD
eventGroups map[int64]*eventsGroup
decoder codec.RowEventDecoder
=======
tableSinkMap map[model.TableID]tablesink.TableSink
eventGroups map[model.TableID]*eventsGroup
decoder codec.RowEventDecoder
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

Unresolved merge conflict markers found in partitionProgress. Additionally, the struct is missing the partition field which is initialized in newPartitionProgress (line 91) and used in updateWatermark (line 103). Please resolve the conflicts and add the missing field to ensure the code compiles and functions correctly.

Comment on lines +134 to +147
<<<<<<< HEAD
ddlList []*model.DDLEvent
ddlWithMaxCommitTs *model.DDLEvent
ddlSink ddlsink.Sink
fakeTableIDGenerator *fakeTableIDGenerator
=======
ddlList []*model.DDLEvent
ddlWithMaxCommitTs *model.DDLEvent
// ddlKeysWithMaxCommitTs records every logical DDL seen at the current
// maximum CommitTs, so replayed prefixes of split DDL sequences can be
// ignored without collapsing distinct DDLs that share the same CommitTs.
ddlKeysWithMaxCommitTs map[ddlEventKey]struct{}
ddlSink ddlsink.Sink
>>>>>>> 431c2afbed (kafka-consumer(ticdc): tolerate replayed resolved and DDL events (#12596))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

Unresolved merge conflict markers found in the writer struct definition. This will prevent the code from compiling and indicates an incomplete cherry-pick process.

Comment on lines +269 to +273
<<<<<<< HEAD
=======
w.ddlKeysWithMaxCommitTs[ddlKey] = struct{}{}
log.Info("DDL message received", zap.Any("offset", offset), zap.Uint64("commitTs", ddl.CommitTs), zap.String("DDL", ddl.Query))
>>>>>>> 431c2afbed (kafka-consumer(ticdc): tolerate replayed resolved and DDL events (#12596))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

Unresolved merge conflict markers in appendDDL. The logic should be resolved to correctly update the deduplication map and log the DDL event using the provided offset.

	w.ddlKeysWithMaxCommitTs[ddlKey] = struct{}{}
	log.Info("DDL message received", zap.Any("offset", offset), zap.Uint64("commitTs", ddl.CommitTs), zap.String("DDL", ddl.Query))

Comment on lines +101 to +102
p.watermark = newWatermark
p.watermarkOffset = offset
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Direct assignment to p.watermark and p.watermarkOffset causes a data race. These fields are accessed concurrently by other goroutines (e.g., in getMinWatermark and checkOldMessage) using atomic operations or direct reads. Use atomic operations to ensure thread safety.

		atomic.StoreUint64(&p.watermark, newWatermark)
		atomic.StoreInt64((*int64)(&p.watermarkOffset), int64(offset))

Comment on lines +126 to 129
func (p *partitionProgress) loadWatermark() uint64 {
return p.watermark
>>>>>>> 431c2afbed (kafka-consumer(ticdc): tolerate replayed resolved and DDL events (#12596))
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The loadWatermark method should use atomic.LoadUint64 to safely read the watermark value, as it is updated concurrently. Additionally, the conflict marker at line 128 must be removed.

func (p *partitionProgress) loadWatermark() uint64 {
	return atomic.LoadUint64(&p.watermark)
}

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release-8.5@1fbf1f4). Learn more about missing BASE report.

Additional details and impacted files
Components Coverage Δ
cdc 57.5979% <0.0000%> (?)
dm 48.9810% <0.0000%> (?)
engine 50.7106% <0.0000%> (?)
Flag Coverage Δ
cdc 57.5979% <ø> (?)
unit 53.4200% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

@@               Coverage Diff                @@
##             release-8.5     #12620   +/-   ##
================================================
  Coverage               ?   53.4200%           
================================================
  Files                  ?       1026           
  Lines                  ?     137924           
  Branches               ?          0           
================================================
  Hits                   ?      73679           
  Misses                 ?      58726           
  Partials               ?       5519           
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 24, 2026

@ti-chi-bot: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-check-8.5 8b75c4d link true /test pull-check-8.5
pull-cdc-integration-kafka-test 8b75c4d link true /test pull-cdc-integration-kafka-test
pull-cdc-integration-pulsar-test 8b75c4d link true /test pull-cdc-integration-pulsar-test
pull-cdc-integration-mysql-test 8b75c4d link true /test pull-cdc-integration-mysql-test
pull-cdc-integration-storage-test 8b75c4d link true /test pull-cdc-integration-storage-test

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/cherry-pick-not-approved do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants