txn: support shared lock for pessimistic / prewrite / commit schedulers#19282
txn: support shared lock for pessimistic / prewrite / commit schedulers#19282ti-chi-bot[bot] merged 14 commits intotikv:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request implements support for shared locks in the pessimistic transaction model for TiKV. The PR adds shared lock functionality to the acquire_pessimistic_lock, prewrite, and commit schedulers/actions.
Changes:
- Adds
SharedLockvariant toMutationenum and related type handling - Implements shared lock acquisition logic in
acquire_pessimistic_lockaction - Updates prewrite logic to handle shared lock mutations and merge them with existing shared locks
- Modifies commit logic to handle shared lock entries, removing locks individually while keeping remaining entries
- Adds scheduler support for tracking whether lock requests are for shared locks
- Implements
SharedLockstype with methods for managing multiple transaction locks on the same key
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| components/txn_types/src/types.rs | Adds SharedLock mutation type and helper methods |
| components/txn_types/src/lock.rs | Implements SharedLocks structure with lock management methods and for_update_ts tracking |
| components/txn_types/src/lib.rs | Exports SharedLocks type |
| src/storage/txn/actions/acquire_pessimistic_lock.rs | Refactors lock acquisition to handle shared locks, adds helper functions for existing lock types |
| src/storage/txn/actions/prewrite.rs | Updates prewrite to handle shared lock mutations, validates incompatibilities with async commit/1PC |
| src/storage/txn/actions/commit.rs | Modifies commit to remove individual locks from shared lock entries |
| src/storage/txn/commands/mod.rs | Adds is_shared_lock_request field to WriteResultLockInfo |
| src/storage/txn/commands/acquire_pessimistic_lock.rs | Passes shared lock flag through command execution |
| src/storage/txn/commands/acquire_pessimistic_lock_resumed.rs | Updates resumed command to pass shared lock flag |
| src/storage/txn/commands/prewrite.rs | Updates byte size calculation to include SharedLock mutations |
| src/storage/txn/commands/flush.rs | Updates byte size calculation to include SharedLock mutations |
| src/storage/txn/scheduler.rs | Refactors pessimistic lock cleanup logic with better scoping |
| src/storage/mvcc/txn.rs | Adds put_shared_lock and put_shared_pessimistic_lock methods |
| src/storage/mvcc/mod.rs | Exports SharedLocks and adds test helper function |
| src/storage/mvcc/metrics.rs | Adds metric for shared lock acquisition |
| src/storage/mvcc/reader/reader.rs | Updates test to pass new shared lock parameter |
| tests/failpoints/cases/test_storage.rs | Adds comprehensive integration test for shared/exclusive lock conflicts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
4858a0d to
57dab48
Compare
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
|
/retest |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com> update type hint Signed-off-by: you06 <you1474600@gmail.com> update kvproto Signed-off-by: you06 <you1474600@gmail.com> fix: adapt into_lock_info for current branch design The cherry-picked PR had Lock::into_lock_info handling LockType::Shared, but in the current branch Lock and SharedLocks are separate types. This commit: - Simplifies Lock::into_lock_info to panic on LockType::Shared (shouldn't happen) - Updates SharedLocks::into_lock_info to properly set SharedPessimisticLock/SharedLock types Signed-off-by: you06 <you1474600@gmail.com> fix lock type Signed-off-by: you06 <you1474600@gmail.com>
| // do it when val exists | ||
| if !lock_only_if_exists || val.is_some() { | ||
| if is_shared_lock_req { | ||
| txn.put_shared_pessimistic_lock(key, current_shared_locks, lock); |
There was a problem hiding this comment.
Would the other path like cleanup.rs, scan_locks panic because of LockType::Shared is unimplemented! for them by now?
There was a problem hiding this comment.
If there is a shared lock in the storage engine, some unimplemented! will panic. But no client can write shared locks by now.
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
|
/retest |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cfzjywxk, zyguan The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…rs (tikv#19282) ref tikv#19087 This PR implement the acquire_pessimistic_lock / prewrite / commit schedulers for shared lock. Signed-off-by: you06 <you1474600@gmail.com>
…rs (tikv#19282) ref tikv#19087 This PR implement the acquire_pessimistic_lock / prewrite / commit schedulers for shared lock. Signed-off-by: you06 <you1474600@gmail.com>
ref tikv#19087 Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
|
In response to a cherrypick label: new pull request created to branch |
…rs (tikv#19282) ref tikv#19087 This PR implement the acquire_pessimistic_lock / prewrite / commit schedulers for shared lock. Signed-off-by: you06 <you1474600@gmail.com>
What is changed and how it works?
Issue Number: ref #19087
What's Changed:
Related changes
pingcap/docs/pingcap/docs-cn:Check List
Tests
Side effects
Release note