Skip to content

Commit ecafb7b

Browse files
committed
kvserver: explain an invariant
1 parent d284218 commit ecafb7b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/kv/kvserver/scheduler.go

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

145145
type raftScheduleState struct {
146-
flags raftScheduleFlags
146+
flags raftScheduleFlags
147+
// When this event was queued. This is set if and only if the item is present
148+
// in the raft scheduler shard's queue.
147149
queued crtime.Mono
148150

149151
// The number of ticks queued. Usually it's 0 or 1, but may go above if the
@@ -392,10 +394,11 @@ func (ss *raftSchedulerShard) worker(
392394
ss.state[id] = raftScheduleState{flags: stateQueued}
393395
ss.Unlock()
394396

395-
// Record the scheduling latency for the range.
396397
if buildutil.CrdbTestBuild && state.queued == 0 {
398+
// See state.queued for the invariant being checked here.
397399
log.Fatalf(ctx, "raftSchedulerShard.worker called with zero queued: %+v", state)
398400
}
401+
// Record the scheduling latency for the range.
399402
lat := state.queued.Elapsed()
400403
metrics.RaftSchedulerLatency.RecordValue(int64(lat))
401404

@@ -504,6 +507,7 @@ func (ss *raftSchedulerShard) enqueue1Locked(
504507
newState.flags |= stateQueued
505508
queued++
506509
if buildutil.CrdbTestBuild && newState.queued != 0 {
510+
// See newState.queued for the invariant being checked here.
507511
log.Fatalf(context.Background(), "raftSchedulerShard.enqueue1Locked called with non-zero queued: %+v", newState)
508512
}
509513
newState.queued = now

0 commit comments

Comments
 (0)