Skip to content

transaction: resolve orphaned locks whose primary was never written#544

Open
eduralph wants to merge 2 commits into
tikv:masterfrom
getwyrd:fix/check-txn-status-multiplekeyerrors
Open

transaction: resolve orphaned locks whose primary was never written#544
eduralph wants to merge 2 commits into
tikv:masterfrom
getwyrd:fix/check-txn-status-multiplekeyerrors

Conversation

@eduralph

@eduralph eduralph commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

check_txn_status matched only ExtractedErrors, but its plan delivers per-key errors as MultipleKeyErrors, so the Rollback_if_not_exist escalation in get_txn_status_from_lock was unreachable and an orphaned secondary lock poisoned its key permanently. Accept both wrappers.

Refs #531

Signed-off-by: Eduard Ralph eduard@ralphovi.net

Summary by CodeRabbit

  • Bug Fixes
    • Improved transaction status handling when multiple per-key errors are returned.
    • txn_not_found is now consistently reported as “transaction not found” instead of a generic error.
    • Ensures orphaned locks (primary never written) properly trigger rollback escalation and lock cleanup.
  • Tests
    • Added coverage for the missing-primary/orphaned-lock scenario, including verification that lock resolution is invoked once.

@ti-chi-bot

ti-chi-bot Bot commented Jul 5, 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 disksing 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 added dco-signoff: yes Indicates the PR's author has signed the dco. contribution This PR is from a community contributor. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 5, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown

Welcome @eduralph!

It looks like this is your first PR to tikv/client-rust 🎉.

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 tikv/client-rust. 😃

@ti-chi-bot ti-chi-bot Bot added the first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. label Jul 5, 2026
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0ce8a72b-d8da-4da2-95fe-405445b12650

📥 Commits

Reviewing files that changed from the base of the PR and between 0902af0 and f6cf433.

📒 Files selected for processing (1)
  • src/transaction/lock.rs

📝 Walkthrough

Walkthrough

check_txn_status now handles Error::MultipleKeyErrors when converting txn_not_found key failures. Tests cover an orphaned lock whose primary transaction was never written and verify rollback escalation removes the lock.

Changes

Transaction status error handling

Layer / File(s) Summary
Expand transaction status error handling
src/transaction/lock.rs
check_txn_status processes Error::MultipleKeyErrors like Error::ExtractedErrors, converting a matching KeyError into Error::TxnNotFound.
Validate orphaned-lock rollback escalation
src/transaction/lock.rs
An async test captures status requests and verifies rollback_if_not_exist escalation, lock removal, and one ResolveLock invocation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: resolving orphaned transaction locks when the primary was never written.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

eduralph added 2 commits July 12, 2026 15:41
check_txn_status matched only ExtractedErrors, but its plan delivers per-key
errors as MultipleKeyErrors, so the rollback_if_not_exist escalation in
get_txn_status_from_lock was unreachable and an orphaned secondary lock
poisoned its key permanently. Accept both wrappers.

Refs tikv#531

Signed-off-by: Eduard Ralph <eduard@ralphovi.net>
Add a regression test for the MultipleKeyErrors fix: an expired lock whose
primary was never written must escalate to rollback_if_not_exist and resolve,
rather than surfacing the raw error. The test asserts the two CheckTxnStatus
calls and fails on the pre-fix code with MultipleKeyErrors([KeyError { .. }]).

Also correct the new comment: the key errors are produced by
single_shard_handler, not single_plan_handler, and name CollectSingle as the
reason this call site differs from the plans that never see MultipleKeyErrors.

Refs tikv#531

Signed-off-by: Eduard Ralph <eduard@ralphovi.net>
@eduralph eduralph force-pushed the fix/check-txn-status-multiplekeyerrors branch from 0902af0 to f6cf433 Compare July 12, 2026 13:44
@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution This PR is from a community contributor. dco-signoff: yes Indicates the PR's author has signed the dco. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. 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.

1 participant