Skip to content

Commit

Permalink
Merge #76719
Browse files Browse the repository at this point in the history
76719: sql: extend resolverQueue to support waiter transactions r=Azhng a=Azhng

Reviewer note: only last two commits are relevant

---

# First commit

sql: add waiter txn id to extended contention event

Previously, contention event only include the txnID of the transaction
that held the lock (a.k.a. blocking transaction). The txnID of the
waiter transaction is missing from the contention event.

This commit includes the txnID of the waiter transaction into contention
events.

Release note: None

---

# Second commit

sql: extend resolverQueue to resolve waiter txn id

Previously, the resovlerQueue used in the contention event store only
resolved the txnID of the blocking transaction.
This commit, the resolverQueue would also resolve the txnID of the
waiting transaction.

Release note: None



Co-authored-by: Azhng <[email protected]>
  • Loading branch information
craig[bot] and Azhng committed Feb 26, 2022
2 parents 4a8d2f5 + a943872 commit 86bb64a
Show file tree
Hide file tree
Showing 18 changed files with 1,865 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/generated/settings/settings-for-tenants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ server.web_session.purge.max_deletions_per_cycle integer 10 the maximum number o
server.web_session.purge.period duration 1h0m0s the time until old sessions are deleted
server.web_session.purge.ttl duration 1h0m0s if nonzero, entries in system.web_sessions older than this duration are periodically purged
server.web_session_timeout duration 168h0m0s the duration that a newly created web session will be valid
sql.contention.event_store.capacity byte size 64 MiB the in-memory storage capacity per-node of contention event store
sql.contention.txn_id_cache.max_size byte size 0 B the maximum byte size TxnID cache will use (set to 0 to disable)
sql.cross_db_fks.enabled boolean false if true, creating foreign key references across databases is allowed
sql.cross_db_sequence_owners.enabled boolean false if true, creating sequences owned by tables from other databases is allowed
Expand Down
1 change: 1 addition & 0 deletions docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<tr><td><code>server.web_session.purge.period</code></td><td>duration</td><td><code>1h0m0s</code></td><td>the time until old sessions are deleted</td></tr>
<tr><td><code>server.web_session.purge.ttl</code></td><td>duration</td><td><code>1h0m0s</code></td><td>if nonzero, entries in system.web_sessions older than this duration are periodically purged</td></tr>
<tr><td><code>server.web_session_timeout</code></td><td>duration</td><td><code>168h0m0s</code></td><td>the duration that a newly created web session will be valid</td></tr>
<tr><td><code>sql.contention.event_store.capacity</code></td><td>byte size</td><td><code>64 MiB</code></td><td>the in-memory storage capacity per-node of contention event store</td></tr>
<tr><td><code>sql.contention.txn_id_cache.max_size</code></td><td>byte size</td><td><code>0 B</code></td><td>the maximum byte size TxnID cache will use (set to 0 to disable)</td></tr>
<tr><td><code>sql.cross_db_fks.enabled</code></td><td>boolean</td><td><code>false</code></td><td>if true, creating foreign key references across databases is allowed</td></tr>
<tr><td><code>sql.cross_db_sequence_owners.enabled</code></td><td>boolean</td><td><code>false</code></td><td>if true, creating sequences owned by tables from other databases is allowed</td></tr>
Expand Down
1 change: 1 addition & 0 deletions pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ ALL_TESTS = [
"//pkg/sql/contention/contentionutils:contentionutils_test",
"//pkg/sql/contention/txnidcache:txnidcache_test",
"//pkg/sql/contention:contention_test",
"//pkg/sql/contentionpb:contentionpb_test",
"//pkg/sql/covering:covering_test",
"//pkg/sql/delegate:delegate_test",
"//pkg/sql/distsql:distsql_test",
Expand Down
4 changes: 3 additions & 1 deletion pkg/server/server_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ func newSQLServer(ctx context.Context, cfg sqlServerArgs) (*SQLServer, error) {
if hasNodeLiveness {
traceCollector = collector.New(cfg.nodeDialer, nodeLiveness, cfg.Tracer)
}
contentionRegistry := contention.NewRegistry(cfg.Settings, cfg.sqlStatusServer.TxnIDResolution)
contentionRegistry.Start(ctx, cfg.stopper)

*execCfg = sql.ExecutorConfig{
Settings: cfg.Settings,
Expand All @@ -681,7 +683,7 @@ func newSQLServer(ctx context.Context, cfg sqlServerArgs) (*SQLServer, error) {
SQLStatusServer: cfg.sqlStatusServer,
RegionsServer: cfg.regionsServer,
SessionRegistry: cfg.sessionRegistry,
ContentionRegistry: contention.NewRegistry(),
ContentionRegistry: contentionRegistry,
SQLLiveness: cfg.sqlLivenessProvider,
JobRegistry: jobRegistry,
VirtualSchemas: virtualSchemas,
Expand Down
22 changes: 21 additions & 1 deletion pkg/sql/contention/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,62 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "contention",
srcs = ["registry.go"],
srcs = [
"cluster_settings.go",
"event_store.go",
"registry.go",
"resolver.go",
"test_utils.go",
],
importpath = "github.com/cockroachdb/cockroach/pkg/sql/contention",
visibility = ["//visibility:public"],
deps = [
"//pkg/keys",
"//pkg/roachpb",
"//pkg/server/serverpb",
"//pkg/settings",
"//pkg/settings/cluster",
"//pkg/sql/catalog/descpb",
"//pkg/sql/contention/contentionutils",
"//pkg/sql/contentionpb",
"//pkg/util/cache",
"//pkg/util/log",
"//pkg/util/stop",
"//pkg/util/syncutil",
"//pkg/util/timeutil",
"//pkg/util/uuid",
"@com_github_biogo_store//llrb",
"@com_github_cockroachdb_errors//:errors",
],
)

go_test(
name = "contention_test",
size = "small",
srcs = [
"event_store_test.go",
"registry_test.go",
"resolver_test.go",
"utils_test.go",
],
data = glob(["testdata/**"]),
embed = [":contention"],
deps = [
"//pkg/keys",
"//pkg/roachpb",
"//pkg/settings/cluster",
"//pkg/sql/contentionpb",
"//pkg/storage/enginepb",
"//pkg/testutils",
"//pkg/util/cache",
"//pkg/util/encoding",
"//pkg/util/leaktest",
"//pkg/util/randutil",
"//pkg/util/stop",
"//pkg/util/timeutil",
"//pkg/util/uuid",
"@com_github_cockroachdb_datadriven//:datadriven",
"@com_github_cockroachdb_errors//:errors",
"@com_github_stretchr_testify//require",
],
)
36 changes: 36 additions & 0 deletions pkg/sql/contention/cluster_settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package contention

import (
"time"

"github.com/cockroachdb/cockroach/pkg/settings"
)

// TxnIDResolutionInterval is the cluster setting that controls how often the
// Transaction ID Resolution is performed.
var TxnIDResolutionInterval = settings.RegisterDurationSetting(
settings.TenantWritable,
"sql.contention.event_store.resolution_interval",
"the interval at which transaction fingerprint ID resolution is "+
"performed (set to 0 to disable)",
time.Second*30,
)

// StoreCapacity is the cluster setting that controls the
// maximum size of the contention event store.
var StoreCapacity = settings.RegisterByteSizeSetting(
settings.TenantWritable,
"sql.contention.event_store.capacity",
"the in-memory storage capacity per-node of contention event store",
64*1024*1024, // 64 MB per node.
).WithPublic()
Loading

0 comments on commit 86bb64a

Please sign in to comment.