Skip to content

Commit 5ecb250

Browse files
craig[bot]DrewKimballRaduBerinde
committed
113649: execstats: add latch wait time into cumulative contention time r=yuzefovich a=DrewKimball #### sql: add setting to enable registering latch wait contention events This commit adds a session setting (default off) that will cause contention events emitted by the latch table to be included in the `*_contention_events` virtual tables. This behavior is hidden behind a setting because latch wait events are more common than events emitted by the lock table. Tracking them in the virtual tables could increase system load and flood the statement insights with uninteresting events. For now, this setting does nothing, but the following commit will use it. Informs #103713 Release note: None #### execstats: add latch wait time into cumulative contention time This patch adds a field `IsLatch` to the `ContentionEvent` protobuf struct that indicates that a contention event was emitted by the latch table. The event is added to the trace and used to increment the contention time metrics, but is only added to the contention registry if `register_latch_wait_contention_events` is set to true. This commit also propagates the transaction ID into the latch manager and the contention events listener. This information is used during a latch wait event to distinguish between time waiting for a transaction's own requests (e.g. for QueryIntent) and for real contention between different transactions. Fixes #103713 Release note (ui change): The contention time metric now includes time spent waiting to acquire latches in addition to time spent acquiring locks. This applies to both the cumulative contention time visible in the db console and the annotations of an `EXPLAIN ANALYZE` output. 143382: go.mod: bump Pebble to 96302028f139 r=RaduBerinde a=RaduBerinde Changes: * [`96302028`](cockroachdb/pebble@96302028) db: embed DataCorruptionInfo into corruption errors * [`a3c4df0a`](cockroachdb/pebble@a3c4df0a) db: add mechanics for compaction-time value separation * [`afe96a7e`](cockroachdb/pebble@afe96a7e) sstable: add redaction to bit flip check * [`918c6dd6`](cockroachdb/pebble@918c6dd6) manifest: add L0Sublevels sanity checks, fix L0Index * [`a45eb824`](cockroachdb/pebble@a45eb824) sstable: do a bit flip computation on a checksum mismatch in the Reader * [`8701659b`](cockroachdb/pebble@8701659b) db: fix CompactionPickerTargetLevel test Release note: none. Epic: none. Co-authored-by: Drew Kimball <[email protected]> Co-authored-by: Radu Berinde <[email protected]>
3 parents abefdb6 + 1314dc0 + 627c848 commit 5ecb250

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+600
-122
lines changed

