Skip to content

consumer: use dml message instead of dml event#5590

Draft
wk989898 wants to merge 5 commits into
pingcap:masterfrom
wk989898:consumer-0706
Draft

consumer: use dml message instead of dml event#5590
wk989898 wants to merge 5 commits into
pingcap:masterfrom
wk989898:consumer-0706

Conversation

@wk989898

@wk989898 wk989898 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Issue Number: close #5587

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

wk989898 added 2 commits July 6, 2026 06:31
Signed-off-by: wk989898 <nhsmwk@gmail.com>
Signed-off-by: wk989898 <nhsmwk@gmail.com>
@ti-chi-bot ti-chi-bot Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/needs-triage-completed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jul 6, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 6, 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 commented Jul 6, 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 flowbehappy 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 Jul 6, 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: 3fe66a25-2b67-4514-8b02-defaa9cdce35

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.

@ti-chi-bot ti-chi-bot Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 6, 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 refactors the consumer and codec components to use a deferred DMLMessage abstraction instead of assembling DMLEvent objects immediately, which optimizes memory usage and performance. Additionally, the Canal-JSON decoder is updated to track DDL commit timestamps for more accurate table schema caching across column changes. The code review feedback suggests several defensive programming enhancements to prevent potential nil pointer dereferences and nil map panics, specifically by checking for nil messages in consumer.go and event_group.go, and ensuring the ddlCommitTs map is properly initialized and checked in canal_json_decoder.go.

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.

Comment thread cmd/storage-consumer/consumer.go Outdated
Comment on lines +354 to +356
row := decoder.NextDMLMessage().ToDMLEvent()
row.PhysicalTableID = tableID
c.appendRow2Group(row, fileIdx.EnableTableAcrossNodes)
c.appendMessage2Group(common.NewDMLMessageFromEvent(row), fileIdx.EnableTableAcrossNodes)

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

For defensive programming, we should check if decoder.NextDMLMessage() is nil before calling .ToDMLEvent() to avoid any potential nil pointer dereference panic.

			dmlMsg := decoder.NextDMLMessage()
			if dmlMsg == nil {
				log.Panic("DML message is nil, it's not expected")
			}
			row := dmlMsg.ToDMLEvent()
			row.PhysicalTableID = tableID
			c.appendMessage2Group(common.NewDMLMessageFromEvent(row), fileIdx.EnableTableAcrossNodes)
References
  1. Defensive programming: always check for nil pointers before dereferencing or calling methods on objects that can be nil.

Comment on lines +594 to +597
func (d *decoder) addDDLCommitTs(schema, table string, commitTs uint64) {
if schema == "" || table == "" || commitTs == 0 {
return
}

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 d.ddlCommitTs is not initialized (e.g., if the decoder is created manually in tests or other packages without calling NewDecoder), calling d.ddlCommitTs[key] will panic. We should defensively initialize it if it is nil.

func (d *decoder) addDDLCommitTs(schema, table string, commitTs uint64) {
	if schema == "" || table == "" || commitTs == 0 {
		return
	}
	if d.ddlCommitTs == nil {
		d.ddlCommitTs = make(map[tableNameKey][]uint64)
	}

	key := tableNameKey{schema: schema, table: table}
References
  1. Defensive programming: ensure maps are initialized before writing to them to avoid nil map panics.

Comment on lines +610 to +615
func (d *decoder) getDDLCommitTs(schema, table string, commitTs uint64) uint64 {
if commitTs == 0 {
return 0
}

commitTsList := d.ddlCommitTs[tableNameKey{schema: schema, table: table}]

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 d.ddlCommitTs is nil, accessing it will panic. We should defensively check if d.ddlCommitTs is nil before querying it.

Suggested change
func (d *decoder) getDDLCommitTs(schema, table string, commitTs uint64) uint64 {
if commitTs == 0 {
return 0
}
commitTsList := d.ddlCommitTs[tableNameKey{schema: schema, table: table}]
func (d *decoder) getDDLCommitTs(schema, table string, commitTs uint64) uint64 {
if commitTs == 0 || d.ddlCommitTs == nil {
return 0
}
commitTsList := d.ddlCommitTs[tableNameKey{schema: schema, table: table}]
References
  1. Defensive programming: check for nil maps before reading from them to avoid nil pointer panics.

Comment thread cmd/util/event_group.go
Comment on lines +107 to +113
func AppendOrMergeDMLEvent(events []*commonEvent.DMLEvent, row *commonEvent.DMLEvent) []*commonEvent.DMLEvent {
var lastDMLEvent *commonEvent.DMLEvent
if len(events) > 0 {
lastDMLEvent = events[len(events)-1]
}

if lastDMLEvent == nil || lastDMLEvent.GetCommitTs() < row.GetCommitTs() {

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 row is nil, calling row.GetCommitTs() will panic with a nil pointer dereference. We should defensively check if row is nil at the beginning of AppendOrMergeDMLEvent.

func AppendOrMergeDMLEvent(events []*commonEvent.DMLEvent, row *commonEvent.DMLEvent) []*commonEvent.DMLEvent {
	if row == nil {
		return events
	}
	var lastDMLEvent *commonEvent.DMLEvent
	if len(events) > 0 {
		lastDMLEvent = events[len(events)-1]
	}

	if lastDMLEvent == nil || lastDMLEvent.GetCommitTs() < row.GetCommitTs() {
References
  1. Defensive programming: check for nil arguments before calling methods on them to avoid nil pointer panics.

Signed-off-by: wk989898 <nhsmwk@gmail.com>
@wk989898

wk989898 commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

/test kafka
/test pulsar

@wk989898

wk989898 commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

/test kafka

@ti-chi-bot

ti-chi-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

@wk989898: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cdc-pulsar-integration-heavy-next-gen 39d3a6a link false /test pull-cdc-pulsar-integration-heavy-next-gen

Full PR test history. Your PR dashboard.

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 kubernetes-sigs/prow repository. I understand the commands that are listed here.

wk989898 added 2 commits July 7, 2026 09:31
Signed-off-by: wk989898 <nhsmwk@gmail.com>
Signed-off-by: wk989898 <nhsmwk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

unstable test ddl_for_split_tables_with_failover

1 participant