Skip to content

Fix ddl barrier backlog#4881

Draft
haiboumich wants to merge 5 commits intopingcap:masterfrom
haiboumich:fix-ddl-barrier-backlog
Draft

Fix ddl barrier backlog#4881
haiboumich wants to merge 5 commits intopingcap:masterfrom
haiboumich:fix-ddl-barrier-backlog

Conversation

@haiboumich
Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #xxx

What is changed and how it works?

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

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Apr 21, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@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. labels Apr 21, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Apr 21, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign asddongmen for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found 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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

Important

Review skipped

Draft detected.

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

Run ID: be4c4344-383d-4744-a8b3-71afee8fc132

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 and usage tips.

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 21, 2026
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 improves the handling of handshake events to unblock idle tables and optimizes barrier tracking in the maintainer to prevent memory growth during DDL-heavy workloads by waiting for the DDL dispatcher's report. The feedback identifies an issue where the deferredStatus flag is incorrectly placed, potentially leading to spurious warning logs. Additionally, it is suggested to expand the barrier deferral logic to include InfluenceType_All (syncpoints) to further mitigate memory growth issues and to update log messages accordingly.

Comment thread maintainer/barrier.go
Comment on lines 124 to +128
if event == nil {
if !needACK {
deferredStatus = true
continue
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The deferredStatus flag is currently only set when event == nil. However, handleOneStatus can return a non-nil event with needACK == false (for example, in handleBlockState at lines 432 and 466 when an event is deferred due to pending schedule events or scheduling not being ready). In these cases, deferredStatus remains false, which will trigger a spurious "no dispatcher status to send" warning log at line 156 if no other statuses are processed in the request.

Consider setting deferredStatus = true and continuing the loop whenever needACK is false to correctly handle all deferred status paths.

Suggested change
if event == nil {
if !needACK {
deferredStatus = true
continue
}
if !needACK {
deferredStatus = true
continue
}
if event == nil {

Comment thread maintainer/barrier.go
Comment on lines +379 to +380
normalBlockEventIncludesDDLSpan(blockState.BlockTables) {
log.Debug("wait ddl dispatcher report before tracking normal block event",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

If the helper function is updated to include InfluenceType_All (syncpoints), the log message and function call should be updated to reflect that it now covers more than just 'normal' block events.

Suggested change
normalBlockEventIncludesDDLSpan(blockState.BlockTables) {
log.Debug("wait ddl dispatcher report before tracking normal block event",
blockEventIncludesDDLSpan(blockState.BlockTables) {
log.Debug("wait ddl dispatcher report before tracking block event",

Comment thread maintainer/barrier.go
Comment on lines +472 to +482
func normalBlockEventIncludesDDLSpan(blockedTables *heartbeatpb.InfluencedTables) bool {
if blockedTables == nil || blockedTables.InfluenceType != heartbeatpb.InfluenceType_Normal {
return false
}
for _, tableID := range blockedTables.TableIDs {
if tableID == common.DDLSpanTableID {
return true
}
}
return 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.

medium

The current implementation only defers InfluenceType_Normal events that include the DDL span. However, InfluenceType_All events (such as syncpoints) also conceptually include the DDL span and are coordinated by the DDL dispatcher. If there is a large backlog of syncpoints, table dispatchers reporting them before the DDL dispatcher will still create BarrierEvent objects, which could lead to the memory growth issue this PR aims to address.

Consider renaming this function to blockEventIncludesDDLSpan and including InfluenceType_All in the check.

func blockEventIncludesDDLSpan(blockedTables *heartbeatpb.InfluencedTables) bool {
	if blockedTables == nil {
		return false
	}
	if blockedTables.InfluenceType == heartbeatpb.InfluenceType_All {
		return true
	}
	if blockedTables.InfluenceType != heartbeatpb.InfluenceType_Normal {
		return false
	}
	for _, tableID := range blockedTables.TableIDs {
		if tableID == common.DDLSpanTableID {
			return true
		}
	}
	return false
}

@ti-chi-bot ti-chi-bot Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 21, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Apr 21, 2026

[FORMAT CHECKER NOTIFICATION]

Notice: To remove the do-not-merge/needs-linked-issue label, please provide the linked issue number on one line in the PR body, for example: Issue Number: close #123 or Issue Number: ref #456.

📖 For more info, you can check the "Contribute Code" section in the development guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/needs-linked-issue do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant