-
Notifications
You must be signed in to change notification settings - Fork 306
cdc(ddl): ensure strict ordering for multi-table DDLs after split (#12450) #12457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
27b0f5a
3f6d012
46691be
696f185
3f71132
bd2b769
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1056,6 +1056,10 @@ type DDLEvent struct { | |
| // the DDL is executed by the primary cluster. | ||
| BDRRole string `msg:"-"` | ||
| SQLMode mysql.SQLMode `msg:"-"` | ||
| // 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"` | ||
|
Comment on lines
+1059
to
+1062
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| // FromJob fills the values with DDLEvent from DDL job | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -484,7 +484,7 @@ func (m *ddlManager) getNextDDL() *model.DDLEvent { | |
| delete(m.pendingDDLs, tb) | ||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The modification to include |
||
| res = ddls[0] | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,3 +175,33 @@ VALUES (1), | |
| UPDATE `column_is_null` | ||
| SET t = NULL | ||
| WHERE id = 1; | ||
|
|
||
| -- 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); | ||
|
Comment on lines
+179
to
+207
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,6 +86,9 @@ EOF | |
| # sync_diff can't check non-exist table, so we check expected tables are created in downstream first | ||
| check_table_exists common_1.v1 ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} | ||
| check_table_exists common_1.recover_and_insert ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} | ||
| 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} | ||
|
Comment on lines
+89
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| check_table_exists common_1.finish_mark ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} | ||
| check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assigning
event.Seq = uint64(i)within thebuildRenameEventsfunction correctly sets the order for individual DDL events originating from a multi-tableRENAMEstatement. This ensures that the original DDL order is preserved.