*: support shared lock upgrade - #69559
Conversation
|
Skipping CI for Draft Pull Request. |
📝 WalkthroughWalkthroughTiDB adds a NextGen-only shared-lock upgrade variable, propagates it to TiKV, maps shared-lock loss and upgrade conflicts, rolls back affected transactions, and adds unit and RealTiKV coverage. TiKV dependency replacements and versions are also updated. ChangesShared-lock upgrade support
Estimated code review effort: 4 (Complex) | ~45 minutes Mergeability Score: 🔵 Low · up to The shared-lock upgrade feature is gated off by default and the focused error-handling and rollback behavior is covered by tests. Merge readiness is low risk, but the PR should remain held until its temporary dependency replacements are switched back to durable upstream versions. Sequence Diagram(s)sequenceDiagram
participant Client
participant Sysvar
participant LockContext
participant TiKV
participant Transaction
Client->>Sysvar: Enable shared-lock upgrades
Sysvar->>LockContext: Store EnableSharedLockUpgrade
LockContext->>TiKV: Request shared-lock upgrade
TiKV-->>Transaction: Return lock loss or upgrade conflict
Transaction->>Transaction: Map error and roll back
Possibly related issues
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 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 |
8fcb8b3 to
94c2e16
Compare
94c2e16 to
8eeccd0
Compare
58427e3 to
7023849
Compare
Convert the client-go typed lock upgrade conflict into a non-retryable deadlock at the TiDB driver boundary, add committed local go.work wiring for the cross-repo rollout, and keep the change path-limited so the user-owned orchestration docs stay out of the commit.
Remove the supported next-gen shared-lock skips, add explicit shared-lock-upgrade acceptance scenarios, and scope the upgrade gate to only the RealTiKV cases that exercise S->X behavior.
Tighten the next-gen shared-lock rollout tests so they prove the upgrader is actually waiting through transaction state, and verify the second upgrader is a deadlock victim without an explicit rollback.
Move the lock upgrade conflict assertions out of TestLockNotFoundPrint into a dedicated top-level test so the grouping matches the extractKeyErr behavior under test. Keep the pkg/store/driver/txn Bazel test deps aligned with the current test imports surfaced by bazel_prepare.
Bump go.work to Go 1.25.10 to match the rebased TiDB and local client-go modules, and record the workspace sums generated by local build and test commands.
Signed-off-by: Wenxuan Zhang <wenxuangm@gmail.com>
Signed-off-by: Wenxuan Zhang <wenxuangm@gmail.com>
Signed-off-by: Wenxuan Zhang <wenxuangm@gmail.com>
Replace the local Go workspace with pseudo-versioned kvproto and client-go forks so the branch builds without local sibling checkouts. Regenerate the standalone Go and Bazel dependency metadata. Signed-off-by: Wenxuan Zhang <wenxuangm@gmail.com>
7023849 to
57433b6
Compare
|
[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 |
|
/hold |
Pin the feature branch to client-go dcfbdfc so lock upgrade conflicts make transactions rollback-only while preserving explicit rollback. Regenerate the Go and Bazel dependency metadata. Signed-off-by: Wenxuan Zhang <wenxuangm@gmail.com>
e498289 to
83d198b
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
go.mod (1)
366-368: 🔒 Security & Privacy | 🔵 TrivialTemporary fork dependency is consistent with the PR's tracked
/holdstatus.The replace directives point
github.com/pingcap/kvprotoandgithub.com/tikv/client-go/v2togithub.com/wfxr/kvprotoandgithub.com/wfxr/client-go/v2. This matches the PR description: the PR is/hold, and the TODO is to switch to upstream pseudo-versions after the companion kvproto and client-go changes merge. Confirm CI blocks merge until the replace directives point back to upstream modules, since a personal-namespace fork is not a durable dependency source.🤖 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 `@go.mod` around lines 366 - 368, Keep the temporary fork replacements for github.com/pingcap/kvproto and github.com/tikv/client-go/v2 while the PR remains on hold, and add or update CI merge gating to block merging until both replacements are restored to upstream modules at the required pseudo-versions after the companion changes merge.
🤖 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 `@go.mod`:
- Around line 366-368: Keep the temporary fork replacements for
github.com/pingcap/kvproto and github.com/tikv/client-go/v2 while the PR remains
on hold, and add or update CI merge gating to block merging until both
replacements are restored to upstream modules at the required pseudo-versions
after the companion changes merge.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5247c999-efee-4b73-b21b-b1828b7056d7
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (20)
DEPS.bzlgo.modpkg/errno/errcode.gopkg/errno/errname.gopkg/executor/select.gopkg/executor/select_test.gopkg/kv/error.gopkg/kv/error_test.gopkg/session/BUILD.bazelpkg/session/tidb.gopkg/session/tidb_test.gopkg/sessionctx/vardef/tidb_vars.gopkg/sessionctx/variable/session.gopkg/sessionctx/variable/sysvar.gopkg/sessionctx/variable/sysvar_test.gopkg/sessionctx/variable/varsutil_test.gopkg/store/driver/txn/BUILD.bazelpkg/store/driver/txn/driver_test.gopkg/store/driver/txn/error.gotests/realtikvtest/txntest/shared_lock_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #69559 +/- ##
================================================
- Coverage 76.3277% 76.3276% -0.0001%
================================================
Files 2041 2041
Lines 558363 558361 -2
================================================
- Hits 426186 426184 -2
Misses 131277 131277
Partials 900 900
🚀 New features to boost your workflow:
|
|
/retest |
2 similar comments
|
/retest |
|
/retest |
|
@wfxr: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. I understand the commands that are listed here. |
What problem does this PR solve?
Issue Number: ref #68815
Problem Summary:
The TiDB Next-gen shared-lock rollout needs TiDB-side wiring for allowing a pessimistic shared lock to upgrade to an exclusive lock only when the rollout gate is enabled. This rollout is intentionally limited to the TiDB Next-gen kernel; the Classic kernel must reject attempts to enable the gate. It also needs stable TiDB error semantics for typed lock-upgrade conflicts so they abort the current transaction as a non-retryable deadlock instead of entering statement retry. If TiKV reports that the original shared lock was lost during an upgrade, TiDB must expose a stable error and roll back the transaction before subsequent statements can continue using it.
What changed and how does it work?
tidb_enable_shared_lock_upgradeas a global/session boolean system variable, defaulting toOFF. It can be enabled only on the TiDB Next-gen kernel; the Classic kernel rejectsON.LockCtx.AllowSharedLockUpgradewhen TiDB builds the pessimistic lock context.ErrLockUpgradeConflictto a non-retryable deadlock at the TiDB transaction driver boundary. The client marks the original conflict as rollback-only, so later lock and commit operations cannot continue while an explicit rollback remains available for cleanup.ErrSharedLockLostto TiDB error 9015 with the transaction start TS and redacted key, and roll back the affected transaction even if it is not pessimistic.wfxr/kvprotoandwfxr/client-gomodule replacements, removego.work/go.work.sum, and regenerate standalone Go and Bazel dependency metadata.TODO / Blocker:
github.com/pingcap/kvproto/pkg/apipb, which was introduced by kvproto#1458, but the CSE-compatible kvproto fork pinned by this PR does not include that package.oneofwrappers. Existing TiDB composite literals such asAutoIDRequest.KeyspaceID,RequestHeader.KeyspaceId,kvrpcpb.Context.KeyspaceId, andkeyspacepb.KeyspaceMeta.Idtherefore no longer compile and must be migrated or covered by a compatibility strategy.replacedirectives.Check List
Tests
Validation:
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.
Summary by CodeRabbit
tidb_enable_shared_lock_upgradeto control shared-lock upgrades during pessimistic transactions.