Skip to content

Conversation

@wlwilliamx
Copy link
Contributor

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 bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Dec 7, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @wlwilliamx, 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 resolves a critical issue where multi-table DDL statements, such as RENAME, could lead to out-of-order execution of their constituent DDL events downstream. This problem stemmed from these split DDLs sharing the same commit timestamp and being processed non-deterministically. The solution introduces a sequence number for these events, ensuring that the original logical order of the multi-table DDL is preserved during replication, thereby enhancing data consistency and reliability in the CDC pipeline.

Highlights

  • Strict DDL Ordering: Introduced a new Seq (sequence) field to DDLEvent to ensure strict ordering for split DDLs originating from a single multi-table DDL statement (e.g., RENAME TABLE) that share the same CommitTs.
  • Sequence Assignment: The Seq field is populated during the buildRenameEvents process in schema_storage.go, assigning an incremental sequence number to each individual DDL event generated from a multi-table DDL.
  • DDL Manager Logic Update: The ddlManager's getNextDDL function was updated to consider both CommitTs and the new Seq field when determining the next DDL to execute, guaranteeing correct order even when commit timestamps are identical.
  • Serialization Updates: MessagePack (msgp) serialization and deserialization logic for DDLEvent and RedoDDLEvent was updated to properly handle the new Seq field, ensuring it is correctly transmitted and parsed.
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.

@ti-chi-bot ti-chi-bot bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 7, 2025
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 effectively addresses the issue of potential out-of-order execution for DDLs split from multi-table statements. By introducing a Seq field to DDLEvent, you've provided a mechanism to enforce a strict ordering for DDLs that share the same commit timestamp. The implementation across schema_storage, ddl_manager, and the model files is clean and correct. I particularly appreciate the refactoring in cdc/model/sink_gen.go which improves code reuse and maintainability for serialization logic. I have one comment regarding the manual edits in the generated file.

Comment on lines +904 to 908
err = z.DDL.DecodeMsg(dc)
if err != nil {
err = msgp.WrapError(err, "DDL")
return
}

Choose a reason for hiding this comment

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

high

These changes, which refactor the serialization logic for DDLEvent within RedoDDLEvent and change method receivers to pointers, are great improvements for maintainability and performance. However, since this is a generated file (as indicated by the DO NOT EDIT header), these manual changes might be lost the next time go generate is run. If the file is regenerated without these manual changes, the Seq field will not be correctly serialized for RedoDDLEvent, which could break the ordering guarantee this PR aims to provide when using redo logs. This is a potential correctness issue. Could you explore ways to make these changes permanent, perhaps by configuring the msgp generator, or add a prominent comment to the file to prevent accidental overwrites by the generator in the future?

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Dec 7, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Dec 8, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: asddongmen, lidezhu

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

The pull request process is described 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 ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 8, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Dec 8, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-12-07 11:40:09.946992314 +0000 UTC m=+781954.760769886: ☑️ agreed by asddongmen.
  • 2025-12-08 07:09:26.802272727 +0000 UTC m=+852111.616050299: ☑️ agreed by lidezhu.

@ti-chi-bot ti-chi-bot bot added needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. labels Dec 8, 2025
@wlwilliamx
Copy link
Contributor Author

/retest

@ti-chi-bot ti-chi-bot bot merged commit 3c7fd0a into pingcap:master Dec 10, 2025
24 checks passed
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #12456.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #12457.

ti-chi-bot pushed a commit to ti-chi-bot/tiflow that referenced this pull request Dec 10, 2025
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #12458.
But this PR has conflicts, please resolve them!

ti-chi-bot pushed a commit to ti-chi-bot/tiflow that referenced this pull request Dec 10, 2025
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #12459.
But this PR has conflicts, please resolve them!

ti-chi-bot pushed a commit to ti-chi-bot/tiflow that referenced this pull request Dec 10, 2025
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #12460.
But this PR has conflicts, please resolve them!

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

Labels

approved lgtm needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix incorrect execution order for multi-table RENAME TABLE DDLs

4 participants