Skip to content

Optimize MPP lock exception handling - #11019

Merged
ti-chi-bot[bot] merged 2 commits into
pingcap:masterfrom
windtalker:optimize_lock_handling_in_mpp
Aug 11, 2026
Merged

Optimize MPP lock exception handling#11019
ti-chi-bot[bot] merged 2 commits into
pingcap:masterfrom
windtalker:optimize_lock_handling_in_mpp

Conversation

@windtalker

@windtalker windtalker commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #11018

Problem Summary:

MPP local read can encounter lock exceptions on many regions for the same snapshot or transaction. Falling back to remote read for each region independently can duplicate resolve-lock work and increase query latency.

What is changed and how it works?

Optimize MPP lock exception handling

This PR improves the MPP local read lock-exception path:

  • Carry local-lock transaction information through RegionException so the MPP local read retry path can decide whether local retry is possible.
  • Use client-c lock resolver bypass information to retry local read with bypass_lock_ts when a lock can be safely bypassed for the current read timestamp.
  • Keep read-index lock exceptions on the unavailable-region path, because read-index requests do not carry bypass/resolved-lock information.
  • Add tests for read-index lock handling and local-lock retryable-region handling.

Check List

Tests

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

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

None

Summary by CodeRabbit

  • Bug Fixes

    • Improved read handling when transactional locks temporarily block regions.
    • Added a brief retry path for eligible locked reads, reducing unnecessary remote read fallbacks.
    • Improved unavailable-region errors with clearer lock-related region and transaction details.
    • Read-index locks are now reported consistently as unavailable regions for more accurate recovery behavior.
    • Improved lock handling across batch, distributed, and disaggregated reads.
  • Tests

    • Added coverage for lock classification, retryable lock handling, and unavailable-region reporting.

Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c90296f3-5654-4d87-a495-972b3acade57

📥 Commits

Reviewing files that changed from the base of the PR and between 3848fd9 and 74f5435.

📒 Files selected for processing (2)
  • dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp
  • dbms/src/Storages/KVStore/Read/LearnerReadWorker.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • dbms/src/Storages/KVStore/Read/LearnerReadWorker.cpp
  • dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp

📝 Walkthrough

Walkthrough

The change preserves local lock metadata, propagates bypass-lock timestamps through DAG preparation, and adds bounded local retry handling for batch cop reads. Read-index locks remain unavailable regions and use the remote-read path.

Changes

Lock bypass retry flow

Layer / File(s) Summary
Lock exception classification and metadata
dbms/src/Storages/KVStore/Read/LearnerReadWorker.h, dbms/src/Storages/KVStore/Read/LearnerReadWorker.cpp, dbms/src/Storages/KVStore/Read/RegionException.h, dbms/src/Storages/KVStore/tests/gtest_learner_read.cpp
UnavailableRegions separates read-index locks from local lock regions. RegionException carries lock-region IDs and locks grouped by transaction. Tests cover both classifications.
Bypass timestamp propagation
dbms/src/Flash/Coprocessor/DAGContext.h, dbms/src/Flash/Coprocessor/TablesRegionsInfo.h, dbms/src/Flash/Coprocessor/TablesRegionsInfo.cpp, dbms/src/Flash/BatchCoprocessorHandler.cpp, dbms/src/Flash/Mpp/MPPTask.cpp, dbms/src/Flash/Disaggregated/WNEstablishDisaggTaskHandler.cpp
Region metadata accepts an optional bypass-lock timestamp set. Batch, MPP, and disaggregated preparation transfer the set into DAGContext.
Bounded local lock retry
dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp
The batch cop path resolves local locks with bounded backoff, records bypass timestamps, retries locally once, and falls back to remote reads when needed.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant LearnerReadWorker
  participant RegionException
  participant DAGStorageInterpreter
  participant LockResolver
  participant DAGContext
  LearnerReadWorker->>RegionException: provide lock-region metadata
  DAGStorageInterpreter->>RegionException: inspect local lock regions
  DAGStorageInterpreter->>LockResolver: resolve lock transaction
  LockResolver-->>DAGStorageInterpreter: return resolution and bypass timestamp
  DAGStorageInterpreter->>DAGContext: store bypass-lock timestamp
  DAGStorageInterpreter->>DAGStorageInterpreter: retry locally once or use remote read
Loading

Possibly related PRs

Poem

I’m a rabbit with timestamps bright,
Guiding locked reads through the night.
Local retries hop once in line,
Remote paths wait when locks still shine.
Read-index locks stay safely away—
Bypass-aware reads now lead the way.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: optimizing MPP lock exception handling.
Description check ✅ Passed The description follows the template and includes the issue, problem, implementation, tests, side effects, documentation, and release note sections.
Linked Issues check ✅ Passed The changes address local-lock propagation, bypass-based local retries, bounded waiting, read-index fallback, and relevant test coverage required by issue #11018.
Out of Scope Changes check ✅ Passed The changes remain focused on MPP and batch local-read lock handling, related exception data, resolver integration, and targeted tests.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp (1)

146-154: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use tryLogCurrentException in the catch-all path.

The current log discards the exception details. Use tryLogCurrentException with the lock-region context before returning the remote-read fallback.

