-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
Previously, FOR SHARE and FOR KEY SHARE would use non-locking KV scans. Now that the lock table supports shared locks, we can use lock.Shared as the locking strength for KV scans. This patch does that, and in doing so, wires up SHARED locks end to end. Informs #91545 Release note: None
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# LogicTest: !local-mixed-22.2-23.1 | ||
|
||
statement ok | ||
SET CLUSTER SETTING sql.locking.enable_shared_locks = true | ||
|
||
statement ok | ||
CREATE TABLE t(a INT PRIMARY KEY); | ||
INSERT INTO t VALUES(1); | ||
GRANT ALL ON t TO testuser; | ||
CREATE USER testuser2 WITH VIEWACTIVITY; | ||
GRANT ALL ON t TO testuser2; | ||
|
||
user testuser | ||
|
||
statement ok | ||
BEGIN | ||
|
||
query I | ||
SELECT * FROM t WHERE a = 1 FOR SHARE; | ||
---- | ||
1 | ||
|
||
# Start another transaction to show multiple transactions can acquire SHARED | ||
# locks at the same time. | ||
|
||
user root | ||
|
||
statement ok | ||
BEGIN | ||
|
||
query I | ||
SELECT * FROM t WHERE a = 1 FOR SHARE; | ||
---- | ||
1 | ||
|
||
user testuser2 | ||
|
||
statement async writeReq count 1 | ||
UPDATE t SET a = 2 WHERE a = 1 | ||
|
||
# TODO(arul): Until https://github.com/cockroachdb/cockroach/issues/107766 is | ||
# addressed, we'll incorrectly report shared locks as having "Exclusive" lock | ||
# strength; however, having this query in here is useful to make sure there are | ||
# two locks on our key and setting the cluster setting above actually did | ||
# something; otherwise, had we used non-locking reads, we'd have failed here. | ||
query TTTTTTTBB colnames,retry,rowsort | ||
SELECT database_name, schema_name, table_name, lock_key_pretty, lock_strength, durability, isolation_level, granted, contended FROM crdb_internal.cluster_locks | ||
---- | ||
database_name schema_name table_name lock_key_pretty lock_strength durability isolation_level granted contended | ||
test public t /Table/106/1/1/0 Exclusive Unreplicated SERIALIZABLE true true | ||
test public t /Table/106/1/1/0 Exclusive Unreplicated SERIALIZABLE false true | ||
|
||
# Commit the first transaction and rollback the second. | ||
|
||
user testuser | ||
|
||
statement ok | ||
COMMIT | ||
|
||
user root | ||
|
||
statement ok | ||
ROLLBACK | ||
|
||
user testuser2 | ||
|
||
# Now that both the transactions that issued shared lock reads have been | ||
# finalized, the write should be able to proceed. | ||
|
||
awaitstatement writeReq | ||
|
||
query I | ||
SELECT * FROM t; | ||
---- | ||
2 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.