Skip to content

Commit 3f23b10

Browse files
craig[bot]wenyihu6
andcommitted
Merge #152508
152508: kvserver: small changes r=arulajmani a=wenyihu6 Epic: none Release note: none ---- **allocator: move isDecommissionAction to allocatorimpl** This commit refactors isDecommissionAction into allocatorimpl for consistency with other similar helpers like allocatorActions.{Add,Replace,Remove}. This change has no behavior changes but to make future commits easier. --- **kvserver: simplify logging in maybeEnqueueProblemRange** This commit simplifies the logging in `maybeEnqueueProblemRange` to log two booleans directly. --- **kvserver: fix comment when dropping due to exceeding size** Previously, the comment on the queue incorrectly stated that it removes the lowest-priority element when exceeding its maximum size. This was misleading because heap only guarantees that the root is the highest priority, not that elements are globally ordered. This commit updates the comment to clarify that the removed element might not be the lowest priority. Ideally, we should drop the lowest priority element when exceeding queue size, but heap doesn't make this very easy. --- **kvserver: add logging for ranges dropped from base queue** This commit adds logging for ranges dropped from the base queue due to exceeding max size, improving observability. The log is gated behind V(1) to avoid verbosity on nodes with many ranges. Co-authored-by: wenyihu6 <[email protected]>
2 parents b39295a + ed6c55e commit 3f23b10

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ func (a AllocatorAction) Remove() bool {
163163
a == AllocatorRemoveDecommissioningNonVoter
164164
}
165165

166+
// Decommissioning indicates an action replacing or removing a decommissioning
167+
// replicas.
168+
func (a AllocatorAction) Decommissioning() bool {
169+
return a == AllocatorRemoveDecommissioningVoter ||
170+
a == AllocatorRemoveDecommissioningNonVoter ||
171+
a == AllocatorReplaceDecommissioningVoter ||
172+
a == AllocatorReplaceDecommissioningNonVoter
173+
}
174+
166175
// TargetReplicaType returns that the action is for a voter or non-voter replica.
167176
func (a AllocatorAction) TargetReplicaType() TargetReplicaType {
168177
var t TargetReplicaType

pkg/kv/kvserver/queue.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,16 @@ func (bq *baseQueue) addInternal(
766766
item = &replicaItem{rangeID: desc.RangeID, replicaID: replicaID, priority: priority}
767767
bq.addLocked(item)
768768

769-
// If adding this replica has pushed the queue past its maximum size,
770-
// remove the lowest priority element.
769+
// If adding this replica has pushed the queue past its maximum size, remove
770+
// an element. Note that it might not be the lowest priority since heap is not
771+
// guaranteed to be globally ordered. Ideally, we would remove the lowest
772+
// priority element, but it would require additional bookkeeping or a linear
773+
// scan.
771774
if pqLen := bq.mu.priorityQ.Len(); pqLen > bq.maxSize {
772-
bq.removeLocked(bq.mu.priorityQ.sl[pqLen-1])
775+
replicaItemToDrop := bq.mu.priorityQ.sl[pqLen-1]
776+
log.Dev.VInfof(ctx, 1, "dropping due to exceeding queue max size: priority=%0.3f, replica=%v",
777+
priority, replicaItemToDrop.replicaID)
778+
bq.removeLocked(replicaItemToDrop)
773779
}
774780
// Signal the processLoop that a replica has been added.
775781
select {

pkg/kv/kvserver/replica.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,15 +2930,8 @@ func (r *Replica) maybeEnqueueProblemRange(
29302930
if !isLeaseholder || !leaseValid {
29312931
// The replicate queue will not process the replica without a valid lease.
29322932
// Track when we skip enqueuing for these reasons.
2933-
boolToInt := func(b bool) int {
2934-
if b {
2935-
return 1
2936-
}
2937-
return 0
2938-
}
2939-
reasons := []string{"is not the leaseholder", "the lease is not valid"}
2940-
reason := reasons[boolToInt(isLeaseholder)]
2941-
log.KvDistribution.VInfof(ctx, 1, "not enqueuing replica %s because %s", r.Desc(), reason)
2933+
log.KvDistribution.Infof(ctx, "not enqueuing replica %s because isLeaseholder=%t, leaseValid=%t",
2934+
r.Desc(), isLeaseholder, leaseValid)
29422935
r.store.metrics.DecommissioningNudgerNotLeaseholderOrInvalidLease.Inc(1)
29432936
return
29442937
}

pkg/kv/kvserver/replicate_queue.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -923,19 +923,12 @@ func (rq *replicateQueue) processOneChange(
923923
}
924924

925925
func maybeAnnotateDecommissionErr(err error, action allocatorimpl.AllocatorAction) error {
926-
if err != nil && isDecommissionAction(action) {
926+
if err != nil && action.Decommissioning() {
927927
err = decommissionPurgatoryError{err}
928928
}
929929
return err
930930
}
931931

932-
func isDecommissionAction(action allocatorimpl.AllocatorAction) bool {
933-
return action == allocatorimpl.AllocatorRemoveDecommissioningVoter ||
934-
action == allocatorimpl.AllocatorRemoveDecommissioningNonVoter ||
935-
action == allocatorimpl.AllocatorReplaceDecommissioningVoter ||
936-
action == allocatorimpl.AllocatorReplaceDecommissioningNonVoter
937-
}
938-
939932
// shedLease takes in a leaseholder replica, looks for a target for transferring
940933
// the lease and, if a suitable target is found (e.g. alive, not draining),
941934
// transfers the lease away.

0 commit comments

Comments
 (0)