Skip to content

Conversation

@ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #12450

What problem does this PR solve?

Issue Number: close #12449

What is changed and how it works?

This PR addresses an issue where split DDLs from a multi-table RENAME statement could be executed out of order downstream because they share the same CommitTs and the order of ranging map is non-deterministic.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test

Questions

Will it cause performance regression or break compatibility?

None

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

None

Release note

Fix the incorrect execution order of split DDLs generated from a multi-table DDL statement (e.g., RENAME TABLE).

@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-7.1 This PR is cherry-picked to release-7.1 from a source PR. labels Dec 10, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Dec 10, 2025

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

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Dec 10, 2025

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

ti-chi-bot bot commented Dec 10, 2025

@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 ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 10, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @ti-chi-bot, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the Change Data Capture (CDC) process where multi-table DDL operations, such as RENAME TABLE, could result in their constituent DDL events being applied in an incorrect order downstream. The core of the solution involves introducing a new sequencing mechanism (Seq field) for these split DDL events, ensuring that even when they share the same commit timestamp, their original execution order is preserved. This enhancement significantly improves the reliability and consistency of DDL replication for complex schema changes.

Highlights

  • DDL Ordering Fix: Resolved an issue where multi-table DDL statements, such as RENAME TABLE, could lead to out-of-order execution of split DDL events downstream due to shared CommitTs and non-deterministic map iteration.
  • Sequential Ordering for Split DDLs: Introduced a new Seq field in the DDLEvent struct to explicitly define the execution order for individual DDL events derived from a single multi-table DDL statement, ensuring strict sequential processing.
  • Enhanced DDL Event Building: The schemaStorage component now includes dedicated logic to build DDLEvents for multi-table DDLs, specifically RENAME TABLE and CREATE TABLES, correctly assigning the Seq field to maintain the original DDL statement's order.
  • DDL Manager Update: The ddlManager's logic for selecting the next DDL event has been updated to consider the Seq field, in addition to CommitTs, to guarantee correct ordering when multiple DDLs share the same commit timestamp.
  • Integration Test Coverage: New integration tests have been added to validate the strict ordering of RENAME TABLE DDL operations, confirming the fix works as expected in a multi-table scenario.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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 enhances DDL event handling by introducing a Seq field to DDLEvent for strict ordering of multi-table DDLs, particularly for ActionRenameTables and ActionCreateTables. The schemaStorage now builds multiple DDLEvents for these operations, assigning a sequence number to ensure correct processing when events share the same commit timestamp. The ddlManager's logic for selecting the next DDL event was updated to prioritize events based on this new Seq field after CommitTs, a change explicitly praised by the reviewer as a critical fix. An integration test was added to validate the ordering of rename table DDLs. A review comment, however, pointed out a potential side effect in BuildDDLEvents where job.Query is directly modified within a loop, suggesting the use of a local copy of the job object to prevent unintended mutations.

continue
}
if res == nil || res.CommitTs > ddls[0].CommitTs {
if res == nil || res.CommitTs > ddls[0].CommitTs || (res.CommitTs == ddls[0].CommitTs && res.Seq > ddls[0].Seq) {

Choose a reason for hiding this comment

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

high

The condition (res.CommitTs == ddls[0].CommitTs && res.Seq > ddls[0].Seq) is correctly added to ensure strict ordering of DDL events when they share the same CommitTs. This is a critical fix for multi-table DDLs to prevent out-of-order execution downstream.

multiTableInfos := job.BinlogInfo.MultipleTableInfos
for index, tableInfo := range multiTableInfos {
newTableInfo := model.WrapTableInfo(job.SchemaID, job.SchemaName, job.BinlogInfo.FinishedTS, tableInfo)
job.Query = querys[index]

Choose a reason for hiding this comment

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

medium

Modifying job.Query directly within this loop can lead to unexpected side effects if the original job object is expected to remain immutable or if job.Query is used elsewhere after this function call. It's generally safer to create a local copy of the job object for each iteration and modify the copy's Query field before passing it to event.FromJob.

For example:

// Create a copy of the job for each iteration
clonedJob := *job
clonedJob.Query = querys[index]
event.FromJob(&clonedJob, nil, newTableInfo)
clonedJob := *job
clonedJob.Query = querys[index]
event := new(model.DDLEvent)
event.FromJob(&clonedJob, nil, newTableInfo)

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Dec 10, 2025

@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-cdc-integration-kafka-test 2db70d1 link true /test pull-cdc-integration-kafka-test
pull-verify 2db70d1 link true /test pull-verify
pull-cdc-integration-mysql-test 2db70d1 link true /test pull-cdc-integration-mysql-test
pull-cdc-integration-storage-test 2db70d1 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/cherry-pick-for-release-7.1 This PR is cherry-picked to release-7.1 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants