@@ -139,6 +139,7 @@ const (
139
139
AllocatorConsiderRebalance
140
140
AllocatorRangeUnavailable
141
141
AllocatorFinalizeAtomicReplicationChange
142
+ AllocatorMaxPriority
142
143
)
143
144
144
145
// Add indicates an action adding a replica.
@@ -267,9 +268,12 @@ func (a AllocatorAction) SafeValue() {}
267
268
// predate this comment, so we allow them as they belong to the same general
268
269
// priority category.
269
270
func (a AllocatorAction ) Priority () float64 {
271
+ const maxPriority = 12002
270
272
switch a {
273
+ case AllocatorMaxPriority :
274
+ return maxPriority
271
275
case AllocatorFinalizeAtomicReplicationChange :
272
- return 12002
276
+ return maxPriority
273
277
case AllocatorRemoveLearner :
274
278
return 12001
275
279
case AllocatorReplaceDeadVoter :
@@ -3309,12 +3313,6 @@ func roundToNearestPriorityCategory(n float64) float64 {
3309
3313
return math .Round (n / 100.0 ) * 100
3310
3314
}
3311
3315
3312
- // WithinPriorityRange checks if a priority is within the range of possible
3313
- // priorities for the allocator actions.
3314
- func withinPriorityRange (priority float64 ) bool {
3315
- return AllocatorNoop .Priority () <= priority && priority <= AllocatorFinalizeAtomicReplicationChange .Priority ()
3316
- }
3317
-
3318
3316
// CheckPriorityInversion returns whether there was a priority inversion (and
3319
3317
// the range should not be processed at this time, since doing so could starve
3320
3318
// higher-priority items), and whether the caller should re-add the range to the
@@ -3333,18 +3331,20 @@ func withinPriorityRange(priority float64) bool {
3333
3331
func CheckPriorityInversion (
3334
3332
priorityAtEnqueue float64 , actionAtProcessing AllocatorAction ,
3335
3333
) (isInversion bool , shouldRequeue bool ) {
3336
- // priorityAtEnqueue of -1 is a special case reserved for processing logic to
3337
- // run even if there’s a priority inversion. If the priority is not -1, the
3338
- // range may be re-queued to be processed with the correct priority. It is
3339
- // used for things that call into baseQueue.process without going through the
3340
- // replicate priority queue. For example, s.ReplicateQueueDryRun or
3341
- // r.scatterRangeAndRandomizeLeases.
3334
+ // NB: priorityAtEnqueue is -1 for callers such as scatter, dry runs, and
3335
+ // manual queue runs. Priority inversion does not apply to these calls.
3336
+ if priorityAtEnqueue == - 1 {
3337
+ return false , false
3338
+ }
3342
3339
3343
3340
// NB: we need to check for when priorityAtEnqueue falls within the range
3344
3341
// of the allocator actions because store.Enqueue might enqueue things with
3345
3342
// a very high priority (1e5). In those cases, we do not want to requeue
3346
3343
// these actions or count it as an inversion.
3347
- if priorityAtEnqueue == - 1 || ! withinPriorityRange (priorityAtEnqueue ) {
3344
+ withinPriorityRange := func (priority float64 ) bool {
3345
+ return AllocatorNoop .Priority () <= priority && priority <= AllocatorMaxPriority .Priority ()
3346
+ }
3347
+ if ! withinPriorityRange (priorityAtEnqueue ) {
3348
3348
return false , false
3349
3349
}
3350
3350
0 commit comments