Skip to content

txn: implement rollback, cleanup and lock resolving for shared locks#19149

Merged
you06 merged 7 commits intotikv:tikv-8.5-with-shared-lockfrom
you06:dev/resolve-shared-lock
Dec 3, 2025
Merged

txn: implement rollback, cleanup and lock resolving for shared locks#19149
you06 merged 7 commits intotikv:tikv-8.5-with-shared-lockfrom
you06:dev/resolve-shared-lock

Conversation

@you06
Copy link
Contributor

@you06 you06 commented Nov 27, 2025

What is changed and how it works?

Issue Number: ref #19087

What's Changed:

Implement rollback, cleanup and lock resolving for shared locks.

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

zyguan and others added 4 commits November 27, 2025 18:43
Signed-off-by: zyguan <zhongyangguan@gmail.com>
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 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 Nov 27, 2025
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Nov 28, 2025
Comment on lines +402 to +403
// `protected` is always false for a shared lock
assert!(!key.is_encoded_from(&lock.primary));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it guaranteed that a shared lock is never the primary of a 2PC transaction?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 If so, then how does it determine the primary when a transaction's first batch of locks are shared locks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's fine for foreign key usage because the shared lock(parent table) is always acquired after an exclusive lock(child table).

For select for share usage, we may unlock this limitation or use a fake primary key (e.g. pk_start_ts).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And for simplicity, it doesn't acquire exclusive lock and share lock in one rpc call by now.

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

@cfzjywxk cfzjywxk left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 1, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Dec 1, 2025

[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
Copy link
Contributor

ti-chi-bot bot commented Dec 1, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-11-28 06:49:51.661818519 +0000 UTC m=+858355.311012966: ☑️ agreed by zyguan.
  • 2025-12-01 12:02:10.610650238 +0000 UTC m=+264875.424427820: ☑️ agreed by cfzjywxk.

Signed-off-by: you06 <you1474600@gmail.com>
@you06 you06 merged commit f01c91d into tikv:tikv-8.5-with-shared-lock Dec 3, 2025
2 of 3 checks passed
@zyguan zyguan mentioned this pull request Dec 5, 2025
13 tasks
you06-pingcap pushed a commit to you06/tikv that referenced this pull request Jan 21, 2026
…ikv#19149)

* txn: partially support shared lock for lock resolving

Signed-off-by: zyguan <zhongyangguan@gmail.com>

* add test for resolving locks

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

* impl pessimistic rollback

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

* fix lock test

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

* fix scan lock & address comment

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

* impl resolve lock read phases & add tests

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

* do not cast embed locks to shared types

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

---------

Signed-off-by: zyguan <zhongyangguan@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Co-authored-by: zyguan <zhongyangguan@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 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.

4 participants