tidb icon indicating copy to clipboard operation
tidb copied to clipboard

*: ref all the jobs before sending to jobToWorkerCh

Open wjhuang2016 opened this issue 1 month ago • 10 comments

What problem does this PR solve?

Issue Number: close #64666

Problem Summary: In the generateAndSendJob function, we previously referenced one region job at a time and immediately sent it to jobToWorkerCh. If a job (especially an empty job) finished before the next job was referenced, the reference count could drop to 0, causing memoryIngestData to be cleaned unexpectedly. This prevented other jobs still being processed from accessing the data, leading to data inconsistency. In tidb-x scenarios, where region sizes are larger than the configured SplitRegionSize, some regions' jobs are empty. These empty jobs are processed quickly, which makes this issue more likely to occur.

What changed and how does it work?

We modified the logic in generateAndSendJob to reference all jobs before sending them to jobToWorkerCh. Specifically, we first call job.ref(jobWg) for all generated jobs in a loop, and then send them to the channel one by one in a separate loop.

This ensures all jobs have their reference counts incremented before any of them are sent to the channel. Even if some jobs (like empty jobs) finish quickly and call done(), as long as other jobs still hold references, ingestData will not be cleaned prematurely. Only when all jobs complete and call done() will the reference count reach 0, at which point ingestData can be safely cleaned, preventing data inconsistency issues.

Check List

Tests

  • [x] Unit test
  • [x] Integration test Pass the tidb-x HA add index test
  • [ ] Manual test (add detailed scripts or steps below)
  • [ ] No need to test
    • [ ] I checked and no code files have been changed.

Side effects

  • [ ] Performance regression: Consumes more CPU
  • [ ] Performance regression: Consumes more Memory
  • [ ] Breaking backward compatibility

Documentation

  • [ ] Affects user behaviors
  • [ ] Contains syntax changes
  • [ ] Contains variable changes
  • [ ] Contains experimental features
  • [ ] Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

wjhuang2016 avatar Nov 28 '25 10:11 wjhuang2016

Codecov Report

:x: Patch coverage is 45.94595% with 20 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 70.2114%. Comparing base (8aefecd) to head (7136ac0). :warning: Report is 13 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #64767        +/-   ##
================================================
- Coverage   70.9290%   70.2114%   -0.7176%     
================================================
  Files          1888       1890         +2     
  Lines        515954     522435      +6481     
================================================
+ Hits         365961     366809       +848     
- Misses       125582     132381      +6799     
+ Partials      24411      23245      -1166     
Flag Coverage Δ
integration 45.0599% <24.3243%> (-3.0946%) :arrow_down:
unit 66.6995% <21.6216%> (+1.0354%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.8700% <ø> (ø)
parser ∅ <ø> (∅)
br 39.3982% <ø> (-20.0267%) :arrow_down:
:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Nov 30 '25 22:11 codecov[bot]

/retest

joechenrh avatar Dec 01 '25 10:12 joechenrh

/retest

wjhuang2016 avatar Dec 02 '25 04:12 wjhuang2016

/retest

wjhuang2016 avatar Dec 09 '25 13:12 wjhuang2016

/retest

wjhuang2016 avatar Dec 10 '25 06:12 wjhuang2016

/retest

wjhuang2016 avatar Dec 10 '25 09:12 wjhuang2016

please also node in the detail that only partition table might meet this issue. as we are grouping keys by index id, not partition id, so some range might cross many partition, and the created region job might be empty and trigger this issue

D3Hunter avatar Dec 11 '25 06:12 D3Hunter

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: D3Hunter, joechenrh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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[bot] avatar Dec 12 '25 07:12 ti-chi-bot[bot]

[LGTM Timeline notifier]

Timeline:

  • 2025-12-12 07:51:35.34099909 +0000 UTC m=+1200240.154776652: :ballot_box_with_check: agreed by D3Hunter.
  • 2025-12-12 07:56:54.840458734 +0000 UTC m=+1200559.654236306: :ballot_box_with_check: agreed by joechenrh.

ti-chi-bot[bot] avatar Dec 12 '25 07:12 ti-chi-bot[bot]

/retest

joechenrh avatar Dec 12 '25 14:12 joechenrh

/retest

joechenrh avatar Dec 13 '25 02:12 joechenrh

/retest

joechenrh avatar Dec 13 '25 11:12 joechenrh

@wjhuang2016: 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-unit-test-ddlv1 baf0d5483fbe3c247469b34659602c4e766b9ddc link true /test pull-unit-test-ddlv1
pull-br-integration-test baf0d5483fbe3c247469b34659602c4e766b9ddc link true /test pull-br-integration-test

Full PR test history. Your PR dashboard.

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.

ti-chi-bot[bot] avatar Dec 13 '25 11:12 ti-chi-bot[bot]

/retest

wjhuang2016 avatar Dec 14 '25 05:12 wjhuang2016

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

ti-chi-bot avatar Dec 14 '25 06:12 ti-chi-bot