Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concurrency: integrate lock modes with SKIP LOCKED #108715

Closed
arulajmani opened this issue Aug 14, 2023 · 0 comments · Fixed by #108918
Closed

concurrency: integrate lock modes with SKIP LOCKED #108715

arulajmani opened this issue Aug 14, 2023 · 0 comments · Fixed by #108918
Assignees
Labels
A-kv-transactions Relating to MVCC and the transactional model. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-kv KV Team

Comments

@arulajmani
Copy link
Collaborator

arulajmani commented Aug 14, 2023

Describe the problem

Currently, SKIP LOCKED (via IsKeyLockedByConflictingTxn) performs bespoke conflict resolution, around:

// Key locked.
txn, ts := l.getLockHolder()
if strength == lock.None && g.ts.Less(ts) {
// Non-locking read below lock's timestamp.
return false, nil
}
if g.isSameTxn(txn) {
// Already locked by this txn.
return false, nil
}
// "If the key is locked, the lock holder is also returned."
return true, txn
}

This bakes in the assumption that the lock is of strength Exclusive/Intent. As such, SKIP LOCKED doesn't account for other lock strengths (notably Shared) correctly. We should switch out this function to make use of lock modes instead.

Jira issue: CRDB-30609

@arulajmani arulajmani added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. A-kv-transactions Relating to MVCC and the transactional model. T-kv KV Team labels Aug 14, 2023
@arulajmani arulajmani self-assigned this Aug 14, 2023
arulajmani added a commit to arulajmani/cockroach that referenced this issue Aug 17, 2023
This patch switches isKeyLockedByConflictingTxn to make use of lock
modes to detect conflicts. As a result, SKIP LOCKED requests correctly
interact with shared locks. We add a few tests to demonstrate this.

Fixes cockroachdb#108715

Release note: None
craig bot pushed a commit that referenced this issue Aug 19, 2023
108918: concurrency: use lock modes to detect conflicts in SKIP LOCKED r=nvanbenschoten a=arulajmani

This patch switches isKeyLockedByConflictingTxn to make use of lock modes to detect conflicts. As a result, SKIP LOCKED requests correctly interact with shared locks. We add a few tests to demonstrate this.

Fixes #108715

Release note: None

Co-authored-by: Arul Ajmani <[email protected]>
@craig craig bot closed this as completed in 6342e6f Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-kv-transactions Relating to MVCC and the transactional model. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-kv KV Team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant