Skip to content

txn_types: add shrink-only flag to shared locks#19280

Merged
ti-chi-bot[bot] merged 2 commits intotikv:masterfrom
zyguan:dev/slock-flags
Jan 15, 2026
Merged

txn_types: add shrink-only flag to shared locks#19280
ti-chi-bot[bot] merged 2 commits intotikv:masterfrom
zyguan:dev/slock-flags

Conversation

@zyguan
Copy link
Contributor

@zyguan zyguan commented Jan 13, 2026

What is changed and how it works?

Issue Number: ref #19087

What's Changed:

Introduce shrink-only flag to 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

Signed-off-by: zyguan <zhongyangguan@gmail.com>
Copilot AI review requested due to automatic review settings January 13, 2026 05:19
@ti-chi-bot ti-chi-bot bot added dco-signoff: yes Indicates the PR's author has signed the dco. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. 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 PR introduces a shrink-only flag to shared locks as part of the broader effort to support shared locks for foreign key constraints (issue #19087). The shrink-only flag prevents new shared locks from being added to a SharedLocks instance once set, enabling specific lock management patterns needed for foreign key constraint handling.

Changes:

  • Added a SharedLocksFlags bitflags type with a SHRINK_ONLY flag to control whether new shared locks can be added
  • Modified put_shared_lock method to return Result<()> and fail when attempting to add locks to a shrink-only instance
  • Added a new SharedLocksAreShrinkOnly error type with appropriate error handling and conversion logic
  • Updated serialization/deserialization to persist the flags field with forward compatibility support

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
components/txn_types/src/lock.rs Core implementation of shrink-only flag including bitflags definition, SharedLocks struct modification, put_shared_lock API change, serialization/deserialization updates, and comprehensive unit tests
components/txn_types/src/lib.rs New error type definition with appropriate error code mapping and cloning support
src/storage/mvcc/mod.rs Error conversion logic to handle SharedLocksAreShrinkOnly as an internal error

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -774,12 +812,15 @@ impl SharedLocks {
}

#[inline]
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The method signature has changed to return a Result, but there is no documentation explaining when this method can fail. Consider adding a doc comment that explains the method can return an error when attempting to add a lock to a shrink-only SharedLocks instance.

Suggested change
#[inline]
#[inline]
/// Inserts a shared lock into this `SharedLocks` collection.
///
/// # Errors
///
/// Returns an error if this `SharedLocks` instance is marked as shrink-only
/// and cannot accept new locks, in which case `ErrorInner::SharedLocksAreShrinkOnly`
/// is returned.

Copilot uses AI. Check for mistakes.
Comment on lines +749 to +754
#[inline]
pub fn is_shrink_only(&self) -> bool {
self.flags.contains(SharedLocksFlags::SHRINK_ONLY)
}

#[inline]
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

These public methods lack documentation. Consider adding doc comments explaining what the shrink-only flag means and its intended usage, especially since this is a public API that will be used by other parts of the codebase.

Suggested change
#[inline]
pub fn is_shrink_only(&self) -> bool {
self.flags.contains(SharedLocksFlags::SHRINK_ONLY)
}
#[inline]
#[inline]
/// Returns whether this shared-lock set is marked as *shrink-only*.
///
/// When a `SharedLocks` instance is in shrink-only mode, it is only expected
/// to have entries removed (i.e. the set of held shared locks may shrink)
/// and should not grow with new shared-lock entries. Callers can use this
/// flag to coordinate flows where shared locks are being cleaned up or
/// finalized and no new shared locks should be appended.
pub fn is_shrink_only(&self) -> bool {
self.flags.contains(SharedLocksFlags::SHRINK_ONLY)
}
#[inline]
/// Marks this shared-lock set as *shrink-only*.
///
/// After calling this, the `SharedLocks` value should only be modified by
/// removing existing shared-lock entries, not by inserting new ones. This
/// is typically used in code paths that are shrinking or cleaning up the
/// shared locks and want to prevent further expansion of the lock set.

Copilot uses AI. Check for mistakes.
Signed-off-by: zyguan <zhongyangguan@gmail.com>
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 15, 2026
@zyguan zyguan requested a review from cfzjywxk January 15, 2026 04:20
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jan 15, 2026
@ti-chi-bot ti-chi-bot bot added the lgtm label Jan 15, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 15, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, you06

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 15, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 15, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-01-15 04:25:25.344124233 +0000 UTC m=+35952.958081089: ☑️ agreed by you06.
  • 2026-01-15 07:06:45.160333957 +0000 UTC m=+45632.774290833: ☑️ agreed by cfzjywxk.

@ti-chi-bot ti-chi-bot bot merged commit a5f0d1a into tikv:master Jan 15, 2026
8 of 9 checks passed
@ti-chi-bot ti-chi-bot bot added this to the Pool milestone Jan 15, 2026
@you06 you06 mentioned this pull request Feb 24, 2026
13 tasks
you06-pingcap pushed a commit to you06/tikv that referenced this pull request Mar 4, 2026
ref tikv#19087

Introduce shrink-only flag to shared locks.

Signed-off-by: zyguan <zhongyangguan@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
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #19424.

ti-chi-bot bot pushed a commit that referenced this pull request Mar 4, 2026
ref #19087

Introduce shrink-only flag to shared locks.

Signed-off-by: zyguan <zhongyangguan@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 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants