Skip to content

Commit

Permalink
sql: introduce crdb_internal.cluster_locks virtual table
Browse files Browse the repository at this point in the history
This change introduces the new virtual table
`crdb_internal.cluster_locks`, as proposed in the KV Lock Observability
RFC (#75541), to expose lock contention.  This virtual table displays
the locks currently tracked in the lock tables in ranges across a
cluster, utilizing the KV `QueryLocksRequest` API to gather information
on the lock holders as well as the operations waiting on the locks
before converting to a user-friendly SQL view that incorporates
information about the database, table, schema, and index.

For example,
```
root@localhost:26261/defaultdb> select range_id, table_name, lock_key_pretty, txn_id, ts, lock_strength, durability, granted, contended, duration from crdb_internal.cluster_locks;
  range_id | table_name |     lock_key_pretty      |                txn_id                |             ts             | lock_strength | durability | granted | contended |    duration
-----------+------------+--------------------------+--------------------------------------+----------------------------+---------------+------------+---------+-----------+------------------
       235 | kv         | /Table/115/1/"alex"/0    | 7471e67b-bbc3-4dd9-a42f-43ec97949b14 | 2022-03-26 00:23:45.916745 | Exclusive     | Replicated |  true   |   true    | 00:01:50.607386
       235 | kv         | /Table/115/1/"alex"/0    | d71ea8eb-21b9-48a0-98b6-82eed84ed76f | 2022-03-26 00:24:02.137125 | None          | Replicated |  false  |   true    | 00:01:50.607376
       235 | kv         | /Table/115/1/"bob"/0     | 7471e67b-bbc3-4dd9-a42f-43ec97949b14 | 2022-03-26 00:23:45.916745 | Exclusive     | Replicated |  true   |   false   | 00:01:50.607384
       235 | kv         | /Table/115/1/"chris"/0   | 7471e67b-bbc3-4dd9-a42f-43ec97949b14 | 2022-03-26 00:23:45.916745 | Exclusive     | Replicated |  true   |   false   | 00:01:50.607383
       255 | kv         | /Table/115/1/"lauren"/0  | 7471e67b-bbc3-4dd9-a42f-43ec97949b14 | 2022-03-26 00:23:45.819704 | Exclusive     | Replicated |  true   |   true    | 00:01:50.607757
       255 | kv         | /Table/115/1/"lauren"/0  | d71ea8eb-21b9-48a0-98b6-82eed84ed76f | 2022-03-26 00:24:02.137125 | None          | Replicated |  false  |   true    | 00:01:50.60773
       255 | kv         | /Table/115/1/"marilyn"/0 | 7471e67b-bbc3-4dd9-a42f-43ec97949b14 | 2022-03-26 00:23:45.819704 | Exclusive     | Replicated |  true   |   false   | 00:01:50.607755
       255 | kv         | /Table/115/1/"mike"/0    | 7471e67b-bbc3-4dd9-a42f-43ec97949b14 | 2022-03-26 00:23:45.819704 | Exclusive     | Replicated |  true   |   false   | 00:01:50.607754
       255 | kv         | /Table/115/1/"nancy"/0   | 7471e67b-bbc3-4dd9-a42f-43ec97949b14 | 2022-03-26 00:23:45.819704 | Exclusive     | Replicated |  true   |   false   | 00:01:50.607745
       255 | kv         | /Table/115/1/"noah"/0    | 7471e67b-bbc3-4dd9-a42f-43ec97949b14 | 2022-03-26 00:23:45.819704 | Exclusive     | Replicated |  true   |   false   | 00:01:50.607744
       255 | kv         | /Table/115/1/"paul"/0    | 7471e67b-bbc3-4dd9-a42f-43ec97949b14 | 2022-03-26 00:23:45.819704 | Exclusive     | Replicated |  true   |   false   | 00:01:50.607744
       255 | kv         | /Table/115/1/"peter"/0   | 7471e67b-bbc3-4dd9-a42f-43ec97949b14 | 2022-03-26 00:23:45.819704 | Exclusive     | Replicated |  true   |   false   | 00:01:50.607743
       256 | kv         | /Table/115/1/"sam"/0     | 7471e67b-bbc3-4dd9-a42f-43ec97949b14 | 2022-03-26 00:23:45.740235 | Exclusive     | Replicated |  true   |   true    | 00:01:50.607582
       256 | kv         | /Table/115/1/"sam"/0     | d71ea8eb-21b9-48a0-98b6-82eed84ed76f | 2022-03-26 00:24:02.137125 | None          | Replicated |  false  |   true    | 00:01:50.607573
       256 | kv         | /Table/115/1/"thomas"/0  | 7471e67b-bbc3-4dd9-a42f-43ec97949b14 | 2022-03-26 00:23:45.740235 | Exclusive     | Replicated |  true   |   false   | 00:01:50.607581
       256 | kv         | /Table/115/1/"zebra"/0   | 7471e67b-bbc3-4dd9-a42f-43ec97949b14 | 2022-03-26 00:23:45.740235 | Exclusive     | Replicated |  true   |   false   | 00:01:50.60758
(16 rows)
```

This internal table is usable for system tenants as well as secondary
tenants.  It is also useful in conjunction with other
`crdb_internal.cluster_*` tables used for observability, and also can be
joined with itself to visualize blocked operations, and the transactions
that are blocking them.  This feature is gated on v22.1, to ensure that
older nodes will not receive `kv.Batch` requests with
`QueryLocksRequest`s in them.

Closes #74834

Release justification: Low risk, high benefit change.
Release note (sql change): TBD
  • Loading branch information
AlexTalks committed Mar 26, 2022
1 parent 6621bc6 commit a5ba1d0
Show file tree
Hide file tree
Showing 14 changed files with 2,092 additions and 1,767 deletions.
2 changes: 1 addition & 1 deletion docs/generated/settings/settings-for-tenants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ trace.jaeger.agent string the address of a Jaeger agent to receive traces using
trace.opentelemetry.collector string address of an OpenTelemetry trace collector to receive traces using the otel gRPC protocol, as <host>:<port>. If no port is specified, 4317 will be used.
trace.span_registry.enabled boolean true if set, ongoing traces can be seen at https://<ui>/#/debug/tracez
trace.zipkin.collector string the address of a Zipkin instance to receive traces, as <host>:<port>. If no port is specified, 9411 will be used.
version version 21.2-94 set the active cluster version in the format '<major>.<minor>'
version version 21.2-98 set the active cluster version in the format '<major>.<minor>'
2 changes: 1 addition & 1 deletion docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,6 @@
<tr><td><code>trace.opentelemetry.collector</code></td><td>string</td><td><code></code></td><td>address of an OpenTelemetry trace collector to receive traces using the otel gRPC protocol, as <host>:<port>. If no port is specified, 4317 will be used.</td></tr>
<tr><td><code>trace.span_registry.enabled</code></td><td>boolean</td><td><code>true</code></td><td>if set, ongoing traces can be seen at https://<ui>/#/debug/tracez</td></tr>
<tr><td><code>trace.zipkin.collector</code></td><td>string</td><td><code></code></td><td>the address of a Zipkin instance to receive traces, as <host>:<port>. If no port is specified, 9411 will be used.</td></tr>
<tr><td><code>version</code></td><td>version</td><td><code>21.2-94</code></td><td>set the active cluster version in the format '<major>.<minor>'</td></tr>
<tr><td><code>version</code></td><td>version</td><td><code>21.2-98</code></td><td>set the active cluster version in the format '<major>.<minor>'</td></tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ crdb_internal cluster_contention_events table NULL NULL NULL
crdb_internal cluster_database_privileges table NULL NULL NULL
crdb_internal cluster_distsql_flows table NULL NULL NULL
crdb_internal cluster_inflight_traces table NULL NULL NULL
crdb_internal cluster_locks table NULL NULL NULL
crdb_internal cluster_queries table NULL NULL NULL
crdb_internal cluster_sessions table NULL NULL NULL
crdb_internal cluster_settings table NULL NULL NULL
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/zip_cluster_wide.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var debugZipTablesPerCluster = []string{
"crdb_internal.cluster_contention_events",
"crdb_internal.cluster_distsql_flows",
"crdb_internal.cluster_database_privileges",
"crdb_internal.cluster_locks",
"crdb_internal.cluster_queries",
"crdb_internal.cluster_sessions",
"crdb_internal.cluster_settings",
Expand Down
9 changes: 8 additions & 1 deletion pkg/clusterversion/cockroach_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,14 @@ var versionsSingleton = keyedVersions{
Key: DateStyleIntervalStyleCastRewrite,
Version: roachpb.Version{Major: 21, Minor: 2, Internal: 94},
},

{
Key: EnableNewStoreRebalancer,
Version: roachpb.Version{Major: 21, Minor: 2, Internal: 96},
},
{
Key: ClusterLocksVirtualTable,
Version: roachpb.Version{Major: 21, Minor: 2, Internal: 98},
},
// *************************************************
// Step (2): Add new versions here.
// Do not add new versions to a patch release.
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/catalog/catconstants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const (
CrdbInternalClusterContendedTablesViewID
CrdbInternalClusterContentionEventsTableID
CrdbInternalClusterDistSQLFlowsTableID
CrdbInternalClusterLocksTableID
CrdbInternalClusterQueriesTableID
CrdbInternalClusterTransactionsTableID
CrdbInternalClusterSessionsTableID
Expand Down
Loading

0 comments on commit a5ba1d0

Please sign in to comment.