Class HttpShardHandler
- java.lang.Object
-
- org.apache.solr.handler.component.ShardHandler
-
- org.apache.solr.handler.component.HttpShardHandler
-
- Direct Known Subclasses:
ParallelHttpShardHandler
@NotThreadSafe public class HttpShardHandler extends ShardHandler
Solr's defaultShardHandler
implementation; uses Jetty's async HTTP Client APIs for sending requests.Shard-requests triggered by
submit(ShardRequest, String, ModifiableSolrParams)
will be sent synchronously (i.e. before 'submit' returns to the caller). Response waiting and parsing happens asynchronously viaHttpShardHandlerFactory.commExecutor
. SeeHttpShardHandlerFactory
for details on configuring this executor.The ideal choice for collections with modest or moderate sharding.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HttpShardHandler.SimpleSolrResponse
-
Field Summary
Fields Modifier and Type Field Description protected Object
FUTURE_MAP_LOCK
protected org.apache.solr.client.solrj.impl.LBHttp2SolrClient
lbClient
static String
ONLY_NRT_REPLICAS
If the request context map has an entry with this key and Boolean.TRUE as value,prepDistributed(ResponseBuilder)
will only includeReplica.Type.NRT
replicas as possible destination of the distributed request (or a leader replica of typeReplica.Type.TLOG
).protected AtomicInteger
pending
The number of pending requests.protected Map<ShardResponse,CompletableFuture<org.apache.solr.client.solrj.impl.LBSolrClient.Rsp>>
responseFutureMap
protected BlockingQueue<ShardResponse>
responses
-
Constructor Summary
Constructors Constructor Description HttpShardHandler(HttpShardHandlerFactory httpShardHandlerFactory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancelAll()
Cancels all uncompleted requests managed by this instanceprotected org.apache.solr.client.solrj.request.QueryRequest
createQueryRequest(ShardRequest sreq, org.apache.solr.common.params.ModifiableSolrParams params, String shard)
Subclasses could modify the request based on the shardShardHandlerFactory
getShardHandlerFactory()
static boolean
getShardsTolerantAsBool(SolrQueryRequest req)
Parse the "shards.tolerant" param fromparams
as a boolean; accepts "requireZkConnected" as a valid value indicatingfalse
.protected void
makeShardRequest(ShardRequest sreq, String shard, org.apache.solr.common.params.ModifiableSolrParams params, org.apache.solr.client.solrj.impl.LBSolrClient.Req lbReq, HttpShardHandler.SimpleSolrResponse ssr, ShardResponse srsp, long startTimeNS)
Do the actual work of sending a request to a shard and receiving the responsevoid
prepDistributed(ResponseBuilder rb)
Bootstraps any data structures needed by the ShardHandler to execute or track outgoing requests.protected boolean
responsesPending()
void
submit(ShardRequest sreq, String shard, org.apache.solr.common.params.ModifiableSolrParams params)
Sends a request (represented bysreq
) to the specified shard.ShardResponse
takeCompletedIncludingErrors()
Returns a ShardResponse of the last response correlated with a ShardRequest.ShardResponse
takeCompletedOrError()
Returns a ShardResponse of the last response correlated with a ShardRequest, or immediately returns a ShardResponse if there was an error detected.protected ShardResponse
transformResponse(ShardRequest sreq, ShardResponse rsp, String shard)
Subclasses could modify the Response based on the shard-
Methods inherited from class org.apache.solr.handler.component.ShardHandler
setShardAttributesToParams
-
-
-
-
Field Detail
-
ONLY_NRT_REPLICAS
public static String ONLY_NRT_REPLICAS
If the request context map has an entry with this key and Boolean.TRUE as value,prepDistributed(ResponseBuilder)
will only includeReplica.Type.NRT
replicas as possible destination of the distributed request (or a leader replica of typeReplica.Type.TLOG
). This is used by the RealtimeGet handler, since other types of replicas shouldn't respond to RTG requests
-
FUTURE_MAP_LOCK
protected final Object FUTURE_MAP_LOCK
-
responseFutureMap
protected Map<ShardResponse,CompletableFuture<org.apache.solr.client.solrj.impl.LBSolrClient.Rsp>> responseFutureMap
-
responses
protected BlockingQueue<ShardResponse> responses
-
pending
protected AtomicInteger pending
The number of pending requests. This must be incremented before aShardResponse
is added toresponses
, and decremented after a ShardResponse is removed fromresponses
. We can't rely on responseFutureMap.size() because it is an unsynchronized collection updated by multiple threads, and it's internal state including the size field is not volatile/synchronized.
-
lbClient
protected org.apache.solr.client.solrj.impl.LBHttp2SolrClient lbClient
-
-
Constructor Detail
-
HttpShardHandler
public HttpShardHandler(HttpShardHandlerFactory httpShardHandlerFactory)
-
-
Method Detail
-
getShardsTolerantAsBool
public static boolean getShardsTolerantAsBool(SolrQueryRequest req)
Parse the "shards.tolerant" param fromparams
as a boolean; accepts "requireZkConnected" as a valid value indicatingfalse
.By default, returns
false
when "shards.tolerant" is not set inparams
.
-
submit
public void submit(ShardRequest sreq, String shard, org.apache.solr.common.params.ModifiableSolrParams params)
Description copied from class:ShardHandler
Sends a request (represented bysreq
) to the specified shard.The outgoing request may be sent asynchronously. Callers must invoke
ShardHandler.takeCompletedIncludingErrors()
orShardHandler.takeCompletedOrError()
to inspect the success or failure of requests.- Specified by:
submit
in classShardHandler
- Parameters:
sreq
- metadata about the series of sub-requests that the outgoing request belongs to and should be tracked with.shard
- URLs for replicas of the receiving shard, delimited by '|' (e.g. "http://solr1:8983/solr/foo1|http://solr2:7574/solr/foo2")params
- query-parameters set on the outgoing request
-
makeShardRequest
protected void makeShardRequest(ShardRequest sreq, String shard, org.apache.solr.common.params.ModifiableSolrParams params, org.apache.solr.client.solrj.impl.LBSolrClient.Req lbReq, HttpShardHandler.SimpleSolrResponse ssr, ShardResponse srsp, long startTimeNS)
Do the actual work of sending a request to a shard and receiving the response- Parameters:
sreq
- the request to makeshard
- the shard to addressparams
- request parameterslbReq
- the load balanced request suitable for LBHttp2SolrClientssr
- the response collector part 1srsp
- the shard response collectorstartTimeNS
- the time at which the request was initiated, likely just prior to calling this method.
-
createQueryRequest
protected org.apache.solr.client.solrj.request.QueryRequest createQueryRequest(ShardRequest sreq, org.apache.solr.common.params.ModifiableSolrParams params, String shard)
Subclasses could modify the request based on the shard
-
transformResponse
protected ShardResponse transformResponse(ShardRequest sreq, ShardResponse rsp, String shard)
Subclasses could modify the Response based on the shard
-
takeCompletedIncludingErrors
public ShardResponse takeCompletedIncludingErrors()
Description copied from class:ShardHandler
Returns a ShardResponse of the last response correlated with a ShardRequest. This won't return early if it runs into an error. Callers are responsible for ensuring that this can't be called before requests have been submitted with submit.- Specified by:
takeCompletedIncludingErrors
in classShardHandler
-
takeCompletedOrError
public ShardResponse takeCompletedOrError()
Description copied from class:ShardHandler
Returns a ShardResponse of the last response correlated with a ShardRequest, or immediately returns a ShardResponse if there was an error detected. Callers are responsible for ensuring that this can't be called before requests have been submitted with submit.- Specified by:
takeCompletedOrError
in classShardHandler
-
responsesPending
protected boolean responsesPending()
-
cancelAll
public void cancelAll()
Description copied from class:ShardHandler
Cancels all uncompleted requests managed by this instance- Specified by:
cancelAll
in classShardHandler
-
prepDistributed
public void prepDistributed(ResponseBuilder rb)
Description copied from class:ShardHandler
Bootstraps any data structures needed by the ShardHandler to execute or track outgoing requests.- Specified by:
prepDistributed
in classShardHandler
- Parameters:
rb
- provides access to request and response state.
-
getShardHandlerFactory
public ShardHandlerFactory getShardHandlerFactory()
- Specified by:
getShardHandlerFactory
in classShardHandler
-
-