Skip to content

dm: fix validator handling for unsigned columns (#12554)#12557

Open
ti-chi-bot wants to merge 2 commits intopingcap:release-8.1from
ti-chi-bot:cherry-pick-12554-to-release-8.1
Open

dm: fix validator handling for unsigned columns (#12554)#12557
ti-chi-bot wants to merge 2 commits intopingcap:release-8.1from
ti-chi-bot:cherry-pick-12554-to-release-8.1

Conversation

@ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #12554

What problem does this PR solve?

Issue Number: close #12178

What is changed and how it works?

DM validator now normalizes row images with adjustValueFromBinlogData before building RowChange, so UNSIGNED values follow the same conversion path as syncer.
This prevents high-bit UNSIGNED values from being treated as negative signed integers during row key generation and downstream validation.
A regression test is added for an int unsigned primary key case.

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?

No. This only reuses the existing binlog value normalization path in validator.

Do you need to update user documentation, design documentation or monitoring documentation?

No.

Release note

Fixed false-positive DM validator errors on UNSIGNED columns by normalizing row values before validation.

@ti-chi-bot ti-chi-bot added area/dm Issues or PRs related to DM. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-8.1 This PR is cherry-picked to release-8.1 from a source PR. labels Mar 13, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Mar 13, 2026

This cherry pick PR is for a release branch and has not yet been approved by triage owners.
Adding the do-not-merge/cherry-pick-not-approved label.

To merge this cherry pick:

  1. It must be LGTMed and approved by the reviewers firstly.
  2. For pull requests to TiDB-x branches, it must have no failed tests.
  3. AFTER it has lgtm and approved labels, please wait for the cherry-pick merging approval from triage owners.
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.

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Mar 13, 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 charlescheung96 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

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical validation issue in DM (Data Migration) when dealing with UNSIGNED columns. By normalizing row values before validation, it prevents false-positive errors caused by high-bit UNSIGNED values being misinterpreted as negative signed integers. The inclusion of a new regression test ensures the fix's long-term stability.

Highlights

  • Fix for UNSIGNED Column Validation: This PR addresses an issue where the DM validator incorrectly flagged errors on UNSIGNED columns due to improper handling of high-bit values.
  • Normalization of Row Images: The fix normalizes row images with adjustValueFromBinlogData before building RowChange, ensuring that UNSIGNED values are correctly converted.
  • Regression Test Added: A regression test has been added to cover the int unsigned primary key case, preventing future regressions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • dm/syncer/data_validator.go
    • The row images are now normalized with adjustValueFromBinlogData before building RowChange.
  • dm/syncer/data_validator_test.go
    • Added a regression test for an int unsigned primary key case to prevent future regressions.
Activity
  • The PR includes a fix for a reported issue (DM validator does not correctly handle UNSIGNED columns #12178) related to DM validator errors on UNSIGNED columns.
  • The changes involve modifying dm/syncer/data_validator.go to normalize row images and adding a new test case in dm/syncer/data_validator_test.go.
  • The PR author has confirmed that the changes do not cause performance regression or break compatibility.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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 fixes a bug in the data validator where unsigned integer columns were not handled correctly. The change introduces a call to adjustValueFromBinlogData to normalize row images before they are processed, ensuring UNSIGNED values are converted correctly. A regression test is also added to cover this specific case. The changes look good, but I have a suggestion to refactor some duplicated code to improve maintainability.

Comment on lines +929 to +940
if beforeImage != nil {
beforeImage, err = adjustValueFromBinlogData(beforeImage, tableInfo)
if err != nil {
return terror.Annotate(err, "failed to adjust row before image")
}
}
if afterImage != nil {
afterImage, err = adjustValueFromBinlogData(afterImage, tableInfo)
if err != nil {
return terror.Annotate(err, "failed to adjust row after image")
}
}

Choose a reason for hiding this comment

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

medium

The logic for adjusting beforeImage and afterImage is duplicated. You can refactor this into a helper function to improve code clarity and maintainability.

		adjustImage := func(image []interface{}, imageName string) ([]interface{}, error) {
			if image == nil {
				return nil, nil
			}
			adjustedImage, err := adjustValueFromBinlogData(image, tableInfo)
			if err != nil {
				return nil, terror.Annotate(err, "failed to adjust row "+imageName+" image")
			}
			return adjustedImage, nil
		}

		beforeImage, err = adjustImage(beforeImage, "before")
		if err != nil {
			return err
		}
		afterImage, err = adjustImage(afterImage, "after")
		if err != nil {
			return err
		}

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

Labels

area/dm Issues or PRs related to DM. do-not-merge/cherry-pick-not-approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-8.1 This PR is cherry-picked to release-8.1 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants