@@ -123,7 +123,9 @@ type replicaItem struct {
123
123
replicaID roachpb.ReplicaID
124
124
seq int // enforce FIFO order for equal priorities
125
125
126
- // fields used when a replicaItem is enqueued in a priority queue.
126
+ // fields used when a replicaItem is enqueued in a priority queue. This field
127
+ // is preserved for purgatory queue as well since baseQueue.processReplica
128
+ // requies it.
127
129
priority float64
128
130
index int // The index of the item in the heap, maintained by the heap.Interface methods
129
131
@@ -260,7 +262,7 @@ type queueImpl interface {
260
262
// queue-specific work on it. The Replica is guaranteed to be initialized.
261
263
// We return a boolean to indicate if the Replica was processed successfully
262
264
// (vs. it being a no-op or an error).
263
- process (context.Context , * Replica , spanconfig.StoreReader ) (processed bool , err error )
265
+ process (context.Context , * Replica , spanconfig.StoreReader , float64 ) (processed bool , err error )
264
266
265
267
// processScheduled is called after async task was created to run process.
266
268
// This function is called by the process loop synchronously. This method is
@@ -870,10 +872,10 @@ func (bq *baseQueue) processLoop(stopper *stop.Stopper) {
870
872
// Acquire from the process semaphore.
871
873
bq .processSem <- struct {}{}
872
874
873
- repl , priority := bq .pop ()
875
+ repl , priorityAtEnqueue := bq .pop ()
874
876
if repl != nil {
875
- bq .processOneAsyncAndReleaseSem (ctx , repl , stopper )
876
- bq .impl .postProcessScheduled (ctx , repl , priority )
877
+ bq .processOneAsyncAndReleaseSem (ctx , repl , stopper , priorityAtEnqueue )
878
+ bq .impl .postProcessScheduled (ctx , repl , priorityAtEnqueue )
877
879
} else {
878
880
// Release semaphore if no replicas were available.
879
881
<- bq .processSem
@@ -901,7 +903,7 @@ func (bq *baseQueue) processLoop(stopper *stop.Stopper) {
901
903
// processOneAsyncAndReleaseSem processes a replica if possible and releases the
902
904
// processSem when the processing is complete.
903
905
func (bq * baseQueue ) processOneAsyncAndReleaseSem (
904
- ctx context.Context , repl replicaInQueue , stopper * stop.Stopper ,
906
+ ctx context.Context , repl replicaInQueue , stopper * stop.Stopper , priorityAtEnqueue float64 ,
905
907
) {
906
908
ctx = repl .AnnotateCtx (ctx )
907
909
taskName := bq .processOpName () + " [outer]"
@@ -917,7 +919,7 @@ func (bq *baseQueue) processOneAsyncAndReleaseSem(
917
919
// Release semaphore when finished processing.
918
920
defer func () { <- bq .processSem }()
919
921
start := timeutil .Now ()
920
- err := bq .processReplica (ctx , repl )
922
+ err := bq .processReplica (ctx , repl , priorityAtEnqueue )
921
923
bq .recordProcessDuration (ctx , timeutil .Since (start ))
922
924
bq .finishProcessingReplica (ctx , stopper , repl , err )
923
925
}); err != nil {
@@ -950,7 +952,9 @@ func (bq *baseQueue) recordProcessDuration(ctx context.Context, dur time.Duratio
950
952
//
951
953
// ctx should already be annotated by both bq.AnnotateCtx() and
952
954
// repl.AnnotateCtx().
953
- func (bq * baseQueue ) processReplica (ctx context.Context , repl replicaInQueue ) error {
955
+ func (bq * baseQueue ) processReplica (
956
+ ctx context.Context , repl replicaInQueue , priorityAtEnqueue float64 ,
957
+ ) error {
954
958
955
959
ctx , span := tracing .EnsureChildSpan (ctx , bq .Tracer , bq .processOpName ())
956
960
defer span .Finish ()
@@ -974,7 +978,7 @@ func (bq *baseQueue) processReplica(ctx context.Context, repl replicaInQueue) er
974
978
// it may not be and shouldQueue will be passed a nil realRepl. These tests
975
979
// know what they're getting into so that's fine.
976
980
realRepl , _ := repl .(* Replica )
977
- processed , err := bq .impl .process (ctx , realRepl , conf )
981
+ processed , err := bq .impl .process (ctx , realRepl , conf , priorityAtEnqueue )
978
982
if err != nil {
979
983
return err
980
984
}
@@ -1315,7 +1319,7 @@ func (bq *baseQueue) processReplicasInPurgatory(
1315
1319
if _ , err := bq .replicaCanBeProcessed (ctx , repl , false ); err != nil {
1316
1320
bq .finishProcessingReplica (ctx , stopper , repl , err )
1317
1321
} else {
1318
- err = bq .processReplica (ctx , repl )
1322
+ err = bq .processReplica (ctx , repl , - 1 /*priorityAtEnqueue*/ )
1319
1323
bq .finishProcessingReplica (ctx , stopper , repl , err )
1320
1324
}
1321
1325
},
@@ -1442,7 +1446,7 @@ func (bq *baseQueue) DrainQueue(ctx context.Context, stopper *stop.Stopper) {
1442
1446
if _ , err := bq .replicaCanBeProcessed (annotatedCtx , repl , false ); err != nil {
1443
1447
bq .finishProcessingReplica (annotatedCtx , stopper , repl , err )
1444
1448
} else {
1445
- err = bq .processReplica (annotatedCtx , repl )
1449
+ err = bq .processReplica (annotatedCtx , repl , - 1 /*priorityAtEnqueue*/ )
1446
1450
bq .finishProcessingReplica (annotatedCtx , stopper , repl , err )
1447
1451
}
1448
1452
}
0 commit comments