Skip to content

active-active: Fix tableInfo compatibility checks when enable-active-active is true#4181

Merged
ti-chi-bot[bot] merged 7 commits into
pingcap:masterfrom
hongyunyan:0209
Feb 11, 2026
Merged

active-active: Fix tableInfo compatibility checks when enable-active-active is true#4181
ti-chi-bot[bot] merged 7 commits into
pingcap:masterfrom
hongyunyan:0209

Conversation

@hongyunyan
Copy link
Copy Markdown
Collaborator

@hongyunyan hongyunyan commented Feb 10, 2026

What problem does this PR solve?

Issue Number: close #3446

What is changed and how it works?

This pull request refines the schema compatibility checking mechanism within the BasicDispatcher for active-active replication. It changes how DDL events interact with the tableModeCompatibilityChecked flag, ensuring that schema compatibility is re-evaluated for DML events following any schema alterations. This prevents misconfigurations by guaranteeing that the most current table schema is always validated against the replication mode.

Highlights

  • Refactored Schema Compatibility Check Logic: The mechanism for validating table schema compatibility with the replication mode has been refined, particularly for DDL events.
  • DDL Event Handling Update: DDL events now reset the tableModeCompatibilityChecked flag to false instead of directly performing the compatibility check. This ensures that the schema is re-evaluated on the subsequent DML event.
  • Simplified checkTableModeCompatibility: The checkTableModeCompatibility function has been simplified to primarily handle DML events, as DDL events no longer directly invoke it for validation.
  • Enhanced Test Coverage: A test case was updated to validate the new behavior where DDL events reset the compatibility flag, and subsequent DML events trigger the actual schema compatibility check.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Questions

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

Release note

Please refer to [Release Notes Language Style Guide](https://pingcap.github.io/tidb-dev-guide/contribute-to-tidb/release-notes-style-guide.html) to write a quality release note.

If you don't think this PR needs a release note then fill it with `None`.

Summary by CodeRabbit

  • Refactor

    • Improved internal handling of table-schema compatibility so replication re-validates appropriately after schema-change events, reducing incorrect assumptions and improving reliability during schema updates.
  • Tests

    • Enhanced tests to cover compatibility behavior across schema-change events, ensuring the dispatcher resets and re-checks compatibility as expected.
  • Chore

    • No public API changes.

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 10, 2026
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @hongyunyan, 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 refines the schema compatibility checking mechanism within the BasicDispatcher for active-active replication. It changes how DDL events interact with the tableModeCompatibilityChecked flag, ensuring that schema compatibility is re-evaluated for DML events following any schema alterations. This prevents misconfigurations by guaranteeing that the most current table schema is always validated against the replication mode.

Highlights

  • Refactored Schema Compatibility Check Logic: The mechanism for validating table schema compatibility with the replication mode has been refined, particularly for DDL events.
  • DDL Event Handling Update: DDL events now reset the tableModeCompatibilityChecked flag to false instead of directly performing the compatibility check. This ensures that the schema is re-evaluated on the subsequent DML event.
  • Simplified checkTableModeCompatibility: The checkTableModeCompatibility function has been simplified to primarily handle DML events, as DDL events no longer directly invoke it for validation.
  • Enhanced Test Coverage: A test case was updated to validate the new behavior where DDL events reset the compatibility flag, and subsequent DML events trigger the actual schema compatibility check.

🧠 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.

Changelog
  • downstreamadapter/dispatcher/basic_dispatcher.go
    • Updated logic for tableModeCompatibilityChecked to reset on DDL events.
    • Simplified checkTableModeCompatibility to focus on DML events.
    • Revised comments for clarity on compatibility checking.
  • downstreamadapter/dispatcher/basic_dispatcher_active_active_test.go
    • Enhanced test case TestDDLEventsAlwaysValidateActiveActive to verify DDL event handling and subsequent DML compatibility checks.
Activity
  • No specific activity has been recorded for this pull request yet.
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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

Table-mode compatibility checking in the dispatcher is tightened: compatibility is reset when a DDL event is processed and re-checked on subsequent DMLs or initial processing. checkTableModeCompatibility now only validates DML events; DDL handling simply clears the compatibility flag.

Changes

Cohort / File(s) Summary
Dispatcher core
downstreamadapter/dispatcher/basic_dispatcher.go
Refined semantics of tableModeCompatibilityChecked: reset to false on DDL processing; checkTableModeCompatibility narrowed to handle only DMLEvent (logs error on unexpected types). DDL handling no longer calls the check and instead invalidates prior compatibility assumptions.
Tests
downstreamadapter/dispatcher/basic_dispatcher_active_active_test.go
Replaced direct TableInfo construction with DDL-derived TableInfo via test helper (NewEventTestHelper / DDL2Event); added assertion that tableModeCompatibilityChecked is false after handling a DDL event; continued flow with a subsequent DMLEvent.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • wk989898
  • bufferflies
  • lidezhu
  • flowbehappy

Poem

🐰 I nibble through DDL lines bright,

I reset my flag and keep things right,
When tables change, I hop and see,
Then re-check rows with careful glee. ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The pull request description includes a valid issue reference, detailed explanation of changes, highlights section, and properly filled checklist and questions sections. However, the Release note section is incomplete with only placeholder guidance text and no actual release note content. Provide an actual release note following the Release Notes Language Style Guide, or explicitly state 'None' if no release note is needed. Currently only placeholder text is present.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing tableInfo compatibility checks in active-active mode. It is specific and directly related to the core modifications in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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 refactors the logic for checking table schema compatibility with the replication mode, deferring checks from DDL events to subsequent DML events, and updates associated tests. However, a security audit identified two medium-severity issues in the BasicDispatcher compatibility checking logic: an unsafe type assertion that could lead to panics (Denial of Service) and a logic flaw allowing security checks to be bypassed after an initial failure. Additionally, there's a regression where DDL events are no longer validated for compatibility, potentially compromising data integrity in specialized replication modes. It is suggested to improve the robustness of the checkTableModeCompatibility function by using a type switch instead of a direct type assertion to mitigate these risks.

}
return nil

