Skip to content

txn: support shared lock for pessimistic / prewrite / commit schedulers#19282

Merged
ti-chi-bot[bot] merged 14 commits intotikv:masterfrom
you06:master-shared-lock/schedulers-1
Jan 20, 2026
Merged

txn: support shared lock for pessimistic / prewrite / commit schedulers#19282
ti-chi-bot[bot] merged 14 commits intotikv:masterfrom
you06:master-shared-lock/schedulers-1

Conversation

@you06
Copy link
Contributor

@you06 you06 commented Jan 13, 2026

What is changed and how it works?

Issue Number: ref #19087

What's Changed:

This PR implement the acquire_pessimistic_lock / prewrite / commit schedulers for shared lock.

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Release note

None

Copilot AI review requested due to automatic review settings January 13, 2026 10:57
@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the dco. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jan 13, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SharedLock variant to Mutation enum and related type handling
  • Implements shared lock acquisition logic in acquire_pessimistic_lock action
  • 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 SharedLocks type 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.

you06 added 2 commits January 13, 2026 22:38
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
@you06-pingcap you06-pingcap force-pushed the master-shared-lock/schedulers-1 branch from 4858a0d to 57dab48 Compare January 13, 2026 16:44
you06 added 3 commits January 14, 2026 12:52
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
@you06
Copy link
Contributor Author

you06 commented Jan 14, 2026

/retest

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

you06 and others added 2 commits January 14, 2026 18:08
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the other path like cleanup.rs, scan_locks panic because of LockType::Shared is unimplemented! for them by now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a shared lock in the storage engine, some unimplemented! will panic. But no client can write shared locks by now.

you06 added 4 commits January 15, 2026 16:11
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
@zyguan
Copy link
Contributor

zyguan commented Jan 15, 2026

/retest

you06 added 3 commits January 15, 2026 20:50
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jan 16, 2026
@you06 you06 requested a review from cfzjywxk January 19, 2026 06:47
@ti-chi-bot ti-chi-bot bot added the lgtm label Jan 20, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 20, 2026

[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

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 removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jan 20, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 20, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-01-16 06:24:38.459903742 +0000 UTC m=+129506.073860598: ☑️ agreed by zyguan.
  • 2026-01-20 11:42:37.519597781 +0000 UTC m=+494185.133554637: ☑️ agreed by cfzjywxk.

@ti-chi-bot ti-chi-bot bot merged commit 94acffc into tikv:master Jan 20, 2026
9 checks passed
@ti-chi-bot ti-chi-bot bot added this to the Pool milestone Jan 20, 2026
wshwsh12 pushed a commit to wshwsh12/tikv that referenced this pull request Feb 9, 2026
…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>
you06-pingcap pushed a commit to you06/tikv that referenced this pull request Mar 4, 2026
…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>
@you06 you06 added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Mar 4, 2026
ti-chi-bot pushed a commit to ti-chi-bot/tikv that referenced this pull request Mar 4, 2026
ref tikv#19087

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #19423.
But this PR has conflicts, please resolve them!

@you06 you06 mentioned this pull request Mar 4, 2026
13 tasks
you06-pingcap pushed a commit to you06/tikv that referenced this pull request Mar 4, 2026
…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>
ti-chi-bot bot pushed a commit that referenced this pull request Mar 6, 2026
…rs (#19282) (#19423)

ref #19087

This PR implement the acquire_pessimistic_lock / prewrite / commit schedulers for shared lock.

Signed-off-by: you06 <you1474600@gmail.com>

Co-authored-by: you06 <you1474600@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants