Skip to content

sink/mysql: split DML and control DB pools (#5397) - #5763

Merged
ti-chi-bot[bot] merged 2 commits into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-5397-to-release-8.5
Jul 28, 2026
Merged

sink/mysql: split DML and control DB pools (#5397)#5763
ti-chi-bot[bot] merged 2 commits into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-5397-to-release-8.5

Conversation

@ti-chi-bot

Copy link
Copy Markdown
Member

This is an automated cherry-pick of #5397

What problem does this PR solve?

Issue Number: close #5360

The MySQL sink used one shared *sql.DB pool for DML writers and control-plane work such as DDL execution, DDL-ts metadata, syncpoint metadata, and active-active progress updates. When a DML writer held the only available connection, control-plane operations could block while waiting for a connection. In the reported failure, the DDL was received and dispatched but did not reach downstream because the DDL path could not acquire a connection from the shared pool.

What is changed and how it works?

This PR splits the MySQL sink connection usage into two independent bounded pools created from the same effective DSN:

  • The DML pool is used by DML writers, DML sessions, prepared statement cache use, and active-active sync stats session queries.
  • The control pool is used by the DDL writer, DDL-ts metadata, syncpoint metadata, active-active progress table updates, DDL status queries, and metadata bootstrap.
  • The existing NewMysqlConfigAndDB single-pool API is preserved for existing callers.
  • A new NewMysqlConfigAndDBs helper creates the sink-specific DML/control pools and closes the DML pool if control pool creation fails.
  • MySQLSinkForceSingleConnection now only constrains the DML pool, so the stress path can still simulate DML session starvation without starving DDL/control operations.
  • Sink.Close closes both pools and avoids double-closing when tests pass the same DB for both.

The control pool is bounded to 4 open and idle connections.

Check List

Tests

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

Commands:

  • make fmt
  • go test --tags=intest ./pkg/sink/mysql ./downstreamadapter/sink/mysql

Not run:

  • make integration_test_mysql CASE=ddl_default_current_timestamp, because make check_third_party_binary fails in this worktree: the required third-party binaries under bin/ are not present.

Questions

Will it cause performance regression or break compatibility?

No compatibility break is expected. Existing single-pool factory callers keep the same API. The MySQL sink now opens a small additional control pool, which should reduce DDL/control starvation risk. The DML pool keeps one extra connection for prepared-statement cache misses instead of reserving the historical broader control-plane margin.

Do you need to update user documentation, design documentation or monitoring documentation?

No.

Release note

Fix a MySQL sink hang where DDL and metadata operations could be blocked by DML sessions when the shared downstream connection pool was exhausted.

Summary by CodeRabbit

  • Improvements

    • Enhanced the MySQL sink to use separate long-lived database connections for data changes versus control-plane tasks (DDL and metadata), reducing contention and improving parallelism.
    • Added configurable connection pool sizing for each path and improved verification to validate both connections.
  • Tests

    • Added integration-style coverage to confirm DDL/control-plane operations run on the control connection while batched DML runs on the dedicated DML connection.
    • Added a unit test to verify control connection pooling configuration behavior.

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR. labels Jul 27, 2026
@ti-chi-bot

Copy link
Copy Markdown
Member Author

@hongyunyan This PR has conflicts, I have hold it.
Please resolve them or ask others to resolve them, then comment /unhold to remove the hold label.

@ti-chi-bot

ti-chi-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

@ti-chi-bot: ## If you want to know how to resolve it, please read the guide in TiDB Dev Guide.

Details

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 ti-community-infra/tichi repository.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 059ccf1b-e7f7-4819-af91-3cc18f3a7497

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@hongyunyan

Copy link
Copy Markdown
Collaborator

/unhold

@ti-chi-bot ti-chi-bot Bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 27, 2026
@ti-chi-bot

Copy link
Copy Markdown
Member Author

Cherry-pick conflicts appear resolved; removing the do-not-merge/hold label.

@ti-chi-bot

ti-chi-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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:

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 approved cherry-pick-approved Cherry pick PR approved by release team. and removed do-not-merge/cherry-pick-not-approved labels Jul 28, 2026
@ti-chi-bot
ti-chi-bot Bot merged commit c9b6f5c into pingcap:release-8.5 Jul 28, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved cherry-pick-approved Cherry pick PR approved by release team. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants