tiflow icon indicating copy to clipboard operation
tiflow copied to clipboard

ticdc: MySQL sink dispatcher routing

Open a-cong opened this issue 3 weeks ago • 11 comments

What problem does this PR solve?

Issue Number: close #12434

What is changed and how it works?

  • Extended the dispatchers field (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 Dispatcher interface routes the given sourceSchema, sourceTable to targetSchema, targetTable. SinkRouter wraps the dispatchers
  • Added TargetSchema and TargetTable fields to TableName struct 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 TargetSchema and TargetTable for the USE statement in mysql_ddl_sink.go, and in new method QuoteSinkString() which is called to construct mysql DMLs in pkg/sqlmodel/multirow.go and pkg/sqlmodel/row_change.go
  • Use FetchDDLTables and RenameDDLTable from the dm parser pkg to rewrite DDLs after they are constructed if the schema router is specified. FetchDDLTables returns 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 to RenameDDLTable

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

a-cong avatar Dec 03 '25 16:12 a-cong

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.

ti-chi-bot[bot] avatar Dec 03 '25 16:12 ti-chi-bot[bot]

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 approved by the approvers firstly.
  2. 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.

ti-chi-bot[bot] avatar Dec 03 '25 16:12 ti-chi-bot[bot]

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.

ti-chi-bot[bot] avatar Dec 03 '25 16:12 ti-chi-bot[bot]

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:

ti-chi-bot[bot] avatar Dec 03 '25 16:12 ti-chi-bot[bot]

CLA assistant check
All committers have signed the CLA.

Could you provide a case to demonstrate this feature? It's better to add an integration test to cover it.

wk989898 avatar Dec 11 '25 06:12 wk989898

/ok-to-test

wk989898 avatar Dec 11 '25 09:12 wk989898

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.

codecov[bot] avatar Dec 11 '25 19:12 codecov[bot]

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?

a-cong avatar Dec 12 '25 02:12 a-cong

/retest

3AceShowHand avatar Dec 15 '25 11:12 3AceShowHand

[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.

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

ti-chi-bot[bot] avatar Dec 15 '25 13:12 ti-chi-bot[bot]

[LGTM Timeline notifier]

Timeline:

  • 2025-12-15 13:57:23.304563268 +0000 UTC m=+1481388.118340840: :ballot_box_with_check: agreed by 3AceShowHand.

ti-chi-bot[bot] avatar Dec 15 '25 13:12 ti-chi-bot[bot]

/retest

a-cong avatar Dec 17 '25 01:12 a-cong

/retest

a-cong avatar Dec 17 '25 18:12 a-cong

/retest

a-cong avatar Dec 19 '25 19:12 a-cong

/test all

wk989898 avatar Dec 21 '25 11:12 wk989898