Class CloudSolrClient
java.lang.Object
org.apache.solr.client.solrj.SolrClient
org.apache.solr.client.solrj.impl.CloudSolrClient
- All Implemented Interfaces:
Closeable,Serializable,AutoCloseable
- Direct Known Subclasses:
CloudHttp2SolrClient
A
SolrClient that routes requests to ideal nodes, including splitting update batches to
the correct shards. It uses LBSolrClient as well, thus offering fail-over abilities if a
core or node becomes unavailable. It's able to know where to route requests due to its knowledge
of the SolrCloud "cluster state".- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConstructsCloudSolrClientinstances from provided configuration.static classstatic classprotected static classNested classes/interfaces inherited from class org.apache.solr.client.solrj.SolrClient
SolrClient.SolrClientFunction<C extends SolrClient,R> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CloudSolrClient.StateCacheprotected longstatic final StringFields inherited from class org.apache.solr.client.solrj.SolrClient
defaultCollection -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCloudSolrClient(boolean updatesToLeaders, boolean parallelUpdates, boolean directUpdatesToLeadersOnly) protectedCloudSolrClient(boolean updatesToLeaders, boolean parallelUpdates, boolean directUpdatesToLeadersOnly, int stateRefreshThreads) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()condenseResponse(NamedList<?> response, int timeMillis) protected <T extends CloudSolrClient.RouteResponse<?>>
TcondenseResponse(NamedList<?> response, int timeMillis, Supplier<T> supplier) voidconnect()Deprecated.voidDeprecated.protected Map<String, ? extends LBSolrClient.Req> createRoutes(UpdateRequest updateRequest, ModifiableSolrParams routableParams, DocCollection col, DocRouter router, Map<String, List<String>> urlMap, String routeField) Deprecated.problematic as a 'get' method, since one implementation will do a remote request each time this is called, potentially return lots of data that isn't even needed.abstract ClusterStateProviderprotected DocCollectiongetDocCollection(String collection, Integer expectedVersion) protected abstract LBSolrClientintgetMinAchievedReplicationFactor(String collection, NamedList<?> resp) Useful for determining the minimum achieved replication factor across all shards involved in processing an update request, typically useful for gauging the replication factor of a batch.protected CloudSolrClient.RouteExceptiongetRouteException(SolrException.ErrorCode serverError, NamedList<Throwable> exceptions, Map<String, ? extends LBSolrClient.Req> routes) getShardReplicationFactor(String collection, NamedList<?> resp) Walks the NamedList response after performing an update request looking for the replication factor that was achieved in each shard involved in the request.protected intVisible for tests so they can assert the configured refresh parallelism.booleanIf true, this client has been configured such that "direct updates" will only be sent to the current leader of the corresponding shard, and will not be retried with other replicas.booleanGets whether direct updates are sent in parallelbooleanIf true, this client has been configured such that it will generally prefer to sendSolrRequest.SolrRequestType.UPDATErequests to a shard leader, if and only ifUpdateRequest.isSendToLeaders()is also true.request(SolrRequest<?> request, String collection) Execute a request against a Solr server for a given collectionrequestWithRetryOnStaleState(SolrRequest<?> request, int retryCount, List<String> inputCollections, boolean skipStateVersion, Map<String, CompletableFuture<DocCollection>> pendingRefreshes, boolean waitedForRefresh) As this class doesn't watch external collections on the client side, there's a chance that the request will fail due to cached stale state, which means the state must be refreshed from ZK and retried.sendRequest(SolrRequest<?> request, List<String> inputCollections) protected booleanIs this a communication error? We will retry if so.Methods inherited from class org.apache.solr.client.solrj.SolrClient
add, add, add, add, add, add, add, add, add, add, addBean, addBean, addBean, addBean, addBeans, addBeans, addBeans, addBeans, addBeans, addBeans, commit, commit, commit, commit, commit, commit, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteByQuery, deleteByQuery, deleteByQuery, deleteByQuery, getById, getById, getById, getById, getById, getById, getById, getById, getContext, getDefaultCollection, optimize, optimize, optimize, optimize, optimize, optimize, ping, ping, query, query, query, query, queryAndStreamResponse, queryAndStreamResponse, queryAndStreamResponse, request, rollback, rollback
-
Field Details
-
STATE_VERSION
- See Also:
-
retryExpiryTimeNano
protected long retryExpiryTimeNano -
collectionStateCache
-
-
Constructor Details
-
CloudSolrClient
protected CloudSolrClient(boolean updatesToLeaders, boolean parallelUpdates, boolean directUpdatesToLeadersOnly) -
CloudSolrClient
protected CloudSolrClient(boolean updatesToLeaders, boolean parallelUpdates, boolean directUpdatesToLeadersOnly, int stateRefreshThreads)
-
-
Method Details
-
getLbClient
-
getClusterStateProvider
-
getClusterState
Deprecated.problematic as a 'get' method, since one implementation will do a remote request each time this is called, potentially return lots of data that isn't even needed. -
wasCommError
Is this a communication error? We will retry if so. -
close
public void close() -
getParser
-
getRequestWriter
-
isParallelUpdates
public boolean isParallelUpdates()Gets whether direct updates are sent in parallel -
connect
Deprecated.CallClusterStateProvider.getLiveNodes()instead.Connect to the zookeeper ensemble. This is an optional method that may be used to force a connection before any other requests are sent. -
connect
@Deprecated public void connect(long duration, TimeUnit timeUnit) throws TimeoutException, InterruptedException Deprecated.Connect to a cluster. If the cluster is not ready, retry connection up to a given timeout.- Parameters:
duration- the timeouttimeUnit- the units of the timeout- Throws:
TimeoutException- if the cluster is not ready after the timeoutInterruptedException- if the wait is interrupted
-
getRouteException
protected CloudSolrClient.RouteException getRouteException(SolrException.ErrorCode serverError, NamedList<Throwable> exceptions, Map<String, ? extends LBSolrClient.Req> routes) -
createRoutes
protected Map<String,? extends LBSolrClient.Req> createRoutes(UpdateRequest updateRequest, ModifiableSolrParams routableParams, DocCollection col, DocRouter router, Map<String, List<String>> urlMap, String routeField) -
condenseResponse
protected <T extends CloudSolrClient.RouteResponse<?>> T condenseResponse(NamedList<?> response, int timeMillis, Supplier<T> supplier) -
condenseResponse
-
request
public NamedList<Object> request(SolrRequest<?> request, String collection) throws SolrServerException, IOException Description copied from class:SolrClientExecute a request against a Solr server for a given collection- Specified by:
requestin classSolrClient- Parameters:
request- the request to executecollection- the collection to execute the request against- Returns:
- a
NamedListcontaining the response from the server - Throws:
SolrServerException- if there is an error on the serverIOException- If there is a low-level I/O error.
-
requestWithRetryOnStaleState
protected NamedList<Object> requestWithRetryOnStaleState(SolrRequest<?> request, int retryCount, List<String> inputCollections, boolean skipStateVersion, Map<String, CompletableFuture<DocCollection>> pendingRefreshes, boolean waitedForRefresh) throws SolrServerException, IOExceptionAs this class doesn't watch external collections on the client side, there's a chance that the request will fail due to cached stale state, which means the state must be refreshed from ZK and retried.- Throws:
SolrServerExceptionIOException
-
sendRequest
protected NamedList<Object> sendRequest(SolrRequest<?> request, List<String> inputCollections) throws SolrServerException, IOException - Throws:
SolrServerExceptionIOException
-
isUpdatesToLeaders
public boolean isUpdatesToLeaders()If true, this client has been configured such that it will generally prefer to sendSolrRequest.SolrRequestType.UPDATErequests to a shard leader, if and only ifUpdateRequest.isSendToLeaders()is also true. If false, then this client has been configured to obey normal routing preferences when dealing withSolrRequest.SolrRequestType.UPDATErequests.- See Also:
-
isDirectUpdatesToLeadersOnly
public boolean isDirectUpdatesToLeadersOnly()If true, this client has been configured such that "direct updates" will only be sent to the current leader of the corresponding shard, and will not be retried with other replicas. This method has no effect ifisUpdatesToLeaders()orUpdateRequest.isSendToLeaders()returns false.A "direct update" is any update that can be sent directly to a single shard, and does not need to be broadcast to every shard. (Example: document updates or "delete by id" when using the default router; non-direct updates are things like commits and "delete by query").
NOTE: If a single
UpdateRequestcontains multiple "direct updates" for different shards, this client may break the request up and merge the responses.- Returns:
- true if direct updates are sent to shard leaders only
-
getStateRefreshParallelism
protected int getStateRefreshParallelism()Visible for tests so they can assert the configured refresh parallelism. -
getDocCollection
protected DocCollection getDocCollection(String collection, Integer expectedVersion) throws SolrException - Throws:
SolrException
-
getMinAchievedReplicationFactor
Useful for determining the minimum achieved replication factor across all shards involved in processing an update request, typically useful for gauging the replication factor of a batch. -
getShardReplicationFactor
Walks the NamedList response after performing an update request looking for the replication factor that was achieved in each shard involved in the request. For single doc updates, there will be only one shard in the return value.
-
ClusterStateProvider.getLiveNodes()instead.