Skip to content

table route: add the table route core functionality#4659

Open
3AceShowHand wants to merge 4 commits intopingcap:masterfrom
3AceShowHand:table-route-pr3-routing-core
Open

table route: add the table route core functionality#4659
3AceShowHand wants to merge 4 commits intopingcap:masterfrom
3AceShowHand:table-route-pr3-routing-core

Conversation

@3AceShowHand
Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Issue Number: close #xxx

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

Please refer to [Release Notes Language Style Guide](https://pingcap.github.io/tidb-dev-guide/contribute-to-tidb/release-notes-style-guide.html) to write a quality release note.

If you don't think this PR needs a release note then fill it with `None`.

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Mar 31, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Mar 31, 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 flowbehappy 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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 31, 2026

Warning

Rate limit exceeded

@3AceShowHand has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 9 minutes and 41 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 9 minutes and 41 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ca8f7023-1f6f-43f7-8005-7558e43b6329

📥 Commits

Reviewing files that changed from the base of the PR and between 8a067c4 and dd6283e.

📒 Files selected for processing (34)
  • api/v2/model.go
  • downstreamadapter/dispatcher/basic_dispatcher.go
  • downstreamadapter/dispatcher/basic_dispatcher_active_active_test.go
  • downstreamadapter/dispatcher/basic_dispatcher_info.go
  • downstreamadapter/dispatcher/event_dispatcher_test.go
  • downstreamadapter/dispatcher/redo_dispatcher_test.go
  • downstreamadapter/dispatchermanager/dispatcher_manager.go
  • downstreamadapter/dispatchermanager/dispatcher_manager_redo.go
  • downstreamadapter/dispatchermanager/dispatcher_manager_test.go
  • downstreamadapter/eventcollector/dispatcher_stat.go
  • downstreamadapter/eventcollector/dispatcher_stat_test.go
  • downstreamadapter/eventcollector/event_collector_test.go
  • downstreamadapter/routing/ddl_routing.go
  • downstreamadapter/routing/ddl_routing_test.go
  • downstreamadapter/routing/ddl_table_utils.go
  • downstreamadapter/routing/ddl_table_utils_test.go
  • downstreamadapter/routing/router.go
  • downstreamadapter/routing/router_apply_test.go
  • downstreamadapter/routing/router_test.go
  • downstreamadapter/sink/sink.go
  • pkg/common/event/ddl_event.go
  • pkg/common/event/ddl_event_test.go
  • pkg/common/event/dml_event.go
  • pkg/common/event/redo.go
  • pkg/common/event/redo_test.go
  • pkg/common/table_info.go
  • pkg/common/table_info_test.go
  • pkg/common/table_name.go
  • pkg/common/table_name_gen.go
  • pkg/config/changefeed.go
  • pkg/config/sink.go
  • pkg/config/sink_test.go
  • pkg/errors/error.go
  • tests/integration_tests/api_v2/model.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ti-chi-bot ti-chi-bot Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Mar 31, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Mar 31, 2026

@3AceShowHand: The following test 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-error-log-review dd6283e link true /test pull-error-log-review

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.

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 table routing functionality, allowing users to map source schema and table names to different target names in the downstream using configurable rules and placeholders like {schema} and {table}. The changes introduce a new routing package for name mapping and DDL query rewriting, update event structures to carry routed metadata, and ensure thread-safe handling of shared TableInfo objects through cloning. Review feedback highlights opportunities to optimize performance by reusing parser instances during DDL processing and identifies a potential issue where foreign key references are currently excluded from the routing logic.

}

// Parse the DDL query using TiDB parser
p := parser.New()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Creating a new parser instance for every DDL rewrite can be inefficient. While DDLs are relatively infrequent, it is generally better to reuse a parser instance or use a pool, as parser.New() initializes lexer and yacc state which has some overhead.

Comment on lines +38 to +40
if _, ok := in.(*ast.ReferenceDef); ok {
return in, true
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Skipping ReferenceDef nodes means that foreign key references in DDL statements (like CREATE TABLE or ALTER TABLE) will not have routing rules applied to them. If a referenced table is also being routed to a different name in the downstream, the resulting DDL might fail because it points to a non-existent source table name. Consider if foreign key references should also be matched against routing rules.

}

func extractRenameTargetExtraFromQuery(query string) (string, string) {
stmt, err := parser.New().ParseOneStmt(query, "", "")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Similar to the routing logic, creating a new parser here for every split rename query adds unnecessary overhead. Consider reusing a parser instance.

@3AceShowHand 3AceShowHand changed the title add the table route core table route: add the table route core functionality Mar 31, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Mar 31, 2026

[FORMAT CHECKER NOTIFICATION]

Notice: To remove the do-not-merge/needs-linked-issue label, please provide the linked issue number on one line in the PR body, for example: Issue Number: close #123 or Issue Number: ref #456.

📖 For more info, you can check the "Contribute Code" section in the development guide.

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

Labels

do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant