Skip to content

Commit 9bbbc84

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 0f2bc7b commit 9bbbc84

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():
@@ -608,7 +609,7 @@ func (m *Manager) waitForSignal(
608609
}
609610
case <-t.C:
610611
log.KvExec.Warningf(ctx, "have been waiting %s to acquire %s latch %s, held by %s latch %s",
611-
base.SlowRequestThreshold, waitType, wait, heldType, held)
612+
slowThreshold, waitType, wait, heldType, held)
612613
if m.slowReqs != nil {
613614
m.slowReqs.Inc(1)
614615
defer m.slowReqs.Dec(1) //nolint:deferloop
@@ -709,6 +710,14 @@ func (m *Manager) longLatchHoldThreshold() time.Duration {
709710
return LongLatchHoldThreshold.Get(&m.settings.SV)
710711
}
711712

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

pkg/kv/kvserver/spanlatch/settings.go

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

0 commit comments

Comments
 (0)