Skip to content

Commit 8c80097

Browse files
committed
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.
1 parent cedad11 commit 8c80097

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pkg/kv/kvserver/queue.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,11 @@ 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 {
772775
bq.removeLocked(bq.mu.priorityQ.sl[pqLen-1])
773776
}

0 commit comments

Comments
 (0)