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 defaultShardHandlerimplementation; 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. SeeHttpShardHandlerFactoryfor 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 classHttpShardHandler.SimpleSolrResponse
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.solr.client.solrj.impl.LBHttp2SolrClientlbClientstatic StringONLY_NRT_REPLICASIf the request context map has an entry with this key and Boolean.TRUE as value,prepDistributed(ResponseBuilder)will only includeReplica.Type.NRTreplicas as possible destination of the distributed request (or a leader replica of typeReplica.Type.TLOG).protected ConcurrentMap<ShardResponse,CompletableFuture<org.apache.solr.client.solrj.impl.LBSolrClient.Rsp>>responseFutureMapprotected 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 voidcancelAll()Cancels all uncompleted requests managed by this instanceprotected org.apache.solr.client.solrj.request.QueryRequestcreateQueryRequest(ShardRequest sreq, org.apache.solr.common.params.ModifiableSolrParams params, String shard)Subclasses could modify the request based on the shardShardHandlerFactorygetShardHandlerFactory()static booleangetShardsTolerantAsBool(SolrQueryRequest req)Parse the "shards.tolerant" param fromparamsas a boolean; accepts "requireZkConnected" as a valid value indicatingfalse.protected voidmakeShardRequest(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 responsevoidprepDistributed(ResponseBuilder rb)Bootstraps any data structures needed by the ShardHandler to execute or track outgoing requests.protected voidrecordShardSubmitError(ShardResponse srsp, org.apache.solr.common.SolrException exception)protected booleanresponsesPending()voidsubmit(ShardRequest sreq, String shard, org.apache.solr.common.params.ModifiableSolrParams params)Sends a request (represented bysreq) to the specified shard.ShardResponsetakeCompletedIncludingErrors()Returns a ShardResponse of the last response correlated with a ShardRequest.ShardResponsetakeCompletedOrError()Returns a ShardResponse of the last response correlated with a ShardRequest, or immediately returns a ShardResponse if there was an error detected.protected ShardResponsetransformResponse(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 final 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.NRTreplicas 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- See Also:
- Constant Field Values
-
responseFutureMap
protected final ConcurrentMap<ShardResponse,CompletableFuture<org.apache.solr.client.solrj.impl.LBSolrClient.Rsp>> responseFutureMap
-
responses
protected final BlockingQueue<ShardResponse> responses
-
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 fromparamsas a boolean; accepts "requireZkConnected" as a valid value indicatingfalse.By default, returns
falsewhen "shards.tolerant" is not set inparams.
-
recordShardSubmitError
protected void recordShardSubmitError(ShardResponse srsp, org.apache.solr.common.SolrException exception)
-
submit
public void submit(ShardRequest sreq, String shard, org.apache.solr.common.params.ModifiableSolrParams params)
Description copied from class:ShardHandlerSends 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:
submitin 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:ShardHandlerReturns 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:
takeCompletedIncludingErrorsin classShardHandler
-
takeCompletedOrError
public ShardResponse takeCompletedOrError()
Description copied from class:ShardHandlerReturns 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:
takeCompletedOrErrorin classShardHandler
-
responsesPending
protected boolean responsesPending()
-
cancelAll
public void cancelAll()
Description copied from class:ShardHandlerCancels all uncompleted requests managed by this instance- Specified by:
cancelAllin classShardHandler
-
prepDistributed
public void prepDistributed(ResponseBuilder rb)
Description copied from class:ShardHandlerBootstraps any data structures needed by the ShardHandler to execute or track outgoing requests.- Specified by:
prepDistributedin classShardHandler- Parameters:
rb- provides access to request and response state.
-
getShardHandlerFactory
public ShardHandlerFactory getShardHandlerFactory()
- Specified by:
getShardHandlerFactoryin classShardHandler
-
-