Skip to content

Commit 9d48618

Browse files
authored
Merge pull request #160037 from angeladietz/backport24.1-158472
release-24.1: spanlatch: add cluster setting for slow latch request threshold
2 parents b67db7f + 7897023 commit 9d48618

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"
@@ -579,7 +578,9 @@ func (m *Manager) waitForSignal(
579578
}()
580579
log.Eventf(ctx, "waiting to acquire %s latch %s, held by %s latch %s", waitType, wait, heldType, held)
581580
poisonCh := held.g.poison.signalChan()
582-
t.Reset(base.SlowRequestThreshold)
581+
582+
slowThreshold := m.slowLatchRequestThreshold()
583+
t.Reset(slowThreshold)
583584
for {
584585
select {
585586
case <-held.g.done.signalChan():
@@ -604,7 +605,7 @@ func (m *Manager) waitForSignal(
604605
t.Read = true
605606

606607
log.Warningf(ctx, "have been waiting %s to acquire %s latch %s, held by %s latch %s",
607-
base.SlowRequestThreshold, waitType, wait, heldType, held)
608+
slowThreshold, waitType, wait, heldType, held)
608609
if m.slowReqs != nil {
609610
m.slowReqs.Inc(1)
610611
defer m.slowReqs.Dec(1)
@@ -682,6 +683,14 @@ func (m *Manager) longLatchHoldThreshold() time.Duration {
682683
return LongLatchHoldThreshold.Get(&m.settings.SV)
683684
}
684685

686+
// slowLatchRequestThreshold returns the threshold for logging slow latch requests.
687+
func (m *Manager) slowLatchRequestThreshold() time.Duration {
688+
if m.settings == nil {
689+
return math.MaxInt64 // disable
690+
}
691+
return SlowLatchRequestThreshold.Get(&m.settings.SV)
692+
}
693+
685694
// Metrics holds information about the state of a Manager.
686695
type Metrics struct {
687696
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)