Skip to content

redo(ticdc): add column info for redo ddl event#12602

Merged
ti-chi-bot[bot] merged 8 commits into
pingcap:masterfrom
wk989898:redo-0413
Apr 18, 2026
Merged

redo(ticdc): add column info for redo ddl event#12602
ti-chi-bot[bot] merged 8 commits into
pingcap:masterfrom
wk989898:redo-0413

Conversation

@wk989898
Copy link
Copy Markdown
Collaborator

@wk989898 wk989898 commented Apr 13, 2026

What problem does this PR solve?

Issue Number: close #12600

What is changed and how it works?

Add column info for Redo DDL event to avoid data inconsistency if the column type is time default with origin_default

This PR #12490 will use column info in the DDL event to align the upstream current timestamp. TiCDC has to encode column info for redo ddl event, and redo apply will decode the column info for replicating the ddl event.

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

add column info for redo ddl event

Signed-off-by: wk989898 <nhsmwk@gmail.com>
@ti-chi-bot ti-chi-bot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/needs-triage-completed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 13, 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 enhances DDL redo logs by including column metadata, enabling more accurate table schema reconstruction. The review feedback identifies a critical nil pointer risk in the log reader and highlights the need to properly persist and map unique column IDs, which are currently missing from the data structures and logic.

Comment thread cdc/redo/reader/reader.go
Comment on lines 211 to 213
ddl := item.data.RedoDDL.DDL
ddl.TableInfo.Columns = setColumns(item.data.RedoDDL.Columns)
if ddl != nil && ddl.CommitTs > cfg.startTs && ddl.CommitTs <= cfg.endTs {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

Potential nil pointer dereference. The code accesses ddl.TableInfo on line 212 before checking if ddl is nil on line 213. Additionally, if ddl.TableInfo is initialized but its embedded timodel.TableInfo is nil (as seen in postUnmarshal), accessing Columns will also panic. The column initialization should be guarded by a nil check.

Suggested change
ddl := item.data.RedoDDL.DDL
ddl.TableInfo.Columns = setColumns(item.data.RedoDDL.Columns)
if ddl != nil && ddl.CommitTs > cfg.startTs && ddl.CommitTs <= cfg.endTs {
ddl := item.data.RedoDDL.DDL
if ddl != nil {
if ddl.TableInfo.TableInfo == nil {
ddl.TableInfo.TableInfo = &timodel.TableInfo{}
}
ddl.TableInfo.Columns = setColumns(item.data.RedoDDL.Columns)
}
if ddl != nil && ddl.CommitTs > cfg.startTs && ddl.CommitTs <= cfg.endTs {

Comment thread cdc/redo/reader/reader.go
Comment on lines +405 to +410
colInfo := &timodel.ColumnInfo{
ID: int64(len(columns)),
Name: ast.NewCIStr(col.Name),
State: timodel.StatePublic,
Version: col.Version,
}
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

Setting the ID of every column to int64(len(columns)) is incorrect as column IDs should be unique within a table. Use the ID field from model.ColumnInfo (after adding it to the struct) to reconstruct the column info correctly.

Suggested change
colInfo := &timodel.ColumnInfo{
ID: int64(len(columns)),
Name: ast.NewCIStr(col.Name),
State: timodel.StatePublic,
Version: col.Version,
}
colInfo := &timodel.ColumnInfo{
ID: col.ID,
Name: ast.NewCIStr(col.Name),
State: timodel.StatePublic,
Version: col.Version,
}

Comment thread cdc/model/sink.go
Comment on lines +296 to 301
type ColumnInfo struct {
Name string `msg:"name"`
OriginDefaultValue any `msg:"origin_default"`
Type byte `msg:"type"`
Version uint64 `msg:"version"`
}
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 ColumnInfo struct is missing the column ID. Since timodel.ColumnInfo requires a unique ID for various internal operations and schema tracking, it is recommended to persist the original ID from the upstream table info to ensure accurate reconstruction during redo log playback.

Suggested change
type ColumnInfo struct {
Name string `msg:"name"`
OriginDefaultValue any `msg:"origin_default"`
Type byte `msg:"type"`
Version uint64 `msg:"version"`
}
// ColumnInfo is for column meta in DDL event
type ColumnInfo struct {
ID int64 `msg:"id"`
Name string `msg:"name"`
OriginDefaultValue any `msg:"origin_default"`
Type byte `msg:"type"`
Version uint64 `msg:"version"`
}

Comment thread cdc/model/sink.go
Comment on lines +330 to +335
columns = append(columns, &ColumnInfo{
Name: col.Name.String(),
OriginDefaultValue: col.GetOriginDefaultValue(),
Type: col.GetType(),
Version: col.Version,
})
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

Populate the ID field from the original column info to allow for accurate reconstruction of the table schema from redo logs.

			columns = append(columns, &ColumnInfo{
				ID:                 col.ID,
				Name:               col.Name.String(),
				OriginDefaultValue: col.GetOriginDefaultValue(),
				Type:               col.GetType(),
				Version:            col.Version,
			})

Signed-off-by: wk989898 <nhsmwk@gmail.com>
Signed-off-by: wk989898 <nhsmwk@gmail.com>
@ti-chi-bot ti-chi-bot Bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Apr 14, 2026
@wk989898 wk989898 added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Apr 14, 2026
Signed-off-by: wk989898 <nhsmwk@gmail.com>
@ti-chi-bot ti-chi-bot Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 14, 2026
Signed-off-by: wk989898 <nhsmwk@gmail.com>
Signed-off-by: wk989898 <nhsmwk@gmail.com>
@ti-chi-bot ti-chi-bot Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 14, 2026
@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 14, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 3AceShowHand, 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:
  • OWNERS [3AceShowHand,hongyunyan]

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Apr 14, 2026
@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 14, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-04-14 03:15:48.50642199 +0000 UTC m=+1444553.711782057: ☑️ agreed by 3AceShowHand.
  • 2026-04-14 16:39:13.97659695 +0000 UTC m=+1492759.181957017: ☑️ agreed by hongyunyan.

Signed-off-by: wk989898 <nhsmwk@gmail.com>
@wk989898
Copy link
Copy Markdown
Collaborator Author

/retest

Signed-off-by: wk989898 <nhsmwk@gmail.com>
@wk989898
Copy link
Copy Markdown
Collaborator Author

/retest

2 similar comments
@wk989898
Copy link
Copy Markdown
Collaborator Author

/retest

@wk989898
Copy link
Copy Markdown
Collaborator Author

/retest

@ti-chi-bot ti-chi-bot Bot merged commit 5b45aa0 into pingcap:master Apr 18, 2026
27 of 28 checks passed
ti-chi-bot pushed a commit to ti-chi-bot/tiflow that referenced this pull request Apr 18, 2026
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Copy Markdown
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #12613.
But this PR has conflicts, please resolve them!

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 18, 2026

@wk989898: The following tests 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-dm-integration-test-next-gen c2f3477 link false /test pull-dm-integration-test-next-gen
pull-syncdiff-integration-test c2f3477 link unknown /test pull-syncdiff-integration-test

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.

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

Labels

approved lgtm needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. 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.

incorrect default CURRENT_TIMESTAMP with redo

4 participants