Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/kv/kvserver/spanlatch/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ go_library(
importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/spanlatch",
visibility = ["//visibility:public"],
deps = [
"//pkg/base",
"//pkg/kv/kvpb",
"//pkg/kv/kvserver/concurrency/poison",
"//pkg/kv/kvserver/spanset",
Expand Down
13 changes: 10 additions & 3 deletions pkg/kv/kvserver/spanlatch/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"
"unsafe"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/kv/kvpb"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/poison"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/spanset"
Expand Down Expand Up @@ -585,7 +584,7 @@ func (m *Manager) waitForSignal(
}
log.Eventf(ctx, "waiting to acquire %s latch %s, held by %s latch %s", waitType, wait, heldType, held)
poisonCh := held.g.poison.signalChan()
t.Reset(base.SlowRequestThreshold)
t.Reset(m.slowLatchRequestThreshold())
for {
select {
case <-held.g.done.signalChan():
Expand All @@ -608,7 +607,7 @@ func (m *Manager) waitForSignal(
}
case <-t.C:
log.KvExec.Warningf(ctx, "have been waiting %s to acquire %s latch %s, held by %s latch %s",
base.SlowRequestThreshold, waitType, wait, heldType, held)
m.slowLatchRequestThreshold(), waitType, wait, heldType, held)
if m.slowReqs != nil {
m.slowReqs.Inc(1)
defer m.slowReqs.Dec(1) //nolint:deferloop
Expand Down Expand Up @@ -709,6 +708,14 @@ func (m *Manager) longLatchHoldThreshold() time.Duration {
return LongLatchHoldThreshold.Get(&m.settings.SV)
}

// slowLatchRequestThreshold returns the threshold for logging slow latch requests.
func (m *Manager) slowLatchRequestThreshold() time.Duration {
if m.settings == nil {
return math.MaxInt64 // disable
}
return SlowLatchRequestThreshold.Get(&m.settings.SV)
}

// Metrics holds information about the state of a Manager.
type Metrics struct {
ReadCount int64
Expand Down
10 changes: 10 additions & 0 deletions pkg/kv/kvserver/spanlatch/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ var LongLatchHoldThreshold = settings.RegisterDurationSetting(
"the threshold for logging long latch holds",
3*time.Second,
)

// SlowLatchRequestThreshold controls when we will log slow latch acquisition
// attempts. When a latch acquisition has been waiting for this duration, a
// warning is logged and the slow request metric is incremented.
var SlowLatchRequestThreshold = settings.RegisterDurationSettingWithExplicitUnit(
settings.SystemOnly,
"kv.concurrency.slow_latch_request_duration",
"the threshold for logging slow latch acquisition attempts",
5*time.Second,
)
Loading