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

storage: add MVCCCheckLock and MVCCAcquireLock functions #109646

Closed
nvanbenschoten opened this issue Aug 29, 2023 · 0 comments · Fixed by #110323
Closed

storage: add MVCCCheckLock and MVCCAcquireLock functions #109646

nvanbenschoten opened this issue Aug 29, 2023 · 0 comments · Fixed by #110323
Assignees
Labels
A-kv-transactions Relating to MVCC and the transactional model. A-read-committed Related to the introduction of Read Committed C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-kv KV Team

Comments

@nvanbenschoten
Copy link
Member

nvanbenschoten commented Aug 29, 2023

As part of #100193, we will need to add two new MVCC functions:

// MVCCCheckLock checks for conflicting locks which would prevent acquisition of a
// lock on the key by the specified transaction and with the specified strength. If
// such conflicts are found, a LockConflictError is returned.
MVCCCheckLock(reader, txnID, strength, key)

// MVCCAcquireLock checks for conflicting locks which would prevent acquisition of a
// lock on the key by the specified transaction and with the specified strength. If
// such conflicts are found, a LockConflictError is returned. Otherwise, the lock is
// acquired by writing to the lock table in the provided Writer.
MVCCAcquireLock(readWriter, txnID, strength, key)

Testing for these functions will be predominantly through TestMVCCHistories.

Jira issue: CRDB-31030

Epic CRDB-26544

@nvanbenschoten nvanbenschoten added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-kv-transactions Relating to MVCC and the transactional model. T-kv KV Team A-read-committed Related to the introduction of Read Committed labels Aug 29, 2023
@nvanbenschoten nvanbenschoten self-assigned this Aug 29, 2023
nvanbenschoten added a commit to nvanbenschoten/cockroach that referenced this issue Sep 11, 2023
Fixes cockroachdb#109646.
Informs cockroachdb#100193.

This commit adds and implements two new MVCC functions: `MVCCCheckAcquireLock`
and `MVCCAcquireLock`. The former scans the replicated lock table to determine
whether a lock acquisition is permitted. It will be used by unreplicated lock
acquisition. The latter does the same, but then also writes the lock to the
replicated lock table if permitted. It will be used by replicated lock
acquisition.

MVCCStats handling is left as a TODO for after cockroachdb#109645 is addressed.

----

The two functions are build using a new abstraction, the `lockTableKeyScanner`.

The lockTableKeyScanner uses a LockTableIterator to scan a single key in the
replicated lock table. It searches for locks on the key that conflict with a
(transaction, lock strength) pair and for locks that the transaction has already
acquired on the key.

The purpose of a lockTableKeyScanner is to determine whether a transaction can
acquire a lock on a key or perform an MVCC mutation on a key, and if so, what
lock table keys the transaction should write to perform the operation. It is
used by this commit to implement the two new MVCC functions. In a future commit,
it will also start to be used by `mvccPutInternal`, the kernel of all MVCC
mutations.

Release note: None
nvanbenschoten added a commit to nvanbenschoten/cockroach that referenced this issue Sep 13, 2023
Fixes cockroachdb#109646.
Informs cockroachdb#100193.

This commit adds and implements two new MVCC functions: `MVCCCheckAcquireLock`
and `MVCCAcquireLock`. The former scans the replicated lock table to determine
whether a lock acquisition is permitted. It will be used by unreplicated lock
acquisition. The latter does the same, but then also writes the lock to the
replicated lock table if permitted. It will be used by replicated lock
acquisition.

MVCCStats handling is left as a TODO for after cockroachdb#109645 is addressed.

----

The two functions are build using a new abstraction, the `lockTableKeyScanner`.

The lockTableKeyScanner uses a LockTableIterator to scan a single key in the
replicated lock table. It searches for locks on the key that conflict with a
(transaction, lock strength) pair and for locks that the transaction has already
acquired on the key.

The purpose of a lockTableKeyScanner is to determine whether a transaction can
acquire a lock on a key or perform an MVCC mutation on a key, and if so, what
lock table keys the transaction should write to perform the operation. It is
used by this commit to implement the two new MVCC functions. In a future commit,
it will also start to be used by `mvccPutInternal`, the kernel of all MVCC
mutations.

Release note: None
nvanbenschoten added a commit to nvanbenschoten/cockroach that referenced this issue Sep 14, 2023
Fixes cockroachdb#109646.
Informs cockroachdb#100193.

