-
Notifications
You must be signed in to change notification settings - Fork 35
sink/mysql: align DDL time defaults with origin_default #3991
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
base: master
Are you sure you want to change the base?
sink/mysql: align DDL time defaults with origin_default #3991
Conversation
- Add StartTs field to DDLEvent struct for preserving upstream execution timestamps - Update MySQL sink to set session timestamps based on upstream StartTs/CommitTs - Add proper session timestamp management with fallback logic - Enhance error handling for timestamp-related failures - Fix timestamp drift issues for DDL statements with NOW(), CURRENT_TIMESTAMP(), etc.
When executing DDLs, check for in the table info and use it to set the session . This ensures columns with are initialized with the exact same time as the upstream.
…ault_current_timestamp
Summary of ChangesHello @haiboumich, 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 enhances the MySQL sink's DDL execution mechanism to maintain data consistency when dealing with columns that have CURRENT_TIMESTAMP-style default values. By programmatically aligning the session timestamp with the original upstream DDL execution time for such columns, it prevents discrepancies in initial data values that could arise from different application times or timezones, ensuring that the replicated schema accurately reflects the source. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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.
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 introduces a mechanism to align CURRENT_TIMESTAMP-style default values in DDLs with the upstream values by setting the session @@timestamp. The logic is well-encapsulated in pkg/sink/mysql/helper.go, and new unit tests are added to verify the behavior. The changes are well-structured and improve data consistency. My review identified a few minor logging issues where the wrong error variable was being used in error logs, which could hinder debugging.
pkg/sink/mysql/mysql_writer_ddl.go
Outdated
| zap.String("query", event.GetDDLQuery()), | ||
| zap.Error(err)) | ||
| if rbErr := tx.Rollback(); rbErr != nil { | ||
| log.Error("Failed to rollback", zap.Error(err)) |
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.
pkg/sink/mysql/mysql_writer_ddl.go
Outdated
| } | ||
| } | ||
| if rbErr := tx.Rollback(); rbErr != nil { | ||
| log.Error("Failed to rollback", zap.String("sql", event.GetDDLQuery()), zap.Error(err)) |
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.
The wrong error variable err is used here for logging. It should be rbErr to log the actual rollback error.
| log.Error("Failed to rollback", zap.String("sql", event.GetDDLQuery()), zap.Error(err)) | |
| log.Error("Failed to rollback", zap.String("sql", event.GetDDLQuery()), zap.Error(rbErr)) |
pkg/sink/mysql/mysql_writer_ddl.go
Outdated
| if err := resetSessionTimestamp(ctx, tx); err != nil { | ||
| log.Error("Failed to reset session timestamp after DDL execution", zap.Error(err)) | ||
| if rbErr := tx.Rollback(); rbErr != nil { | ||
| log.Error("Failed to rollback", zap.String("sql", event.GetDDLQuery()), zap.Error(err)) |
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.
The wrong error variable err is used here for logging. It should be rbErr to log the actual rollback error.
| log.Error("Failed to rollback", zap.String("sql", event.GetDDLQuery()), zap.Error(err)) | |
| log.Error("Failed to rollback", zap.String("sql", event.GetDDLQuery()), zap.Error(rbErr)) |
|
@Debra-He: adding LGTM is restricted to approvers and reviewers in OWNERS files. DetailsIn response to this: 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. |
|
@zier-one: adding LGTM is restricted to approvers and reviewers in OWNERS files. DetailsIn response to this: 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. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Debra-He, zier-one The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/retest-required |
|
/run-check-issue-triage-complete |
|
/retest-required |
|
@haiboumich: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. |
|
Please add unit tests and integration tests 🙏🏻 |
What problem does this PR solve?
DDL statements that add columns with CURRENT_TIMESTAMP-style defaults can produce different initial values downstream if the DDL is applied later or in a different time zone. This PR ensures TiCDC uses the upstream-evaluated default when executing those DDLs.
Issue Number: close #4007
What is changed and how it works?
origin_defaultfrom TableInfo to set session@@timestampbefore executing the DDL, then reset it.pkg/sink/mysql/helper.gofor reuse and keepmysql_writer_ddl.gofocused.Check List
Tests
Questions
Will it cause performance regression or break compatibility?
No. The change only affects DDL execution for CURRENT_TIMESTAMP-style defaults and does not alter DML paths.
Do you need to update user documentation, design documentation or monitoring documentation?
No.
Release note