-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
109638: sql: use the correct locking strength for FOR SHARE clause r=michae2 a=arulajmani 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. By default, we turn of this functionality for serializable transactions. Instead, it's gated behind a session setting called `enable_shared_locking_for_serializable`. Informs #91545 Release note (sql change): SELECT FOR SHARE and SELECT FOR UPDATE previously did not acquire any locks. Users issuing these statements would expect them to acquire shared locks (multiple readers allowed, no writers though). This patch switches over the behavior to acquire such read locks. For serializable transactions, we default to the old behaviour, unless the `enable_shared_locking_for_serializable` session setting is set to true. We'll probably switch this behavior in the future, but for now, given shared locks are a preview feature, we gate things behind a session setting. 111441: goschedstats: reduce underloadedRunnablePerProcThreshold r=aadityasondhi a=sumeerbhola By reducing this threshold, we more often sample the stats at 1ms intervals, which is desirable for admission control slot adjustment. Fixes #111125 Epic: none Release note: None 111466: ui: update default timescale to 1h r=maryliag a=maryliag On the Metrics page, the default value was 10min, which was too small. This commit updates it to 1h to match the most selected value on the SQL Activity. Fixes #96479 Release note: None 111521: roachprod: fix createTenantCertBundle script r=andy-kimball a=herkolategan The `createTenantCertBundle` function has a script in it that has erroneous "+" characters which results in an error when trying to start a secure cluster. This change removes those characters. Epic: None Release Note: None 111526: kv/spanset: permit writes to lock table by shared lock latching configuration r=nvanbenschoten a=nvanbenschoten Fixes #111409. Fixes #111492. This commit updates addLockTableSpans to account for the way that shared locking requests declare their latches. Even though they declare a "read" latch, they do so at max timestamp, which gives them sufficient isolation to write to the lock table without having to declare a write latch and be serialized with other shared lock acquisitions. Release note: None Co-authored-by: Arul Ajmani <[email protected]> Co-authored-by: sumeerbhola <[email protected]> Co-authored-by: maryliag <[email protected]> Co-authored-by: Herko Lategan <[email protected]> Co-authored-by: Nathan VanBenschoten <[email protected]>
- Loading branch information
Showing
35 changed files
with
363 additions
and
54 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# LogicTest: !local-mixed-22.2-23.1 | ||
|
||
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 SYSTEM MODIFYCLUSTERSETTING TO testuser; | ||
GRANT ALL ON t TO testuser2; | ||
|
||
user testuser | ||
|
||
statement ok | ||
SET enable_shared_locking_for_serializable = true; | ||
|
||
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 | ||
SET enable_shared_locking_for_serializable = true; | ||
|
||
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; We'll also only report a single holder (the other row in there is | ||
# the waiting UPDATE request, not the second shared lock holder). However, | ||
# having this query in here is useful to make sure there are locks and waiters | ||
# on our key, meaning 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 | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Tests to ensure the enable_shared_locking_for_serializable session variable | ||
# works as expected. | ||
# ----------------------------------------------------------------------------- | ||
|
||
user testuser | ||
|
||
statement ok | ||
SET enable_shared_locking_for_serializable = false | ||
|
||
statement ok | ||
BEGIN ISOLATION LEVEL SERIALIZABLE | ||
|
||
query I | ||
SELECT * FROM t WHERE a = 2 FOR SHARE | ||
---- | ||
2 | ||
|
||
user testuser2 | ||
|
||
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 | ||
|
||
user testuser | ||
|
||
statement ok | ||
COMMIT | ||
|
||
# TODO(arul): Add a test to show that the session setting doesn't apply to read | ||
# committed transactions. We currently can't issue SELECT FOR SHARE statements | ||
# in read committed transactions because durable locking hasn't been fully | ||
# hooked up. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
pkg/sql/logictest/tests/local-legacy-schema-changer/generated_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.