Skip to content

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

Open
eduralph wants to merge 4 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 4 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 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

📝 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
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.
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.
✨ 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
@eduralph

Copy link
Copy Markdown
Contributor Author

@ekexium to raise awareness

@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 20, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ekexium

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 commented Jul 20, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-07-20 02:41:27.429603463 +0000 UTC m=+1199873.465698519: ☑️ agreed by ekexium.

@ti-chi-bot ti-chi-bot Bot added the approved label Jul 20, 2026
@eduralph eduralph closed this Jul 22, 2026
@eduralph eduralph reopened this Jul 22, 2026
@eduralph

Copy link
Copy Markdown
Contributor Author

@pingyu - we're 1 LGTM away from getting this merged

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

Labels

approved 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. needs-1-more-lgtm Indicates a PR needs 1 more LGTM. 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.

2 participants