Skip to content

sink(ticdc): add before field for avro protocol#12632

Open
wk989898 wants to merge 2 commits into
pingcap:masterfrom
wk989898:avro-0509
Open

sink(ticdc): add before field for avro protocol#12632
wk989898 wants to merge 2 commits into
pingcap:masterfrom
wk989898:avro-0509

Conversation

@wk989898
Copy link
Copy Markdown
Collaborator

@wk989898 wk989898 commented May 9, 2026

What problem does this PR solve?

Issue Number: close #12631 close #11824

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

Signed-off-by: wk989898 <nhsmwk@gmail.com>
@ti-chi-bot ti-chi-bot Bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label May 9, 2026
@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented May 9, 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 likidu, niubell 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

@ti-chi-bot ti-chi-bot Bot added the affect-ticdc-config-docs Pull requests that affect TiCDC configuration docs. label May 9, 2026
@wk989898 wk989898 changed the title sink(ticdc): add before field fro avro protocol sink(ticdc): add before field for avro protocol May 9, 2026
@ti-chi-bot ti-chi-bot Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label May 9, 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 introduces the AvroIncludeBeforeValue configuration option, which allows the Avro codec to include pre-update column values in the encoded output. The implementation includes updates to the API models, configuration parsing, and both the Avro encoder and decoder, along with corresponding unit tests. Review feedback identifies several locations in the decoder where unsafe type assertions and string operations could lead to panics, recommending the use of comma-ok assertions and more rigorous validation of schema metadata.

Comment on lines +203 to +205
namespace := schema["namespace"].(string)
schemaName := strings.Split(namespace, ".")[1]
tableName := schema["name"].(string)
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

These type assertions and the string split operation are fragile and could lead to a panic if the schema metadata is unexpected (e.g., missing namespace or namespace without a dot). It is safer to use comma-ok assertions and check the length of the split result.

Suggested change
namespace := schema["namespace"].(string)
schemaName := strings.Split(namespace, ".")[1]
tableName := schema["name"].(string)
namespace, ok := schema["namespace"].(string)
if !ok {
return nil, errors.New("namespace not found or not a string")
}
parts := strings.Split(namespace, ".")
if len(parts) < 2 {
return nil, errors.New("invalid namespace format")
}
schemaName := parts[1]
tableName, ok := schema["name"].(string)
if !ok {
return nil, errors.New("table name not found or not a string")
}

if !ok {
return nil, errors.New("commit ts not found")
}
commitTs = o.(int64)
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

This type assertion could panic if the value is not an int64. Using a comma-ok assertion is safer.

commitTs, ok = o.(int64)
		if !ok {
			return nil, errors.New("commit ts is not an int64")
		}

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

/retest

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented May 12, 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-error-log-review 0ff364f link true /test pull-error-log-review
pull-dm-integration-test 0ff364f link true /test pull-dm-integration-test
pull-dm-integration-test-next-gen 0ff364f link false /test pull-dm-integration-test-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.

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

Labels

affect-ticdc-config-docs Pull requests that affect TiCDC configuration docs. 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.

TiCDC Avro Protocol Supports "Before" State avro protocol doesn't encode previous values in Delete/Update events

1 participant