txnkv: support shared lock upgrades#2014
Conversation
Add a typed ErrLockUpgradeConflict, decode it from KeyError including API v2 key decoding, treat it as a known shared-lock upgrade failure, and keep the local go.work wiring committed so Task 5 remains buildable against the local kvproto update during rollout sequencing.
Rename the shared-lock-upgrade helper to describe the undetermined-result case directly and invert its return value so the upgrade error branch reads in positive form without changing behavior.
For non-upgrade pessimistic lock groups, the rollback path always uses the same keys that were locked. The shared-lock-upgrade path returns before any pessimistic rollback, so the extra parameter was unused there and can be removed without changing behavior.
Move the temporary lock key into the LockOnlyIfExists validation branch and rename it to lockKey so the variable name matches its diagnostic-only role.
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
Support upgrading a pessimistic shared lock to an exclusive lock when the caller explicitly opts in through
LockCtx.AllowSharedLockUpgrade.This is needed for TiDB foreign-key checking with
tidb_foreign_key_check_in_shared_lockenabled. In that flow, a transaction may first acquire a shared lock while checking the parent row and then update the same parent row later in the same transaction.Related to pingcap/tidb#68815.
Changes
LockCtx.AllowSharedLockUpgradeto gate shared-to-exclusive lock upgrades explicitly.LockUpgradeConflicterrors and API v2 key decoding support.Dependency / TODO
This draft currently depends on kvproto support for
kvrpcpb.LockUpgradeConflict:Temporary TODO before marking this PR ready:
github.com/pingcap/kvprotoingo.modto the merged commit that containsLockUpgradeConflict.go.work/go.work.sumworkspace files after the dependency is updated.Testing
Attempted:
go test ./error ./internal/apicodec ./txnkv/transactionBlocked before running tests because the temporary
go.workdeclaresgo 1.25.9whilego.modrequiresgo 1.25.10.Also attempted:
GOWORK=off GOCACHE=/tmp/codex-go-cache go test ./error ./internal/apicodec ./txnkv/transactionThis confirmed the branch currently depends on the pending kvproto change and fails to compile without it: