Skip to content

Commit 9483b21

Browse files
committed
kvserver: record follower write bytes during recordStatsOnCommit
Previously, we recorded write bytes for follower replicas in runPostAddTriggersReplicaOnly, right before apply, which could be inaccurate since stats should be recorded at commit time. This commit moves the recording to recordStatsOnCommit by including the write bytes in the batch stats. Epic: none Release note: none
1 parent 6a4ebd8 commit 9483b21

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

pkg/kv/kvserver/app_batch.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type appBatchStats struct {
3333
numEntriesProcessedBytes int64
3434
numEmptyEntries int
3535
numAddSST, numAddSSTCopies int
36+
numWriteBytes int64
3637

3738
// NB: update `merge` when adding a new field.
3839
}
@@ -42,6 +43,7 @@ func (s *appBatchStats) merge(ss appBatchStats) {
4243
s.numEntriesProcessed += ss.numEntriesProcessed
4344
s.numEntriesProcessedBytes += ss.numEntriesProcessedBytes
4445
ss.numEmptyEntries += ss.numEmptyEntries
46+
s.numWriteBytes += ss.numWriteBytes
4547
}
4648

4749
// appBatch is the in-progress foundation for standalone log entry

pkg/kv/kvserver/replica_app_batch.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func (b *replicaAppBatch) runPostAddTriggersReplicaOnly(
256256
if !cmd.IsLocal() {
257257
writeBytes, ingestedBytes := cmd.getStoreWriteByteSizes()
258258
if writeBytes > 0 || ingestedBytes > 0 {
259-
b.r.recordRequestWriteBytes(writeBytes, ingestedBytes)
259+
b.ab.numWriteBytes += writeBytes + ingestedBytes
260260
}
261261
// TODO(irfansharif): This code block can be removed once below-raft
262262
// admission control is the only form of IO admission control. It pre-dates
@@ -725,6 +725,7 @@ func (b *replicaAppBatch) recordStatsOnCommit() {
725725
b.applyStats.appBatchStats.merge(b.ab.appBatchStats)
726726
b.applyStats.numBatchesProcessed++
727727
b.applyStats.followerStoreWriteBytes.Merge(b.followerStoreWriteBytes)
728+
b.r.recordRequestWriteBytes(b.ab.numWriteBytes)
728729

729730
if n := b.ab.numAddSST; n > 0 {
730731
b.r.store.metrics.AddSSTableApplications.Inc(int64(n))

pkg/kv/kvserver/replica_raft.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,9 @@ func (s handleRaftReadyStats) SafeFormat(p redact.SafePrinter, _ rune) {
823823
p.Printf(" (copies=%d)", c)
824824
}
825825
}
826+
if b := s.apply.numWriteBytes; b > 0 {
827+
p.Printf(", apply-write-bytes=%s", humanizeutil.IBytes(b))
828+
}
826829
p.SafeString("]")
827830

828831
if n := s.apply.assertionsRequested; n > 0 {

pkg/kv/kvserver/replica_send.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (r *Replica) SendWithWriteBytes(
220220
// accounting.
221221
r.recordBatchRequestLoad(ctx, ba)
222222
if writeBytes != nil {
223-
r.recordRequestWriteBytes(writeBytes.WriteBytes, writeBytes.IngestedBytes)
223+
r.recordRequestWriteBytes(writeBytes.WriteBytes + writeBytes.IngestedBytes)
224224
}
225225
r.recordImpactOnRateLimiter(ctx, br, isReadOnly)
226226
return br, writeBytes, pErr
@@ -1069,10 +1069,10 @@ func (r *Replica) getBatchRequestQPS(ctx context.Context, ba *kvpb.BatchRequest)
10691069

10701070
// recordRequestWriteBytes records the write bytes from a replica batch
10711071
// request.
1072-
func (r *Replica) recordRequestWriteBytes(writeBytes int64, ingestedBytes int64) {
1072+
func (r *Replica) recordRequestWriteBytes(writeBytes int64) {
10731073
// TODO(kvoli): Consider recording the ingested bytes (AddSST) separately
10741074
// to the write bytes.
1075-
r.loadStats.RecordWriteBytes(float64(writeBytes + ingestedBytes))
1075+
r.loadStats.RecordWriteBytes(float64(writeBytes))
10761076
}
10771077

10781078
// checkBatchRequest verifies BatchRequest validity requirements. In particular,

0 commit comments

Comments
 (0)