This commit adds and implements two new MVCC functions: `MVCCCheckForAcquireLock`
and `MVCCAcquireLock`. The former scans the replicated lock table to determine
whether a lock acquisition is permitted. It will be used by unreplicated lock
acquisition. The latter does the same, but then also writes the lock to the
replicated lock table if permitted. It will be used by replicated lock
acquisition.

MVCCStats handling is left as a TODO for after cockroachdb#109645 is addressed.

----

The two functions are built using a new abstraction, the `lockTableKeyScanner`.

The lockTableKeyScanner uses a LockTableIterator to scan a single key in the
replicated lock table. It searches for locks on the key that conflict with a
(transaction, lock strength) pair and for locks that the transaction has already
acquired on the key.

The purpose of a lockTableKeyScanner is to determine whether a transaction can
acquire a lock on a key or perform an MVCC mutation on a key, and if so, what
lock table keys the transaction should write to perform the operation. It is
used by this commit to implement the two new MVCC functions. In a future commit,
it will also start to be used by `mvccPutInternal`, the kernel of all MVCC
mutations.

Release note: None
nvanbenschoten added a commit to nvanbenschoten/cockroach that referenced this issue Sep 14, 2023
Fixes cockroachdb#109646.
Informs cockroachdb#100193.

This commit adds and implements two new MVCC functions: `MVCCCheckForAcquireLock`
and `MVCCAcquireLock`. The former scans the replicated lock table to determine
whether a lock acquisition is permitted. It will be used by unreplicated lock
acquisition. The latter does the same, but then also writes the lock to the
replicated lock table if permitted. It will be used by replicated lock
acquisition.

MVCCStats handling is left as a TODO for after cockroachdb#109645 is addressed.

----

The two functions are built using a new abstraction, the `lockTableKeyScanner`.

The lockTableKeyScanner uses a LockTableIterator to scan a single key in the
replicated lock table. It searches for locks on the key that conflict with a
(transaction, lock strength) pair and for locks that the transaction has already
acquired on the key.

The purpose of a lockTableKeyScanner is to determine whether a transaction can
acquire a lock on a key or perform an MVCC mutation on a key, and if so, what
lock table keys the transaction should write to perform the operation. It is
used by this commit to implement the two new MVCC functions. In a future commit,
it will also start to be used by `mvccPutInternal`, the kernel of all MVCC
mutations.

Release note: None
craig bot pushed a commit that referenced this issue Sep 14, 2023
110323: storage: add MVCCCheckForAcquireLock and MVCCAcquireLock functions r=nvanbenschoten a=nvanbenschoten

Fixes #109646.
Informs #100193.

This PR adds and implements two new MVCC functions: `MVCCCheckForAcquireLock` and `MVCCAcquireLock`. The former scans the replicated lock table to determine whether a lock acquisition is permitted. It will be used by unreplicated lock acquisition. The latter does the same, but then also writes the lock to the replicated lock table if permitted. It will be used by replicated lock acquisition.

MVCCStats handling is left as a TODO for after #109645 is addressed.

----

The two functions are built using a new abstraction, the `lockTableKeyScanner`.

The `lockTableKeyScanner` uses a `LockTableIterator` to scan a single key in the replicated lock table. It searches for locks on the key that conflict with a (transaction, strength) pair and for locks that the transaction has already acquired on the key.

The purpose of a `lockTableKeyScanner` is to determine whether a transaction can acquire a lock on a key or perform an MVCC mutation on a key, and if so, what lock table keys the transaction should write to perform the operation. It is used by this commit to implement the two new MVCC functions. In a future commit, it will also start to be used by `mvccPutInternal`, the kernel of all MVCC mutations.

Release note: None

110652: kvserver: get Stats and GCHint under same RLock r=erikgrinaker a=pavelkalinnikov

Before this commit, `makeMVCCGCQueueScore` unlocked `Replica.mu` between reading `ReplicaState.Stats` and `ReplicaState.GCHint`. The GC scoring function uses both fields, we would like them to be in sync. The unlock makes it possible for `Stats` and `GCHint` to correspond to different states of the `Replica`.

This commit moves both reads under the same `RLock`/`RUnlock`.

Epic: none
Release note: none

Co-authored-by: Nathan VanBenschoten <[email protected]>
Co-authored-by: Pavel Kalinnikov <[email protected]>
@craig craig bot closed this as completed in e329dbf Sep 14, 2023
@github-project-automation github-project-automation bot moved this to Closed in KV Aug 28, 2024
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. A-read-committed Related to the introduction of Read Committed C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-kv KV Team
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant