Skip to content

eventservice: improve dml processing efficiency #5473

Draft
asddongmen wants to merge 3 commits into
pingcap:masterfrom
asddongmen:0617-improve-eventBroker
Draft

eventservice: improve dml processing efficiency #5473
asddongmen wants to merge 3 commits into
pingcap:masterfrom
asddongmen:0617-improve-eventBroker

Conversation

@asddongmen

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Issue Number: close #xxx

What is changed and how it works?

Check List

Tests

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

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

ti-chi-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

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 Jun 22, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

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

@ti-chi-bot

ti-chi-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

[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 wk989898 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

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

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: f52f5d04-1c04-4150-a9bc-014a0a91d8ba

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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 22, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

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 parallel decoding of DML events in the eventScanner and dmlProcessor to improve performance, along with a fast-path cache (dmlTypeFilterCache) to skip decoding for ignored event types early. The review feedback highlights a critical bug where the dmlTypeFilterCache array size of 3 is too small to cache delete events (index 3), causing the cache to be bypassed. Additionally, the reviewer suggested optimizing sequential execution by conditionally bypassing the buffering and cloning of raw KV entries when parallel decoding is disabled.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

dispatcher.info.EnableIgnoreUpdateOnlyColumns(),
withDMLProcessorMounterFactory(s.newMounter),
withDMLProcessorParallelDecodeWorkers(s.parallelDecodeWorkers))
txnRows := make([]*common.RawKVEntry, 0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Define a boolean flag enableParallel to check if parallel decoding is actually enabled and possible. This allows us to conditionally bypass buffering and cloning for sequential runs, avoiding unnecessary allocations and CPU overhead.

Suggested change
txnRows := make([]*common.RawKVEntry, 0)
enableParallel := s.parallelDecodeWorkers > 1 && s.newMounter != nil && !dispatcher.info.IsOutputRawChangeEvent()
txnRows := make([]*common.RawKVEntry, 0)

zap.Int64("mode", s.mode))
return false, err
}
txnRows = append(txnRows, cloneRawKVEntry(rawEvent))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

If parallel decoding is enabled, buffer and clone the raw KV entry. Otherwise, directly append the row sequentially to avoid the memory allocation and CPU overhead of cloning.

		if enableParallel {
			txnRows = append(txnRows, cloneRawKVEntry(rawEvent))
		} else {
			if err = processor.appendRow(rawEvent); err != nil {
				log.Error("append row failed", zap.Error(err),
					zap.Stringer("dispatcherID", session.dispatcherStat.id),
					zap.Int64("tableID", tableID),
					zap.Uint64("startTs", rawEvent.StartTs),
					zap.Uint64("commitTs", rawEvent.CRTs),
					zap.Int64("mode", s.mode))
				return false, err
			}
		}

Comment on lines +830 to +833
dmlTypeFilterCache [3]struct {
valid bool
ignore bool
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The dmlTypeFilterCache array size of 3 is too small to cache RowTypeDelete events. In TiCDC, common.RowType is defined as:

const (
	RowTypeUnknown RowType = iota
	RowTypeInsert
	RowTypeUpdate
	RowTypeDelete
)

This means RowTypeDelete has an integer value of 3. Since the array size is 3, any attempt to cache or retrieve a delete event will result in an out-of-bounds index (idx >= 3), causing the cache to be completely bypassed for all delete events. Increasing the array size to 4 fixes this issue and ensures delete events are cached correctly.

Suggested change
dmlTypeFilterCache [3]struct {
valid bool
ignore bool
}
dmlTypeFilterCache [4]struct {
valid bool
ignore bool
}

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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant