ticdc: MySQL sink dispatcher routing
What problem does this PR solve?
Issue Number: close #12434
What is changed and how it works?
- Extended the
dispatchersfield (currently used for mq sinks https://docs.pingcap.com/tidb/stable/ticdc-sink-to-kafka/#topic-dispatchers) to support schema/table routing for mysql sinks. The config looks like this:
[[sink.dispatchers]]
matcher = ["source_db1.*"]
schema = "dest_db1"
table = "{table}"
[[sink.dispatchers]]
matcher = ["source_db2.*"]
schema = "source_db2"
table = "{table}"
- The
Dispatcherinterface routes the givensourceSchema, sourceTabletotargetSchema, targetTable.SinkRouterwraps the dispatchers - Added
TargetSchemaandTargetTablefields toTableNamestruct in cdc/model/sink.go, which are populated when the sink router is defined. This is handled in 2 ways - for tables that already exist when the changefeed is created/started, the fields are added to the existing snapshot of the schema. For tables that are created later, the fields are added to the new table before the new snapshot is saved - Use
TargetSchemaandTargetTablefor the USE statement inmysql_ddl_sink.go, and in new methodQuoteSinkString()which is called to construct mysql DMLs inpkg/sqlmodel/multirow.goandpkg/sqlmodel/row_change.go - Use
FetchDDLTablesandRenameDDLTablefrom the dm parser pkg to rewrite DDLs after they are constructed if the schema router is specified.FetchDDLTablesreturns all of the tables referenced in the DDL in the order that they appear in the DDL. We then use the schema router to map each source schema to its target schema and pass this list of tables toRenameDDLTable
Check List
Tests
- Unit test
- Manual test - tested in our local development environment
Questions
Will it cause performance regression or break compatibility?
No, the additional latency for DDL rewrites should be minimal compared to barrier ts, and there should not be compatibility issues since this is a new feature
Do you need to update user documentation, design documentation or monitoring documentation?
Yes, this is a new feature for mysql sinks, will need to update https://docs.pingcap.com/tidb/stable/ticdc-sink-to-mysql/
Release note
Support schema and table routing for mysql-compatible sinks by extending the dispatchers config
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.
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.
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:
- It must be approved by the approvers firstly.
- AFTER it has been approved by approvers, please wait for the cherry-pick merging approval from triage owners.
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.
Hi @a-cong. Thanks for your PR.
I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.
Once the patch is verified, the new status will be reflected by the ok-to-test label.
I understand the commands that are listed here.
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.
Welcome @a-cong!
It looks like this is your first PR to pingcap/tiflow 🎉.
I'm the bot to help you request reviewers, add labels and more, See available commands.
We want to make sure your contribution gets all the attention it needs!
Thank you, and welcome to pingcap/tiflow. :smiley:
Could you provide a case to demonstrate this feature? It's better to add an integration test to cover it.
/ok-to-test
Codecov Report
:x: Patch coverage is 64.51613% with 132 lines in your changes missing coverage. Please review.
:warning: Please upload report for BASE (release-8.5@df4a904). Learn more about missing BASE report.
Additional details and impacted files
| Components | Coverage Δ | |
|---|---|---|
| cdc | 57.8408% <0.0000%> (?) |
|
| dm | 48.6677% <0.0000%> (?) |
|
| engine | 50.6998% <0.0000%> (?) |
| Flag | Coverage Δ | |
|---|---|---|
| unit | 53.4418% <64.5161%> (?) |
Flags with carried forward coverage won't be shown. Click here to find out more.
@@ Coverage Diff @@
## release-8.5 #12435 +/- ##
================================================
Coverage ? 53.4418%
================================================
Files ? 1006
Lines ? 137310
Branches ? 0
================================================
Hits ? 73381
Misses ? 58461
Partials ? 5468
:rocket: New features to boost your workflow:
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Could you provide a case to demonstrate this feature? It's better to add an integration test to cover it.
I added an integration test in sink_routing, please take a look. I fixed the rest of the tests but pull-dm-integration-test is still failing with a mysql connection error and I'm not sure why - is it related to my changes?
/retest
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: 3AceShowHand Once this PR has been reviewed and has the lgtm label, please assign benmeadowcroft 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.
- ~~OWNERS~~ [3AceShowHand]
- cdc/api/v2/OWNERS
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
[LGTM Timeline notifier]
Timeline:
2025-12-15 13:57:23.304563268 +0000 UTC m=+1481388.118340840: :ballot_box_with_check: agreed by 3AceShowHand.
/retest
/retest
/retest
/test all