Skip to content

sync_diff_inspector: check rows.Err in TiDB iterator#901

Open
banerjeeadrish wants to merge 1 commit into
pingcap:masterfrom
banerjeeadrish:fix/sync-diff-tidb-rows-err
Open

sync_diff_inspector: check rows.Err in TiDB iterator#901
banerjeeadrish wants to merge 1 commit into
pingcap:masterfrom
banerjeeadrish:fix/sync-diff-tidb-rows-err

Conversation

@banerjeeadrish

Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: close #900

sync-diff-inspector can silently swallow TiDB row-stream errors during row comparison.

When TiDBRowsIterator.Next() sees rows.Next() == false, it currently returns (nil, nil) directly. However, per the database/sql contract, rows.Next() == false can mean either clean EOF or an iteration error. The caller must check rows.Err() to distinguish the two cases.

If the TiDB-side query is cancelled mid-stream, for example due to tidb_mem_quota_query, sync-diff-inspector can incorrectly treat the TiDB iterator as exhausted. This may produce false +N/-0 diffs and bogus REPLACE INTO fix SQL instead of surfacing the original TiDB query error.

What is changed and how it works?

This PR updates TiDBRowsIterator.Next() to check s.rows.Err() after s.rows.Next() returns false.

If rows.Err() is non-nil, the iterator now returns the error instead of treating it as clean EOF. The existing row comparison flow already propagates non-nil iterator errors, so the table comparison fails with the real TiDB error instead of generating false fix SQL.

A unit test was added to cover the row-stream error case and verify that TiDBRowsIterator.Next() returns the underlying database/sql error.

Check List

Tests

  • Unit test

Code changes

  • None

Side effects

  • None

Related changes

  • Need to cherry-pick to the release branch
  • Need to be included in the release note

@ti-chi-bot

ti-chi-bot Bot commented Jun 19, 2026

Copy link
Copy Markdown

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

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

ti-chi-bot Bot commented Jun 19, 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 yisaer 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 commented Jun 19, 2026

Copy link
Copy Markdown

Hi @banerjeeadrish. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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

ti-chi-bot Bot commented Jun 19, 2026

Copy link
Copy Markdown

Welcome @banerjeeadrish!

It looks like this is your first PR to pingcap/tidb-tools 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to pingcap/tidb-tools. 😃

@pingcap-cla-assistant

pingcap-cla-assistant Bot commented Jun 19, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@ti-chi-bot ti-chi-bot Bot added the size/S label Jun 19, 2026
@banerjeeadrish banerjeeadrish force-pushed the fix/sync-diff-tidb-rows-err branch from 77b07ad to fc123bd Compare June 19, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sync-diff-inspector silently swallows TiDB row stream errors and generates false REPLACE fix SQL

1 participant