Skip to content

ingest: skip write when the region has no leader#64442

Merged
ti-chi-bot[bot] merged 12 commits into
pingcap:masterfrom
D3Hunter:log-unretryable-err-type
Nov 13, 2025
Merged

ingest: skip write when the region has no leader#64442
ti-chi-bot[bot] merged 12 commits into
pingcap:masterfrom
D3Hunter:log-unretryable-err-type

Conversation

@D3Hunter

@D3Hunter D3Hunter commented Nov 12, 2025

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #64422, ref #61702

Problem Summary:

What changed and how does it work?

this issue only happens in nextgen, as classic region job worker already have an additional leader check after write to tikv, we fix this by check region leader before write, so for classic kernel we can avoid the useless write

if len(leaderPeerMetas) == 0 {

also log the unretryable error, to help debug and direct us to add more retryable error

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

we run the same scenario in the issue, no such error again, and we can see errors like below when there is no leader for some scanned region

[2025/11/13 15:46:11.734 +08:00] [INFO] [local.go:1497] ["put job back to jobCh to retry later"] [keyspaceName=SYSTEM] [task-id=120016] [task-key=keyspace_a/ImportInto/120016] [subtaskID=270022] [step=ingest] [startKey=780000017480000000000000C55F7280000000003C8F88] [endKey=780000017480000000000000C55F7280000000003C9901] [stage=regionScanned] [retryCount=1] [waitUntil=2025/11/13 15:46:13.734 +08:00] [error="[KV:ErrNoLeader]region has no leader, region '326782'"]
  • 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

@ti-chi-bot

ti-chi-bot Bot commented Nov 12, 2025

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 12, 2025
@tiprow

tiprow Bot commented Nov 12, 2025

Copy link
Copy Markdown

Hi @D3Hunter. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

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 added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 12, 2025
@D3Hunter D3Hunter changed the title ingest: skip write when the region has no need ingest: skip write when the region has no leader Nov 12, 2025
@D3Hunter

Copy link
Copy Markdown
Contributor Author

/cherry-pick release-nextgen-20251011

@ti-chi-bot

Copy link
Copy Markdown
Member

@D3Hunter: once the present PR merges, I will cherry-pick it on top of release-nextgen-20251011 in the new PR and assign it to you.

Details

In response to this:

/cherry-pick release-nextgen-20251011

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 ti-community-infra/tichi repository.

@D3Hunter D3Hunter marked this pull request as ready for review November 13, 2025 04:09
@ti-chi-bot ti-chi-bot Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 13, 2025
@codecov

codecov Bot commented Nov 13, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.6174%. Comparing base (d4c1408) to head (566becb).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #64442        +/-   ##
================================================
+ Coverage   72.6813%   73.6174%   +0.9361%     
================================================
  Files          1866       1889        +23     
  Lines        506188     514301      +8113     
================================================
+ Hits         367904     378615     +10711     
+ Misses       115892     112742      -3150     
- Partials      22392      22944       +552     
Flag Coverage Δ
integration 44.4777% <78.2608%> (?)
unit 72.5267% <91.3043%> (+0.2729%) ⬆️

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

Components Coverage Δ
dumpling 52.8700% <ø> (ø)
parser ∅ <ø> (∅)
br 46.2438% <ø> (+0.0901%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@D3Hunter

Copy link
Copy Markdown
Contributor Author

/retest

@tiprow

tiprow Bot commented Nov 13, 2025

Copy link
Copy Markdown

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

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 added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 13, 2025
@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 13, 2025
@D3Hunter

Copy link
Copy Markdown
Contributor Author

/hold

@ti-chi-bot ti-chi-bot Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 13, 2025
Comment thread pkg/lightning/backend/local/job_worker.go

@GMHDBJD GMHDBJD left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot

ti-chi-bot Bot commented Nov 13, 2025

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

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

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:

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 approved lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 13, 2025
@ti-chi-bot

ti-chi-bot Bot commented Nov 13, 2025

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2025-11-13 05:09:07.275011022 +0000 UTC m=+937996.718040891: ☑️ agreed by joechenrh.
  • 2025-11-13 07:30:26.56697029 +0000 UTC m=+946476.010000159: ☑️ agreed by GMHDBJD.

// Also note, valid store ID > 0.
if job.region.Leader.GetStoreId() == 0 {
job.lastRetryableErr = errdef.ErrNoLeader.GenWithStackByArgs(job.region.Region.GetId())
job.convertStageTo(needRescan)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the raft member state are not change and only PD losts the latest state, change to "regionScanned" is better

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

how to determine raft member state are not change and only PD losts the latest state?

@lance6716 lance6716 Nov 13, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we optimistically & wrongly change to regionScanned, later in write RPC TiDB will see "epoch not match", "request too old" and it comes to needRescan. Luckily we don't need to scan region, but the tradeoff is we may have an extra round to process the job.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know the background context of this issue. If only PD reboot, I think TiKV's raft epoch is not changed, regionScanned is better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

if we cannot determine based on the scanned region info, we have to write or ingest and let tikv return the error back to us

in the case of this PR, the above check is to check whether the scanned region have leader or not, if no, we have to rescan

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@D3Hunter

Copy link
Copy Markdown
Contributor Author

/retest

@tiprow

tiprow Bot commented Nov 13, 2025

Copy link
Copy Markdown

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

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.

@D3Hunter

Copy link
Copy Markdown
Contributor Author

/unhold

@ti-chi-bot ti-chi-bot Bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 13, 2025
@D3Hunter

Copy link
Copy Markdown
Contributor Author

/retest

@tiprow

tiprow Bot commented Nov 13, 2025

Copy link
Copy Markdown

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

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 merged commit 8e799f7 into pingcap:master Nov 13, 2025
28 checks passed
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Nov 13, 2025
@ti-chi-bot

Copy link
Copy Markdown
Member

@D3Hunter: new pull request created to branch release-nextgen-20251011: #64470.

Details

In response to this:

/cherry-pick release-nextgen-20251011

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 ti-community-infra/tichi repository.

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

Labels

approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tidb-x] import into failed when kill pd leader

5 participants