return d.ensureTableModeCompatibility(event.(*commonEvent.DMLEvent).TableInfo)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-medium medium

The checkTableModeCompatibility method uses a direct type assertion event.(*commonEvent.DMLEvent) which is a regression and introduces a potential panic (Denial of Service) if called with a non-DML event. This unsafe assertion, combined with a defer block that sets tableModeCompatibilityChecked = true even on failure, creates a logic flaw allowing subsequent events to bypass security/integrity checks. This could lead to data inconsistency in active-active or soft-delete replication modes. It is recommended to use a type switch to safely handle event types and only set tableModeCompatibilityChecked = true if ensureTableModeCompatibility returns no error.

Suggested change
return d.ensureTableModeCompatibility(event.(*commonEvent.DMLEvent).TableInfo)
switch ev := event.(type) {
case *commonEvent.DMLEvent:
return d.ensureTableModeCompatibility(ev.TableInfo)
default:
log.Panic("checkTableModeCompatibility received unexpected event type", zap.Any("event", event))
return nil // Should be unreachable
}

// reset the tableModeCompatibilityChecked when receive a ddl event,
// because ddl event may change the table schema,
// which may cause the table not compatible with current replication mode anymore.
d.tableModeCompatibilityChecked = false
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-medium medium

The compatibility check for DDL events has been removed and replaced with a simple reset of the tableModeCompatibilityChecked flag. This change allows incompatible DDL queries (e.g., those dropping required columns for active-active mode) to be applied to the downstream database before any validation occurs. The check is now delayed until the next DML event arrives, which violates the principle of failing securely. Incompatible schema changes should be blocked before they are applied to prevent downstream corruption or replication loops.

Recommendation: Re-introduce the compatibility check for DDL events before they are applied to the downstream sink via DealWithBlockEvent.

@hongyunyan hongyunyan changed the title wip-active-active active-active: Fix tableInfo compatibility checks when enable-active-active is true Feb 10, 2026
@ti-chi-bot ti-chi-bot Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 10, 2026
@ti-chi-bot ti-chi-bot Bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Feb 10, 2026
@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 10, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Feb 10, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-02-10 08:02:36.076404832 +0000 UTC m=+258371.770544682: ☑️ agreed by wk989898.
  • 2026-02-10 09:26:05.789977335 +0000 UTC m=+263381.484117185: ☑️ agreed by lidezhu.

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Feb 11, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flowbehappy, lidezhu, wk989898

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 [flowbehappy,lidezhu,wk989898]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hongyunyan
Copy link
Copy Markdown
Collaborator Author

/retest

@ti-chi-bot ti-chi-bot Bot merged commit f29125e into pingcap:master Feb 11, 2026
29 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm 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.

Support Active Active Mode

4 participants