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 default ShardHandler 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 via HttpShardHandlerFactory.commExecutor. See HttpShardHandlerFactory for details on configuring this executor.

The ideal choice for collections with modest or moderate sharding.

  • Field Details

    • 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 include Replica.Type.NRT replicas as possible destination of the distributed request (or a leader replica of type Replica.Type.TLOG). This is used by the RealtimeGet handler, since other types of replicas shouldn't respond to RTG requests
      See Also:
    • 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.LBAsyncSolrClient lbClient
  • Constructor Details

  • Method Details

    • getShardsTolerantAsBool

      public static boolean getShardsTolerantAsBool(SolrQueryRequest req)
      Parse the "shards.tolerant" param from params as a boolean; accepts "requireZkConnected" as a valid value indicating false .

      By default, returns false when "shards.tolerant" is not set in params.

    • 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: ShardHandler
      Sends a request (represented by sreq) to the specified shard.

      The outgoing request may be sent asynchronously. Callers must invoke ShardHandler.takeCompletedIncludingErrors() or ShardHandler.takeCompletedOrError() to inspect the success or failure of requests.

      Specified by:
      submit in class ShardHandler
      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 make
      shard - the shard to address
      params - request parameters
      lbReq - the load balanced request
      ssr - the response collector part 1
      srsp - the shard response collector
      startTimeNS - 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 class ShardHandler
    • 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 class ShardHandler
    • 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 class ShardHandler
    • 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 class ShardHandler
      Parameters:
      rb - provides access to request and response state.
    • getShardHandlerFactory

      public ShardHandlerFactory getShardHandlerFactory()
      Specified by:
      getShardHandlerFactory in class ShardHandler