Skip to content

Commit d284218

Browse files
committed
kvserver: rename a field
This is a more evocative name - we're measuring when the event was queued, but not when it was processed.
1 parent 4b58725 commit d284218

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

pkg/kv/kvserver/scheduler.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ const (
143143
)
144144

145145
type raftScheduleState struct {
146-
flags raftScheduleFlags
147-
begin crtime.Mono
146+
flags raftScheduleFlags
147+
queued crtime.Mono
148148

149149
// The number of ticks queued. Usually it's 0 or 1, but may go above if the
150150
// scheduling or processing is slow. It is limited by raftScheduler.maxTicks,
@@ -393,10 +393,10 @@ func (ss *raftSchedulerShard) worker(
393393
ss.Unlock()
394394

395395
// Record the scheduling latency for the range.
396-
if buildutil.CrdbTestBuild && state.begin == 0 {
397-
log.Fatalf(ctx, "raftSchedulerShard.worker called with zero begin: %+v", state)
396+
if buildutil.CrdbTestBuild && state.queued == 0 {
397+
log.Fatalf(ctx, "raftSchedulerShard.worker called with zero queued: %+v", state)
398398
}
399-
lat := state.begin.Elapsed()
399+
lat := state.queued.Elapsed()
400400
metrics.RaftSchedulerLatency.RecordValue(int64(lat))
401401

402402
// Process requests first. This avoids a scenario where a tick and a
@@ -470,7 +470,7 @@ func (ss *raftSchedulerShard) worker(
470470
// can not possibly happen before the current processing is done (i.e.
471471
// now). We do not want the scheduler latency to pick up the time spent
472472
// handling this replica.
473-
state.begin = crtime.NowMono()
473+
state.queued = crtime.NowMono()
474474
ss.state[id] = state
475475
ss.queue.Push(id)
476476
}
@@ -503,10 +503,10 @@ func (ss *raftSchedulerShard) enqueue1Locked(
503503
if newState.flags&stateQueued == 0 {
504504
newState.flags |= stateQueued
505505
queued++
506-
if buildutil.CrdbTestBuild && newState.begin != 0 {
507-
log.Fatalf(context.Background(), "raftSchedulerShard.enqueue1Locked called with non-zero begin: %+v", newState)
506+
if buildutil.CrdbTestBuild && newState.queued != 0 {
507+
log.Fatalf(context.Background(), "raftSchedulerShard.enqueue1Locked called with non-zero queued: %+v", newState)
508508
}
509-
newState.begin = now
509+
newState.queued = now
510510
ss.queue.Push(id)
511511
}
512512
ss.state[id] = newState

pkg/kv/kvserver/scheduler_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,9 @@ func TestSchedulerEnqueueWhileProcessing(t *testing.T) {
390390
p.testEventCh <- func(id roachpb.RangeID, ss *raftSchedulerShard, ev raftScheduleState) {
391391
// First call into this method.
392392
//
393-
// The event calling into us must have `ev.begin` set; it was set when
393+
// The event calling into us must have `ev.queued` set; it was set when
394394
// enqueuing.
395-
assert.NotZero(t, ev.begin)
395+
assert.NotZero(t, ev.queued)
396396

397397
// Even though our event is currently being processed, there is a queued
398398
// and otherwise blank event in the scheduler state (which is how we have
@@ -402,7 +402,7 @@ func TestSchedulerEnqueueWhileProcessing(t *testing.T) {
402402
statePre := ss.state[id]
403403
ss.Unlock()
404404

405-
assert.Zero(t, statePre.begin)
405+
assert.Zero(t, statePre.queued)
406406
assert.Equal(t, stateQueued, statePre.flags)
407407

408408
// Simulate a concurrent actor that enqueues the same range again.
@@ -411,21 +411,21 @@ func TestSchedulerEnqueueWhileProcessing(t *testing.T) {
411411
s.enqueue1(stateTestIntercept, 1)
412412

413413
// Seeing that there is an existing "queued" event, the enqueue call below
414-
// should not populate `begin`. Instead, this will be the job of our
414+
// should not populate `queued`. Instead, this will be the job of our
415415
// caller when it *actually* pushes into the queue again after fully
416416
// having handled `ev`.
417417
ss.Lock()
418418
statePost := ss.state[id]
419419
ss.Unlock()
420420

421-
assert.Zero(t, statePost.begin)
421+
assert.Zero(t, statePost.queued)
422422
assert.Equal(t, stateQueued|stateTestIntercept, statePost.flags)
423423
close(done)
424424
}
425425
p.testEventCh <- func(id roachpb.RangeID, shard *raftSchedulerShard, ev raftScheduleState) {
426426
// Second call into this method, i.e. the overlappingly-enqeued event is
427-
// being processed. Check that `begin` is now set.
428-
assert.NotZero(t, ev.begin)
427+
// being processed. Check that `queued` is now set.
428+
assert.NotZero(t, ev.queued)
429429
}
430430
s.enqueue1(stateTestIntercept, 1) // will become 'ev' in the intercept
431431
select {

0 commit comments

Comments
 (0)