Skip to content

Commit b744cfc

Browse files
committed
allocatorimpl: adds a priority assertion to computeAction
This commit adds an assertion to Allocator.ComputeAction to ensure that priority is never -1 in cases where it shouldn’t be. Normally, ComputeAction returns action.Priority(), but we sometimes adjust the priority for specific actions like AllocatorAddVoter, AllocatorRemoveDeadVoter, and AllocatorRemoveVoter. A priority of -1 is a special case reserved for processing logic to run even if there’s a priority inversion. If the priority is not -1, the range may be re-queued to be processed with the correct priority.
1 parent 18b8e6b commit b744cfc

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pkg/kv/kvserver/allocator/allocatorimpl/allocator.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/cockroachdb/cockroach/pkg/roachpb"
2828
"github.com/cockroachdb/cockroach/pkg/settings"
2929
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
30+
"github.com/cockroachdb/cockroach/pkg/util/buildutil"
3031
"github.com/cockroachdb/cockroach/pkg/util/log"
3132
"github.com/cockroachdb/cockroach/pkg/util/metric"
3233
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
@@ -946,8 +947,21 @@ func (a *Allocator) ComputeAction(
946947
return action, action.Priority()
947948
}
948949

949-
return a.computeAction(ctx, storePool, conf, desc.Replicas().VoterDescriptors(),
950+
action, priority = a.computeAction(ctx, storePool, conf, desc.Replicas().VoterDescriptors(),
950951
desc.Replicas().NonVoterDescriptors())
952+
// Ensure that priority is never -1. Typically, computeAction return
953+
// action.Priority(), but we sometimes modify the priority for specific
954+
// actions like AllocatorAddVoter, AllocatorRemoveDeadVoter, and
955+
// AllocatorRemoveVoter. A priority of -1 is a special case, indicating that
956+
// the caller expects the processing logic to be invoked even if there's a
957+
// priority inversion. If the priority is not -1, the range might be re-queued
958+
// to be processed with the correct priority.
959+
if priority == -1 && buildutil.CrdbTestBuild {
960+
log.Fatalf(ctx, "allocator returned -1 priority for range %s: %v", desc, action)
961+
} else {
962+
log.Warningf(ctx, "allocator returned -1 priority for range %s: %v", desc, action)
963+
}
964+
return action, priority
951965
}
952966

953967
func (a *Allocator) computeAction(

0 commit comments

Comments
 (0)