Skip to content

Commit a091631

Browse files
committed
spanlatch: add cluster setting for slow latch request threshold
This adds a new cluster setting kv.concurrency.slow_latch_request_duration which configures the threshold for logging slow latch acquisitions. Previously, logging would occur after 15 seconds, but now the default is reduced to 5s. Informs #154271 Release note: None Epic: None Part of: CRDB-54843
1 parent 31bf35d commit a091631

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

pkg/kv/kvserver/spanlatch/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ go_library(
1414
importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/spanlatch",
1515
visibility = ["//visibility:public"],
1616
deps = [
17-
"//pkg/base",
1817
"//pkg/kv/kvpb",
1918
"//pkg/kv/kvserver/concurrency/poison",
2019
"//pkg/kv/kvserver/spanset",

pkg/kv/kvserver/spanlatch/manager.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"time"
1212
"unsafe"
1313

14-
"github.com/cockroachdb/cockroach/pkg/base"
1514
"github.com/cockroachdb/cockroach/pkg/kv/kvpb"
1615
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/poison"
1716
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/spanset"
@@ -585,7 +584,9 @@ func (m *Manager) waitForSignal(
585584
}
586585
log.Eventf(ctx, "waiting to acquire %s latch %s, held by %s latch %s", waitType, wait, heldType, held)
587586
poisonCh := held.g.poison.signalChan()
588-
t.Reset(base.SlowRequestThreshold)
587+
588+
slowThreshold := m.slowLatchRequestThreshold()
589+
t.Reset(slowThreshold)
589590
for {
590591
select {
591592
case <-held.g.done.signalChan():
@@ -610,7 +611,7 @@ func (m *Manager) waitForSignal(
610611
t.Read = true
611612

612613
log.Warningf(ctx, "have been waiting %s to acquire %s latch %s, held by %s latch %s",
613-
base.SlowRequestThreshold, waitType, wait, heldType, held)
614+
slowThreshold, waitType, wait, heldType, held)
614615
if m.slowReqs != nil {
615616
m.slowReqs.Inc(1)
616617
defer m.slowReqs.Dec(1) //nolint:deferloop
@@ -711,6 +712,14 @@ func (m *Manager) longLatchHoldThreshold() time.Duration {
711712
return LongLatchHoldThreshold.Get(&m.settings.SV)
712713
}
713714

715+
// slowLatchRequestThreshold returns the threshold for logging slow latch requests.
716+
func (m *Manager) slowLatchRequestThreshold() time.Duration {
717+
if m.settings == nil {
718+
return math.MaxInt64 // disable
719+
}
720+
return SlowLatchRequestThreshold.Get(&m.settings.SV)
721+
}
722+
714723
// Metrics holds information about the state of a Manager.
715724
type Metrics struct {
716725
ReadCount int64

pkg/kv/kvserver/spanlatch/settings.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@ var LongLatchHoldThreshold = settings.RegisterDurationSetting(
2323
3*time.Second,
2424
settings.NonNegativeDuration,
2525
)
26+
27+
// SlowLatchRequestThreshold controls when we will log slow latch acquisition
28+
// attempts. When a latch acquisition has been waiting for this duration, a
29+
// warning is logged and the slow request metric is incremented.
30+
var SlowLatchRequestThreshold = settings.RegisterDurationSettingWithExplicitUnit(
31+
settings.SystemOnly,
32+
"kv.concurrency.slow_latch_request_duration",
33+
"the threshold for logging slow latch acquisition attempts",
34+
5*time.Second,
35+
settings.DurationWithMinimum(10*time.Millisecond),
36+
)

0 commit comments

Comments
 (0)