Skip to content

Commit ad60270

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 f54cc67 commit ad60270

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
@@ -815,21 +815,24 @@ func (bq *baseQueue) addInternal(
815815
replicaID roachpb.ReplicaID,
816816
priority float64,
817817
cb processCallback,
818-
) (bool, error) {
818+
) (added bool, err error) {
819+
defer func() {
820+
if err != nil {
821+
cb.onEnqueueResult(-1 /* indexOnHeap */, err)
822+
}
823+
}()
819824
// NB: this is intentionally outside of bq.mu to avoid having to consider
820825
// lock ordering constraints.
821826
if !desc.IsInitialized() {
822827
// We checked this above in MaybeAdd(), but we need to check it
823828
// again for Add().
824-
cb.onEnqueueResult(-1 /*indexOnHeap*/, errReplicaNotInitialized)
825829
return false, errReplicaNotInitialized
826830
}
827831

828832
bq.mu.Lock()
829833
defer bq.mu.Unlock()
830834

831835
if bq.mu.stopped {
832-
cb.onEnqueueResult(-1 /*indexOnHeap*/, errQueueStopped)
833836
return false, errQueueStopped
834837
}
835838

@@ -842,7 +845,6 @@ func (bq *baseQueue) addInternal(
842845
if log.V(3) {
843846
log.Dev.Infof(ctx, "queue disabled")
844847
}
845-
cb.onEnqueueResult(-1 /*indexOnHeap*/, errQueueDisabled)
846848
return false, errQueueDisabled
847849
}
848850
}

0 commit comments

Comments
 (0)