@@ -234,10 +234,16 @@ type raftScheduler struct {
234
234
done sync.WaitGroup
235
235
}
236
236
237
+ type queuedRangeID struct {
238
+ rangeID roachpb.RangeID
239
+ // queued is the moment in time when the rangeID was added to the queue.
240
+ queued crtime.Mono
241
+ }
242
+
237
243
type raftSchedulerShard struct {
238
244
syncutil.Mutex
239
245
cond * sync.Cond
240
- queue rangeIDQueue [roachpb. RangeID ]
246
+ queue rangeIDQueue [queuedRangeID ]
241
247
state map [roachpb.RangeID ]raftScheduleState
242
248
numWorkers int
243
249
maxTicks int64
@@ -365,14 +371,14 @@ func (ss *raftSchedulerShard) worker(
365
371
366
372
ss .Lock ()
367
373
for {
368
- var id roachpb. RangeID
374
+ var q queuedRangeID
369
375
for {
370
376
if ss .stopped {
371
377
ss .Unlock ()
372
378
return
373
379
}
374
380
var ok bool
375
- if id , ok = ss .queue .PopFront (); ok {
381
+ if q , ok = ss .queue .PopFront (); ok {
376
382
break
377
383
}
378
384
ss .cond .Wait ()
@@ -381,8 +387,8 @@ func (ss *raftSchedulerShard) worker(
381
387
// Grab and clear the existing state for the range ID. Note that we leave
382
388
// the range ID marked as "queued" so that a concurrent Enqueue* will not
383
389
// queue the range ID again.
384
- state := ss .state [id ]
385
- ss .state [id ] = raftScheduleState {flags : stateQueued }
390
+ state := ss .state [q . rangeID ]
391
+ ss .state [q . rangeID ] = raftScheduleState {flags : stateQueued }
386
392
ss .Unlock ()
387
393
388
394
if util .RaceEnabled && state .queued == 0 {
@@ -400,7 +406,7 @@ func (ss *raftSchedulerShard) worker(
400
406
if state .flags & stateRaftRequest != 0 {
401
407
// processRequestQueue returns true if the range should perform ready
402
408
// processing. Do not reorder this below the call to processReady.
403
- if processor .processRequestQueue (ctx , id ) {
409
+ if processor .processRequestQueue (ctx , q . rangeID ) {
404
410
state .flags |= stateRaftReady
405
411
}
406
412
}
@@ -413,30 +419,30 @@ func (ss *raftSchedulerShard) worker(
413
419
for t := state .ticks ; t > 0 ; t -- {
414
420
// processRaftTick returns true if the range should perform ready
415
421
// processing. Do not reorder this below the call to processReady.
416
- if processor .processTick (ctx , id ) {
422
+ if processor .processTick (ctx , q . rangeID ) {
417
423
state .flags |= stateRaftReady
418
424
}
419
425
}
420
426
}
421
427
if state .flags & stateRACv2PiggybackedAdmitted != 0 {
422
- processor .processRACv2PiggybackedAdmitted (ctx , id )
428
+ processor .processRACv2PiggybackedAdmitted (ctx , q . rangeID )
423
429
}
424
430
if state .flags & stateRaftReady != 0 {
425
- processor .processReady (id )
431
+ processor .processReady (q . rangeID )
426
432
}
427
433
if state .flags & stateRACv2RangeController != 0 {
428
- processor .processRACv2RangeController (ctx , id )
434
+ processor .processRACv2RangeController (ctx , q . rangeID )
429
435
}
430
436
if buildutil .CrdbTestBuild && state .flags & stateTestIntercept != 0 {
431
- processor .(testProcessorI ).processTestEvent (id , ss , state )
437
+ processor .(testProcessorI ).processTestEvent (q . rangeID , ss , state )
432
438
}
433
439
434
440
ss .Lock ()
435
- state = ss .state [id ]
441
+ state = ss .state [q . rangeID ]
436
442
if state .flags == stateQueued {
437
443
// No further processing required by the range ID, clear it from the
438
444
// state map.
439
- delete (ss .state , id )
445
+ delete (ss .state , q . rangeID )
440
446
} else {
441
447
// There was a concurrent call to one of the Enqueue* methods. Queue
442
448
// the range ID for further processing.
@@ -465,8 +471,8 @@ func (ss *raftSchedulerShard) worker(
465
471
// now). We do not want the scheduler latency to pick up the time spent
466
472
// handling this replica.
467
473
state .queued = crtime .NowMono ()
468
- ss .state [id ] = state
469
- ss .queue .Push (id )
474
+ ss .state [q . rangeID ] = state
475
+ ss .queue .Push (queuedRangeID { rangeID : q . rangeID , queued : state . queued } )
470
476
}
471
477
}
472
478
}
@@ -502,7 +508,7 @@ func (ss *raftSchedulerShard) enqueue1Locked(
502
508
log .Fatalf (context .Background (), "raftSchedulerShard.enqueue1Locked called with non-zero queued: %+v" , newState )
503
509
}
504
510
newState .queued = now
505
- ss .queue .Push (id )
511
+ ss .queue .Push (queuedRangeID { rangeID : id , queued : now } )
506
512
}
507
513
ss .state [id ] = newState
508
514
return queued
0 commit comments