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

Commit a588d9e

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

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 return 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
}
@@ -612,6 +614,8 @@ func queryPeers(ctx context.Context, peerGroups map[int32][]cluster.Node, name s
612614
//request canceled
613615
return
614616
case resp := <-responses:
617+
states[resp.shardGroup].inflight--
618+
615619
if _, ok := receivedResponses[resp.shardGroup]; ok {
616620
// already received this response (possibly speculatively)
617621
continue
@@ -624,8 +628,11 @@ func queryPeers(ctx context.Context, peerGroups map[int32][]cluster.Node, name s
624628
speculativeRequests.Inc()
625629
continue
626630
}
627-
// No more peers to try. Cancel the reqCtx, which will cancel all in-flight
628-
// requests.
631+
// if there is another request in-flight for this shardGroup, then we can wait for that
632+
if states[resp.shardGroup].inflight > 0 {
633+
continue
634+
}
635+
// we're out of options. Cancel the reqCtx, which will cancel all in-flight requests.
629636
cancel()
630637
errorChan <- resp.err
631638
return

0 commit comments

Comments
 (0)