As per coding guidelines, “Use tryLogCurrentException(log, "context") in broad catch (...) paths.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp` around lines 146 - 154,
Update the catch-all path in the bypass-lock check to call
tryLogCurrentException with the existing log object and lock-region context
before returning false. Replace the generic LOG_WARNING there so the exception
details are preserved while retaining the remote-read fallback behavior.

Source: Coding guidelines

dbms/src/Flash/Coprocessor/DAGContext.h (1)

285-294: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Use camelCase for new C++ variables and parameters.

The new lock-bypass flow introduces snake_case identifiers. Rename these identifiers consistently before extending this API further.

  • dbms/src/Flash/Coprocessor/DAGContext.h#L285-L294: rename bypass_lock_ts and bypass_lock_ts_.
  • dbms/src/Flash/Coprocessor/TablesRegionsInfo.h#L43-L47: rename bypass_lock_ts.
  • dbms/src/Flash/Coprocessor/TablesRegionsInfo.cpp#L71-L88: rename local_region_id_set and bypass_lock_ts.
  • dbms/src/Flash/BatchCoprocessorHandler.cpp#L71-L106: rename bypass_lock_ts.
  • dbms/src/Flash/Disaggregated/WNEstablishDisaggTaskHandler.cpp#L53-L96: rename bypass_lock_ts.
  • dbms/src/Flash/Mpp/MPPTask.cpp#L493-L547: rename bypass_lock_ts.
  • dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp#L91-L179: rename wait_bg_resolve_lock_ms, try_get_bypass_lock_max_backoff_ms, read_tso, and related local variables.
  • dbms/src/Storages/KVStore/Read/RegionException.h#L67-L84: rename unavailable_region_, lock_region_, locks_, lock_region, and unavailable_region.
  • dbms/src/Storages/KVStore/Read/LearnerReadWorker.h#L52-L103: rename lock_region_ids, region_id_, and region_lock_.
  • dbms/src/Storages/KVStore/tests/gtest_learner_read.cpp#L47-L57: rename lock_version and lock_info.

As per coding guidelines, “Method and variable names should use camelCase.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dbms/src/Flash/Coprocessor/DAGContext.h` around lines 285 - 294, Rename the
newly introduced snake_case variables and parameters to camelCase consistently
across the listed sites: DAGContext.h lines 285-294; TablesRegionsInfo.h lines
43-47 and TablesRegionsInfo.cpp lines 71-88; BatchCoprocessorHandler.cpp lines
71-106; WNEstablishDisaggTaskHandler.cpp lines 53-96; MPPTask.cpp lines 493-547;
DAGStorageInterpreter.cpp lines 91-179; RegionException.h lines 67-84;
LearnerReadWorker.h lines 52-103; and gtest_learner_read.cpp lines 47-57. Rename
the specified lock-bypass, region, timing, TSO, and test identifiers while
updating all references without changing behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@dbms/src/Flash/Coprocessor/DAGContext.h`:
- Around line 285-294: Rename the newly introduced snake_case variables and
parameters to camelCase consistently across the listed sites: DAGContext.h lines
285-294; TablesRegionsInfo.h lines 43-47 and TablesRegionsInfo.cpp lines 71-88;
BatchCoprocessorHandler.cpp lines 71-106; WNEstablishDisaggTaskHandler.cpp lines
53-96; MPPTask.cpp lines 493-547; DAGStorageInterpreter.cpp lines 91-179;
RegionException.h lines 67-84; LearnerReadWorker.h lines 52-103; and
gtest_learner_read.cpp lines 47-57. Rename the specified lock-bypass, region,
timing, TSO, and test identifiers while updating all references without changing
behavior.

In `@dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp`:
- Around line 146-154: Update the catch-all path in the bypass-lock check to
call tryLogCurrentException with the existing log object and lock-region context
before returning false. Replace the generic LOG_WARNING there so the exception
details are preserved while retaining the remote-read fallback behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d0ba1a31-c761-4e91-94a8-7d0678f2435d

📥 Commits

Reviewing files that changed from the base of the PR and between fd0d7d3 and 3848fd9.

📒 Files selected for processing (11)
  • dbms/src/Flash/BatchCoprocessorHandler.cpp
  • dbms/src/Flash/Coprocessor/DAGContext.h
  • dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp
  • dbms/src/Flash/Coprocessor/TablesRegionsInfo.cpp
  • dbms/src/Flash/Coprocessor/TablesRegionsInfo.h
  • dbms/src/Flash/Disaggregated/WNEstablishDisaggTaskHandler.cpp
  • dbms/src/Flash/Mpp/MPPTask.cpp
  • dbms/src/Storages/KVStore/Read/LearnerReadWorker.cpp
  • dbms/src/Storages/KVStore/Read/LearnerReadWorker.h
  • dbms/src/Storages/KVStore/Read/RegionException.h
  • dbms/src/Storages/KVStore/tests/gtest_learner_read.cpp

Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
@windtalker

Copy link
Copy Markdown
Contributor Author

/test pull-integration-test

@windtalker

Copy link
Copy Markdown
Contributor Author

/test pull-unit-next-gen

@ti-chi-bot ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 11, 2026
@ti-chi-bot

ti-chi-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gengliqi, solotzg

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 11, 2026
@ti-chi-bot

ti-chi-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

[LGTM Timeline notifier]

Timeline:

  • 2026-08-11 05:17:09.644378567 +0000 UTC m=+3110015.680473624: ☑️ agreed by gengliqi.
  • 2026-08-11 05:26:55.508192245 +0000 UTC m=+3110601.544287302: ☑️ agreed by solotzg.

@windtalker

Copy link
Copy Markdown
Contributor Author

/test pull-integration-test

@ti-chi-bot
ti-chi-bot Bot merged commit 5c72bfa into pingcap:master Aug 11, 2026
11 checks passed
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/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.

Optimize MPP lock exception handling

3 participants