Skip to content

sink(ticdc): retry later when meet unexpected DDL state#12483

Merged
ti-chi-bot[bot] merged 6 commits intopingcap:masterfrom
wk989898:ddl-state
Feb 3, 2026
Merged

sink(ticdc): retry later when meet unexpected DDL state#12483
ti-chi-bot[bot] merged 6 commits intopingcap:masterfrom
wk989898:ddl-state

Conversation

@wk989898
Copy link
Collaborator

@wk989898 wk989898 commented Jan 7, 2026

What problem does this PR solve?

Issue Number: close #12482

What is changed and how it works?

When meeting the unexpected DDL state, instead of immediately failing, CDC now attempts to retry the DDL. This change aims to avoid CDC restart.

Check List

Tests

  • Unit test
  • Integration test

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

Avoid CDC restart when meeting lots of slow DDL.

@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 Jan 7, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @wk989898, 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 robustness of the TiCDC DDL sink by modifying its error handling for unexpected DDL states. Instead of immediately failing, the system will now attempt to retry the operation, treating such states as transient issues. This change aims to prevent potential data inconsistencies or interruptions in DDL replication.

Highlights

  • DDL State Handling: Modified the DDL sink to retry operations when an unexpected DDL state is encountered, preventing immediate failure and improving robustness.
  • Error Wrapping: Wrapped the ErrDDLStateNotFound with mysql.ErrInvalidConn to signal that this condition should trigger a retry mechanism in the DDL sink.

🧠 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 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/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jan 7, 2026
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 modifies the DDL sink logic to retry when an unexpected DDL state is encountered. Specifically, when a DDL job is not found in the downstream TiDB after a connection error, instead of failing immediately, it now triggers a retry of the DDL execution. This is achieved by wrapping the ErrDDLStateNotFound with mysql.ErrInvalidConn to make it retryable. While this works, I've suggested a cleaner implementation for better long-term maintainability by making ErrDDLStateNotFound inherently retryable, which would make the code's intent clearer.

log.Warn("Unexpected DDL state, may not be found downstream", zap.String("ddl", ddl.Query), zap.String("ddlCreateTime", ddlCreateTime), zap.Any("ddlState", state))
return errors.ErrDDLStateNotFound.GenWithStackByArgs(state)
log.Warn("Unexpected DDL state, may not be found downstream, retry later", zap.String("ddl", ddl.Query), zap.String("ddlCreateTime", ddlCreateTime), zap.Any("ddlState", state))
return errors.WrapError(errors.ErrDDLStateNotFound, mysql.ErrInvalidConn, state)

Choose a reason for hiding this comment

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

medium

While wrapping the error with mysql.ErrInvalidConn does make it retryable by the outer retry.Do loop, this approach is a bit misleading as the underlying issue is not a connection error. This could make debugging more difficult in the future.

A cleaner approach would be to make errors.ErrDDLStateNotFound itself retryable. This could be achieved by modifying errorutil.IsRetryableDDLError to recognize errors.ErrDDLStateNotFound.

For example, in pkg/errorutil/util.go:

func IsRetryableDDLError(err error) bool {
	if errors.Is(err, cerror.ErrDDLStateNotFound) {
		return true
	}
	// ... existing code
}

This would make the intent clearer and avoid misrepresenting the error. If changing errorutil is out of scope for this PR, the current change is acceptable as a workaround, but consider refactoring this in the future.

@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 16, 2026
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jan 20, 2026
@wk989898
Copy link
Collaborator Author

/retest

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 2, 2026

[APPROVALNOTIFIER] This PR is APPROVED

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

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:
  • OWNERS [asddongmen,hongyunyan]

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 Feb 2, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 2, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-01-20 08:05:06.376863775 +0000 UTC m=+481133.990820631: ☑️ agreed by asddongmen.
  • 2026-02-02 06:22:20.531951896 +0000 UTC m=+75211.633350608: ☑️ agreed by hongyunyan.

@wk989898
Copy link
Collaborator Author

wk989898 commented Feb 3, 2026

/retest

@ti-chi-bot ti-chi-bot bot merged commit 1da8b3e into pingcap:master Feb 3, 2026
24 checks passed
@wk989898 wk989898 added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Feb 4, 2026
@ti-chi-bot
Copy link
Member

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

ti-chi-bot pushed a commit to ti-chi-bot/tiflow that referenced this pull request Feb 4, 2026
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
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-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/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CDC restart when meet unexpected DDL state

4 participants