Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit d92692a

Browse files
committed
leverage in-flight requests of other replicas to possibly overcome shard query errors
fix #1817
1 parent d53477c commit d92692a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

api/cluster.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ type shardResponse struct {
528528
type shardState struct {
529529
shard int32 // shard ID
530530
remainingPeers []cluster.Node // peers that we have not sent a query to yet
531+
inflight int // number of requests in flight
531532
}
532533

533534
// AskPeer issues the query on the next peer, if available, and returns it
@@ -537,6 +538,7 @@ func (state *shardState) AskPeer(ctx context.Context, fn fetchFunc, responses ch
537538
}
538539
peer := state.remainingPeers[0]
539540
state.remainingPeers = state.remainingPeers[1:]
541+
state.inflight++
540542
go state.askPeer(ctx, peer, fn, responses)
541543
return peer, true
542544
}
@@ -611,6 +613,8 @@ func queryPeers(ctx context.Context, peerGroups map[int32][]cluster.Node, name s
611613
//request canceled
612614
return
613615
case resp := <-responses:
616+
states[resp.shardGroup].inflight--
617+
614618
if _, ok := receivedResponses[resp.shardGroup]; ok {
615619
// already received this response (possibly speculatively)
616620
continue
@@ -623,8 +627,11 @@ func queryPeers(ctx context.Context, peerGroups map[int32][]cluster.Node, name s
623627
speculativeRequests.Inc()
624628
continue
625629
}
626-
// No more peers to try. Cancel the reqCtx, which will cancel all in-flight
627-
// requests.
630+
// if there is another request in-flight for this shardGroup, then we can wait for that
631+
if states[resp.shardGroup].inflight > 0 {
632+
continue
633+
}
634+
// we're out of options. Cancel the reqCtx, which will cancel all in-flight requests.
628635
cancel()
629636
errorChan <- resp.err
630637
return

0 commit comments

Comments
 (0)