Skip to content

Commit ccb5a00

Browse files
committed
kvserver: call cb.onEnqueueResult in defer on errors
Previously, cb.onEnqueueResult was invoked inline before returning errors, which was less robust and required explicit calls. This commit refactors the code to invoke onEnqueueResult in a defer statement when returning a non-nil error. Note that the function may still call cb.onEnqueueResult with non-nil errors even when no error is returned, since we want visibility into those cases as well.
1 parent 8691d33 commit ccb5a00

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pkg/kv/kvserver/queue.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,21 +839,24 @@ func (bq *baseQueue) addInternal(
839839
replicaID roachpb.ReplicaID,
840840
priority float64,
841841
cb processCallback,
842-
) (bool, error) {
842+
) (added bool, err error) {
843+
defer func() {
844+
if err != nil {
845+
cb.onEnqueueResult(-1 /* indexOnHeap */, err)
846+
}
847+
}()
843848
// NB: this is intentionally outside of bq.mu to avoid having to consider
844849
// lock ordering constraints.
845850
if !desc.IsInitialized() {
846851
// We checked this above in MaybeAdd(), but we need to check it
847852
// again for Add().
848-
cb.onEnqueueResult(-1 /*indexOnHeap*/, errReplicaNotInitialized)
849853
return false, errReplicaNotInitialized
850854
}
851855

852856
bq.mu.Lock()
853857
defer bq.mu.Unlock()
854858

855859
if bq.mu.stopped {
856-
cb.onEnqueueResult(-1 /*indexOnHeap*/, errQueueStopped)
857860
return false, errQueueStopped
858861
}
859862

@@ -866,7 +869,6 @@ func (bq *baseQueue) addInternal(
866869
if log.V(3) {
867870
log.Infof(ctx, "queue disabled")
868871
}
869-
cb.onEnqueueResult(-1 /*indexOnHeap*/, errQueueDisabled)
870872
return false, errQueueDisabled
871873
}
872874
}

0 commit comments

Comments
 (0)