Skip to content

Commit

Permalink
kvserver: account for replica follower write bytes
Browse files Browse the repository at this point in the history
Previously, only bytes written at the leaseholder were accounted for on
a replica. Now, follower replicas will record the bytes written.

Informs: cockroachdb#91152

Release note: None
  • Loading branch information
kvoli committed Jan 12, 2023
1 parent ec92c4e commit a0604b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 0 additions & 3 deletions pkg/kv/kvserver/replica_app_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,6 @@ func (b *replicaAppBatch) ApplyToStateMachine(ctx context.Context) error {
deltaStats.Subtract(prevStats)
r.store.metrics.addMVCCStats(ctx, r.tenantMetricsRef, deltaStats)

// Record the number of keys written to the replica.
b.r.loadStats.RecordWriteKeys(float64(b.ab.numMutations))

now := timeutil.Now()
if needsSplitBySize && r.splitQueueThrottle.ShouldProcess(now) {
r.store.splitQueue.MaybeAddAsync(ctx, r, r.store.Clock().NowAsClockTimestamp())
Expand Down
17 changes: 13 additions & 4 deletions pkg/kv/kvserver/replica_raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -993,10 +993,19 @@ func (r *Replica) handleRaftReadyRaftMuLocked(
return stats, err
}

if r.store.cfg.KVAdmissionController != nil &&
stats.apply.followerStoreWriteBytes.NumEntries > 0 {
r.store.cfg.KVAdmissionController.FollowerStoreWriteBytes(
r.store.StoreID(), stats.apply.followerStoreWriteBytes)
r.loadStats.RecordWriteKeys(float64(stats.apply.numMutations))
if stats.apply.followerStoreWriteBytes.NumEntries > 0 {
// NB: The write bytes for non-followers are recorded in replica
// send, the folower bytes are accounted for here on the follower
// replica's store.
r.loadStats.RecordWriteBytes(float64(
stats.apply.followerStoreWriteBytes.WriteBytes +
stats.apply.followerStoreWriteBytes.IngestedBytes))

if r.store.cfg.KVAdmissionController != nil {
r.store.cfg.KVAdmissionController.FollowerStoreWriteBytes(
r.store.StoreID(), stats.apply.followerStoreWriteBytes)
}
}

// etcd raft occasionally adds a nil entry (our own commands are never
Expand Down

0 comments on commit a0604b7

Please sign in to comment.