Skip to content

Commit 45f1688

Browse files
committed
kvserver: add subsume.locks_written metric
The new subsume.locks_written metric tracks how many locks are moved from the in-memory lock table to the replicated lock table during a SubsumeRequest. While here, I updated some log lines and added some assertions to existing tests to make sure we were seeing non-zero values for both the new metric and lease.transfer.locks_written. Epic: none Release note: None
1 parent 084a743 commit 45f1688

File tree

7 files changed

+59
-6
lines changed

7 files changed

+59
-6
lines changed

docs/generated/metrics/metrics.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17498,6 +17498,14 @@ layers:
1749817498
unit: COUNT
1749917499
aggregation: AVG
1750017500
derivative: NON_NEGATIVE_DERIVATIVE
17501+
- name: subsume.locks_written
17502+
exported_name: subsume_locks_written
17503+
description: Number of locks written to storage during subsume (range merge)
17504+
y_axis_label: Locks Written
17505+
type: COUNTER
17506+
unit: COUNT
17507+
aggregation: AVG
17508+
derivative: NON_NEGATIVE_DERIVATIVE
1750117509
- name: sysbytes
1750217510
exported_name: sysbytes
1750317511
description: Number of bytes in system KV pairs

pkg/kv/kvserver/batcheval/cmd_lease.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,16 @@ func evalNewLease(
7474
// If this is a lease transfer, we write out all unreplicated leases to
7575
// storage, so that any waiters will discover them on the new leaseholder.
7676
acquisitions, approxSize := rec.GetConcurrencyManager().OnRangeLeaseTransferEval()
77-
log.VEventf(ctx, 2, "upgrading durability of %d locks", len(acquisitions))
7877
if approxSize > durabilityUpgradeLimit {
7978
log.KvExec.Warningf(ctx,
8079
"refusing to upgrade lock durability of %d locks since approximate lock size of %d byte exceeds %d bytes",
8180
len(acquisitions),
8281
approxSize,
8382
durabilityUpgradeLimit)
8483
} else {
84+
if len(acquisitions) > 0 {
85+
log.KvExec.Infof(ctx, "upgrading durability of %d locks during lease transfer", len(acquisitions))
86+
}
8587
for _, acq := range acquisitions {
8688
if err := storage.MVCCAcquireLock(ctx, readWriter,
8789
&acq.Txn, acq.IgnoredSeqNums, acq.Strength, acq.Key, ms, 0, 0, true /* allowSequenceNumberRegression */); err != nil {

pkg/kv/kvserver/batcheval/cmd_subsume.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ func Subsume(
184184
// will be cleared later when OnRangeMerge is called the replica in
185185
// (*Store).MergeRange.
186186
stats := cArgs.EvalCtx.GetMVCCStats()
187+
var locksWritten int
187188
if args.PreserveUnreplicatedLocks {
188189
durabilityUpgradeLimit := concurrency.GetMaxLockFlushSize(&cArgs.EvalCtx.ClusterSettings().SV)
189190
acquisitions, approxSize := cArgs.EvalCtx.GetConcurrencyManager().OnRangeSubsumeEval()
@@ -194,7 +195,9 @@ func Subsume(
194195
approxSize,
195196
durabilityUpgradeLimit)
196197
} else {
197-
log.VEventf(ctx, 2, "upgrading durability of %d locks", len(acquisitions))
198+
if len(acquisitions) > 0 {
199+
log.KvExec.Infof(ctx, "upgrading durability of %d lock during subsume", len(acquisitions))
200+
}
198201
statsDelta := enginepb.MVCCStats{}
199202
for _, acq := range acquisitions {
200203
if err := storage.MVCCAcquireLock(ctx, readWriter,
@@ -206,6 +209,7 @@ func Subsume(
206209
// response and to the stats update we expect as part of this proposal.
207210
stats.Add(statsDelta)
208211
cArgs.Stats.Add(statsDelta)
212+
locksWritten = len(acquisitions)
209213
}
210214
}
211215

@@ -246,5 +250,10 @@ func Subsume(
246250
// waitForApplication when sending a kvpb.SubsumeRequest.
247251
pd.Replicated.DoTimelyApplicationToAllReplicas = true
248252
pd.Local.RepopulateSubsumeResponseLAI = args.PreserveUnreplicatedLocks
253+
if locksWritten > 0 {
254+
pd.Local.Metrics = &result.Metrics{
255+
SubsumeLocksWritten: locksWritten,
256+
}
257+
}
249258
return pd, nil
250259
}

pkg/kv/kvserver/batcheval/result/metrics.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Metrics struct {
1919
AddSSTableAsWrites int // AddSSTable requests with IngestAsWrites set
2020
SplitsWithEstimatedStats int // Splits that computed stats estimates
2121
SplitEstimatedTotalBytesDiff int // Difference between pre- and post-split total bytes.
22+
SubsumeLocksWritten int // number of locks written during a subsume
2223
}
2324

2425
// Add absorbs the supplied Metrics into the receiver.
@@ -34,4 +35,5 @@ func (mt *Metrics) Add(o Metrics) {
3435
mt.AddSSTableAsWrites += o.AddSSTableAsWrites
3536
mt.SplitsWithEstimatedStats += o.SplitsWithEstimatedStats
3637
mt.SplitEstimatedTotalBytesDiff += o.SplitEstimatedTotalBytesDiff
38+
mt.SubsumeLocksWritten += o.SubsumeLocksWritten
3739
}

pkg/kv/kvserver/client_metrics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func TestStoreResolveMetrics(t *testing.T) {
159159
// them everywhere.
160160
{
161161
act := fmt.Sprintf("%+v", result.Metrics{})
162-
exp := "{LeaseRequestSuccess:0 LeaseRequestError:0 LeaseTransferSuccess:0 LeaseTransferError:0 LeaseTransferLocksWritten:0 ResolveCommit:0 ResolveAbort:0 ResolvePoison:0 AddSSTableAsWrites:0 SplitsWithEstimatedStats:0 SplitEstimatedTotalBytesDiff:0}"
162+
exp := "{LeaseRequestSuccess:0 LeaseRequestError:0 LeaseTransferSuccess:0 LeaseTransferError:0 LeaseTransferLocksWritten:0 ResolveCommit:0 ResolveAbort:0 ResolvePoison:0 AddSSTableAsWrites:0 SplitsWithEstimatedStats:0 SplitEstimatedTotalBytesDiff:0 SubsumeLocksWritten:0}"
163163
if act != exp {
164164
t.Errorf("need to update this test due to added fields: %v", act)
165165
}

pkg/kv/kvserver/client_replica_test.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6171,6 +6171,11 @@ func TestLeaseTransferReplicatesLocks(t *testing.T) {
61716171
t.Log("cancelling txn2")
61726172
txn2Cancel()
61736173
require.NoError(t, g.Wait())
6174+
6175+
// Check metrics
6176+
locksWritten, err := tc.GetFirstStoreFromServer(t, 0).Metrics().GetStoreMetric("leases.transfers.locks_written")
6177+
require.NoError(t, err)
6178+
require.GreaterOrEqual(t, locksWritten, int64(1))
61746179
}
61756180

61766181
func TestLeaseTransferDropsLocksIfLargerThanCommandSize(t *testing.T) {
@@ -6312,15 +6317,16 @@ func TestMergeReplicatesLocks(t *testing.T) {
63126317
)
63136318
concurrency.UnreplicatedLockReliabilityMerge.Override(ctx, &st.SV, true)
63146319

6315-
for _, b := range []bool{true, false} {
6320+
for _, rhsLock := range []bool{true, false} {
63166321
name := "lhs-lock"
63176322
lockKeySuffix := lhsKey
6318-
if b {
6323+
if rhsLock {
63196324
name = "rhs-lock"
63206325
lockKeySuffix = rhsKey
63216326
}
63226327
t.Run(name, func(t *testing.T) {
6323-
tc := testcluster.StartTestCluster(t, 3, base.TestClusterArgs{
6328+
nodeCount := 3
6329+
tc := testcluster.StartTestCluster(t, nodeCount, base.TestClusterArgs{
63246330
ServerArgs: base.TestServerArgs{
63256331
Settings: st,
63266332
},
@@ -6417,6 +6423,17 @@ func TestMergeReplicatesLocks(t *testing.T) {
64176423
for _, err := range failures {
64186424
t.Errorf("consistency failure: %s", err.Error())
64196425
}
6426+
if rhsLock {
6427+
// The range could have been on any node. We just care that this metric
6428+
// is written somewhere.
6429+
var locksWritten int64
6430+
for i := range nodeCount {
6431+
l, err := tc.GetFirstStoreFromServer(t, i).Metrics().GetStoreMetric("subsume.locks_written")
6432+
require.NoError(t, err)
6433+
locksWritten += l
6434+
}
6435+
require.GreaterOrEqual(t, locksWritten, int64(1))
6436+
}
64206437
})
64216438
}
64226439
}

pkg/kv/kvserver/metrics.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ var (
295295
Unit: metric.Unit_COUNT,
296296
}
297297

298+
metaSubsumeLocksWrittenCount = metric.Metadata{
299+
Name: "subsume.locks_written",
300+
Help: "Number of locks written to storage during subsume (range merge)",
301+
Measurement: "Locks Written",
302+
Unit: metric.Unit_COUNT,
303+
}
304+
298305
metaReqCPUNanos = metric.Metadata{
299306
Name: "replicas.cpunanospersecond",
300307
Help: "Nanoseconds of CPU time in Replica request processing including evaluation but not replication",
@@ -3363,6 +3370,8 @@ type StoreMetrics struct {
33633370
SplitsWithEstimatedStats *metric.Counter
33643371
SplitEstimatedTotalBytesDiff *metric.Counter
33653372

3373+
SubsumeLocksWritten *metric.Counter
3374+
33663375
FlushUtilization *metric.GaugeFloat64
33673376
FsyncLatency *metric.ManualWindowHistogram
33683377

@@ -3718,6 +3727,9 @@ func newStoreMetrics(histogramWindow time.Duration) *StoreMetrics {
37183727
ResolveAbortCount: metric.NewCounter(metaResolveAbort),
37193728
ResolvePoisonCount: metric.NewCounter(metaResolvePoison),
37203729

3730+
// Subsume metrics
3731+
SubsumeLocksWritten: metric.NewCounter(metaSubsumeLocksWrittenCount),
3732+
37213733
Capacity: metric.NewGauge(metaCapacity),
37223734
Available: metric.NewGauge(metaAvailable),
37233735
Used: metric.NewGauge(metaUsed),
@@ -4516,6 +4528,9 @@ func (sm *StoreMetrics) handleMetricsResult(ctx context.Context, metric result.M
45164528
sm.SplitEstimatedTotalBytesDiff.Inc(int64(metric.SplitEstimatedTotalBytesDiff))
45174529
metric.SplitEstimatedTotalBytesDiff = 0
45184530

4531+
sm.SubsumeLocksWritten.Inc(int64(metric.SubsumeLocksWritten))
4532+
metric.SubsumeLocksWritten = 0
4533+
45194534
if metric != (result.Metrics{}) {
45204535
log.KvExec.Fatalf(ctx, "unhandled fields in metrics result: %+v", metric)
45214536
}

0 commit comments

Comments
 (0)