cdc(ddl): ensure strict ordering for multi-table DDLs after split (#12450)#12457
Conversation
Summary of ChangesHello @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 resolves a critical data consistency problem in the Change Data Capture (CDC) system where DDL operations affecting multiple tables, such as Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request effectively resolves the issue of out-of-order execution for split DDLs originating from multi-table RENAME statements. The solution introduces a Seq field to the DDLEvent structure, which is then used to enforce strict ordering when multiple DDLs share the same CommitTs. The changes are implemented by assigning the sequence number during DDL event building in schema_storage.go and incorporating this Seq field into the DDL selection logic in ddl_manager.go. Additionally, the msgp serialization code has been updated, and a dedicated integration test has been added to validate the fix.
| 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) { |
There was a problem hiding this comment.
The modification to include (res.CommitTs == ddls[0].CommitTs && res.Seq > ddls[0].Seq) in the DDL selection logic is crucial. This ensures that when multiple DDLs share the same CommitTs, they are processed in the strict order defined by their Seq field, preventing out-of-order execution for multi-table DDLs.
| func (z DDLEvent) Msgsize() (s int) { | ||
| s = 1 + 9 + msgp.Uint64Size + 10 + msgp.Uint64Size + 6 + msgp.StringPrefixSize + len(z.Query) | ||
| func (z *DDLEvent) Msgsize() (s int) { | ||
| s = 1 + 9 + msgp.Uint64Size + 10 + msgp.Uint64Size + 6 + msgp.StringPrefixSize + len(z.Query) + 4 + msgp.Uint64Size |
| } | ||
| // write "query" | ||
| err = en.Append(0xa5, 0x71, 0x75, 0x65, 0x72, 0x79) | ||
| err = z.DDL.EncodeMsg(en) |
| func (z DDLEvent) EncodeMsg(en *msgp.Writer) (err error) { | ||
| // map header, size 3 | ||
| func (z *DDLEvent) EncodeMsg(en *msgp.Writer) (err error) { | ||
| // map header, size 4 |
| // write "seq" | ||
| err = en.Append(0xa3, 0x73, 0x65, 0x71) | ||
| if err != nil { | ||
| return | ||
| } | ||
| err = en.WriteUint64(z.Seq) | ||
| if err != nil { | ||
| err = msgp.WrapError(err, "Seq") | ||
| return | ||
| } |
| } | ||
| var zb0002 uint32 | ||
| zb0002, bts, err = msgp.ReadMapHeaderBytes(bts) | ||
| bts, err = z.DDL.UnmarshalMsg(bts) |
| s += msgp.NilSize | ||
| } else { | ||
| s += 1 + 9 + msgp.Uint64Size + 10 + msgp.Uint64Size + 6 + msgp.StringPrefixSize + len(z.DDL.Query) | ||
| s += z.DDL.Msgsize() |
| // Seq is used to order the DDLs with the same commit ts | ||
| // Only used in the splited DDLEvent generated by a multi-table DDL, | ||
| // we need to keep the order of the original multi-table DDL | ||
| Seq uint64 `msg:"seq"` |
| -- rename tables DDL should keep the order of events | ||
|
|
||
| CREATE TABLE `rename_t3` ( | ||
| `id` INT PRIMARY KEY, | ||
| `val` INT | ||
| ); | ||
|
|
||
| CREATE TABLE `rename_t1` ( | ||
| `id` INT PRIMARY KEY, | ||
| `val` INT | ||
| ); | ||
|
|
||
| CREATE TABLE `rename_t2` ( | ||
| `id` INT PRIMARY KEY, | ||
| `val` INT | ||
| ); | ||
|
|
||
| INSERT INTO `rename_t1` VALUES (1, 1); | ||
| INSERT INTO `rename_t2` VALUES (1, 2); | ||
| INSERT INTO `rename_t3` VALUES (1, 3); | ||
|
|
||
| RENAME TABLE | ||
| `rename_t1` TO `rename_t4`, | ||
| `rename_t2` TO `rename_t1`, | ||
| `rename_t3` TO `rename_t2`; | ||
|
|
||
| INSERT INTO `rename_t4` VALUES (2, 4); | ||
| INSERT INTO `rename_t1` VALUES (2, 1); | ||
| INSERT INTO `rename_t2` VALUES (2, 2); |
| check_table_exists common_1.rename_t4 ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} | ||
| check_table_exists common_1.rename_t1 ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} | ||
| check_table_exists common_1.rename_t2 ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} |
There was a problem hiding this comment.
Codecov Report❌ Patch coverage is Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. @@ Coverage Diff @@
## release-8.5 #12457 +/- ##
================================================
Coverage ? 55.1725%
================================================
Files ? 1003
Lines ? 136858
Branches ? 0
================================================
Hits ? 75508
Misses ? 55800
Partials ? 5550 🚀 New features to boost your workflow:
|
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wlwilliamx The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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
RENAMEstatement could be executed out of order downstream because they share the sameCommitTsand the order of ranging map is non-deterministic.Check List
Tests
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