DEPS.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,10 +1895,10 @@ def go_deps():
18951895
patches = [
18961896
"@com_github_cockroachdb_cockroach//build/patches:com_github_cockroachdb_pebble.patch",
18971897
],
1898-
sha256 = "7c9b3d757f6a65e68fa1e5a2450fd568c9975e06f84f552048cb3a4396fc93e0",
1899-
strip_prefix = "github.com/cockroachdb/[email protected]20250320203539-9aedeff126ce",
1898+
sha256 = "4df0db2feef2d1e9cb3e19678c1a4fa1d73b638ad6c1de4eb9f816787b9e265f",
1899+
strip_prefix = "github.com/cockroachdb/[email protected]20250324192946-96302028f139",
19001900
urls = [
1901-
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250320203539-9aedeff126ce.zip",
1901+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250324192946-96302028f139.zip",
19021902
],
19031903
)
19041904
go_repository(

build/bazelutil/distdir_files.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ DISTDIR_FILES = {
361361
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/gostdlib/com_github_cockroachdb_gostdlib-v1.19.0.zip": "c4d516bcfe8c07b6fc09b8a9a07a95065b36c2855627cb3514e40c98f872b69e",
362362
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/logtags/com_github_cockroachdb_logtags-v0.0.0-20241215232642-bb51bb14a506.zip": "920068af09e3846d9ebb4e4a7787ff1dd10f3989c5f940ad861b0f6a9f824f6e",
363363
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/metamorphic/com_github_cockroachdb_metamorphic-v0.0.0-20231108215700-4ba948b56895.zip": "28c8cf42192951b69378cf537be5a9a43f2aeb35542908cc4fe5f689505853ea",
364-
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250320203539-9aedeff126ce.zip": "7c9b3d757f6a65e68fa1e5a2450fd568c9975e06f84f552048cb3a4396fc93e0",
364+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250324192946-96302028f139.zip": "4df0db2feef2d1e9cb3e19678c1a4fa1d73b638ad6c1de4eb9f816787b9e265f",
365365
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/redact/com_github_cockroachdb_redact-v1.1.6.zip": "018eccb5fb9ca52d43ec9eaf213539d01c1f2b94e0e822406ebfb2e9321ef6cf",
366366
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/returncheck/com_github_cockroachdb_returncheck-v0.0.0-20200612231554-92cdbca611dd.zip": "ce92ba4352deec995b1f2eecf16eba7f5d51f5aa245a1c362dfe24c83d31f82b",
367367
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/stress/com_github_cockroachdb_stress-v0.0.0-20220803192808-1806698b1b7b.zip": "3fda531795c600daf25532a4f98be2a1335cd1e5e182c72789bca79f5f69fcc1",

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ require (
136136
github.com/cockroachdb/go-test-teamcity v0.0.0-20191211140407-cff980ad0a55
137137
github.com/cockroachdb/gostdlib v1.19.0
138138
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506
139-
github.com/cockroachdb/pebble v0.0.0-20250320203539-9aedeff126ce
139+
github.com/cockroachdb/pebble v0.0.0-20250324192946-96302028f139
140140
github.com/cockroachdb/redact v1.1.6
141141
github.com/cockroachdb/returncheck v0.0.0-20200612231554-92cdbca611dd
142142
github.com/cockroachdb/stress v0.0.0-20220803192808-1806698b1b7b

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,8 @@ github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 h1:ASDL+UJcILM
587587
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506/go.mod h1:Mw7HqKr2kdtu6aYGn3tPmAftiP3QPX63LdK/zcariIo=
588588
github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895 h1:XANOgPYtvELQ/h4IrmPAohXqe2pWA8Bwhejr3VQoZsA=
589589
github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895/go.mod h1:aPd7gM9ov9M8v32Yy5NJrDyOcD8z642dqs+F0CeNXfA=
590-
github.com/cockroachdb/pebble v0.0.0-20250320203539-9aedeff126ce h1:DKHaVQVHNIRSaqXhZ6C1vSgDks9brsbWt/OzrvYw0iA=
591-
github.com/cockroachdb/pebble v0.0.0-20250320203539-9aedeff126ce/go.mod h1:08jsvr5vUySLPaDXKxg/jhKDWxzg9Hu27nhhi1z30os=
590+
github.com/cockroachdb/pebble v0.0.0-20250324192946-96302028f139 h1:M4OyhSDhrUnmVbjRhZT+BIgXChNdcnGIiJnCBza4tH4=
591+
github.com/cockroachdb/pebble v0.0.0-20250324192946-96302028f139/go.mod h1:08jsvr5vUySLPaDXKxg/jhKDWxzg9Hu27nhhi1z30os=
592592
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
593593
github.com/cockroachdb/redact v1.1.6 h1:zXJBwDZ84xJNlHl1rMyCojqyIxv+7YUpQiJLQ7n4314=
594594
github.com/cockroachdb/redact v1.1.6/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=

pkg/ccl/logictestccl/testdata/logic_test/triggers_explain

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ quality of service: regular
194194
vectorized batch count: 0
195195
KV time: 0µs
196196
KV contention time: 0µs
197+
KV lock wait time: 0µs
198+
KV latch wait time: 0µs
197199
KV rows decoded: 0
198200
KV pairs read: 0
199201
KV bytes read: 0 B
@@ -367,6 +369,8 @@ quality of service: regular
367369
│ vectorized batch count: 0
368370
│ KV time: 0µs
369371
│ KV contention time: 0µs
372+
│ KV lock wait time: 0µs
373+
│ KV latch wait time: 0µs
370374
│ KV rows decoded: 0
371375
│ KV pairs read: 0
372376
│ KV bytes read: 0 B
@@ -441,6 +445,8 @@ quality of service: regular
441445
│ vectorized batch count: 0
442446
│ KV time: 0µs
443447
│ KV contention time: 0µs
448+
│ KV lock wait time: 0µs
449+
│ KV latch wait time: 0µs
444450
│ KV rows decoded: 1
445451
│ KV pairs read: 2
446452
│ KV bytes read: 8 B
@@ -710,6 +716,8 @@ quality of service: regular
710716
│ vectorized batch count: 0
711717
│ KV time: 0µs
712718
│ KV contention time: 0µs
719+
│ KV lock wait time: 0µs
720+
│ KV latch wait time: 0µs
713721
│ KV rows decoded: 0
714722
│ KV pairs read: 0
715723
│ KV bytes read: 0 B
@@ -783,6 +791,8 @@ quality of service: regular
783791
│ vectorized batch count: 0
784792
│ KV time: 0µs
785793
│ KV contention time: 0µs
794+
│ KV lock wait time: 0µs
795+
│ KV latch wait time: 0µs
786796
│ KV rows decoded: 1
787797
│ KV pairs read: 2
788798
│ KV bytes read: 8 B
@@ -880,6 +890,8 @@ quality of service: regular
880890
│ │ vectorized batch count: 0
881891
│ │ KV time: 0µs
882892
│ │ KV contention time: 0µs
893+
│ │ KV lock wait time: 0µs
894+
│ │ KV latch wait time: 0µs
883895
│ │ KV rows decoded: 1
884896
│ │ KV pairs read: 2
885897
│ │ KV bytes read: 8 B
@@ -927,6 +939,8 @@ quality of service: regular
927939
│ │ vectorized batch count: 0
928940
│ │ KV time: 0µs
929941
│ │ KV contention time: 0µs
942+
│ │ KV lock wait time: 0µs
943+
│ │ KV latch wait time: 0µs
930944
│ │ KV rows decoded: 1
931945
│ │ KV pairs read: 2
932946
│ │ KV bytes read: 8 B
@@ -1103,6 +1117,8 @@ quality of service: regular
11031117
│ vectorized batch count: 0
11041118
│ KV time: 0µs
11051119
│ KV contention time: 0µs
1120+
│ KV lock wait time: 0µs
1121+
│ KV latch wait time: 0µs
11061122
│ KV rows decoded: 1
11071123
│ KV pairs read: 2
11081124
│ KV bytes read: 8 B

pkg/kv/kvpb/api.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2349,7 +2349,13 @@ func (r *IsSpanEmptyResponse) IsEmpty() bool {
23492349

23502350
// SafeFormat implements redact.SafeFormatter.
23512351
func (c *ContentionEvent) SafeFormat(w redact.SafePrinter, _ rune) {
2352-
w.Printf("conflicted with %s on %s for %.3fs", c.TxnMeta.ID, c.Key, c.Duration.Seconds())
2352+
prefix := redact.SafeString("conflicted")
2353+
if c.IsLatch {
2354+
prefix = "latch conflict"
2355+
}
2356+
w.Printf("%s with %s on %s for %.3fs",
2357+
prefix, c.TxnMeta.ID, c.Key, c.Duration.Seconds(),
2358+
)
23532359
}
23542360

23552361
// String implements fmt.Stringer.

pkg/kv/kvpb/api.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3741,6 +3741,9 @@ message ContentionEvent {
37413741
// Duration spent contending against the other transaction.
37423742
google.protobuf.Duration duration = 3 [(gogoproto.nullable) = false,
37433743
(gogoproto.stdduration) = true];
3744+
// IsLatch, if true, indicates that the contention event was due to waiting to
3745+
// acquire a latch.
3746+
bool is_latch = 4;
37443747
}
37453748

37463749
// ScanStats is a message that tracks miscellaneous statistics of all Gets,

pkg/kv/kvserver/concurrency/concurrency_control.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
2323
"github.com/cockroachdb/cockroach/pkg/util/hlc"
2424
"github.com/cockroachdb/cockroach/pkg/util/uuid"
25-
"github.com/cockroachdb/redact"
2625
)
2726

2827
// Manager is a structure that sequences incoming requests and provides
@@ -446,9 +445,8 @@ type Request struct {
446445
// not also passed an exiting Guard.
447446
LockSpans *lockspanset.LockSpanSet
448447

449-
// The SafeFormatter capable of formatting the request. This is used to enrich
450-
// logging with request level information when latches conflict.
451-
BaFmt redact.SafeFormatter
448+
// Batch is the batch to which the request belongs.
449+
Batch *kvpb.BatchRequest
452450

453451
// DeadlockTimeout is the amount of time that the request will wait on a lock
454452
// before pushing the lock holder's transaction for deadlock detection.
@@ -531,7 +529,12 @@ type latchManager interface {
531529
// WaitFor waits for conflicting latches on the specified spans without adding
532530
// any latches itself. Fast path for operations that only require flushing out
533531
// old operations without blocking any new ones.
534-
WaitFor(ctx context.Context, spans *spanset.SpanSet, pp poison.Policy, baFmt redact.SafeFormatter) *Error
532+
WaitFor(
533+
ctx context.Context,
534+
spans *spanset.SpanSet,
535+
pp poison.Policy,
536+
ba *kvpb.BatchRequest,
537+
) *Error
535538

536539
// Poison a guard's latches, allowing waiters to fail fast.
537540
Poison(latchGuard)

pkg/kv/kvserver/concurrency/concurrency_manager.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func NewManager(cfg Config) Manager {
181181
cfg.SlowLatchGauge,
182182
cfg.Settings,
183183
cfg.LatchWaitDurations,
184+
cfg.Clock,
184185
),
185186
},
186187
lt: lt,
@@ -269,7 +270,7 @@ func (m *managerImpl) sequenceReqWithGuard(
269270
// them.
270271
if shouldWaitOnLatchesWithoutAcquiring(g.Req) {
271272
log.Event(ctx, "waiting on latches without acquiring")
272-
return nil, m.lm.WaitFor(ctx, g.Req.LatchSpans, g.Req.PoisonPolicy, g.Req.BaFmt)
273+
return nil, m.lm.WaitFor(ctx, g.Req.LatchSpans, g.Req.PoisonPolicy, g.Req.Batch)
273274
}
274275

275276
// Provide the manager with an opportunity to intercept the request. It

pkg/kv/kvserver/concurrency/concurrency_manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func TestConcurrencyManagerBasic(t *testing.T) {
220220
LatchSpans: latchSpans,
221221
LockSpans: lockSpans,
222222
PoisonPolicy: pp,
223-
BaFmt: ba,
223+
Batch: ba,
224224
}
225225
return ""
226226

0 commit comments

Comments
 (0)