public abstract class BaseCloudSolrClient extends SolrClient
Modifier and Type | Class and Description |
---|---|
static class |
BaseCloudSolrClient.RouteException |
static class |
BaseCloudSolrClient.RouteResponse<T extends LBSolrClient.Req> |
Modifier and Type | Field and Description |
---|---|
protected org.apache.solr.client.solrj.impl.BaseCloudSolrClient.StateCache |
collectionStateCache |
static String |
STATE_VERSION |
Modifier | Constructor and Description |
---|---|
protected |
BaseCloudSolrClient(boolean updatesToLeaders,
boolean parallelUpdates,
boolean directUpdatesToLeadersOnly) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
BaseCloudSolrClient.RouteResponse |
condenseResponse(NamedList response,
int timeMillis) |
protected <T extends BaseCloudSolrClient.RouteResponse> |
condenseResponse(NamedList response,
int timeMillis,
Supplier<T> supplier) |
void |
connect()
Connect to the zookeeper ensemble.
|
void |
connect(long duration,
TimeUnit timeUnit)
Connect to a cluster.
|
protected Map<String,? extends LBSolrClient.Req> |
createRoutes(UpdateRequest updateRequest,
ModifiableSolrParams routableParams,
DocCollection col,
DocRouter router,
Map<String,List<String>> urlMap,
String idField) |
abstract ClusterStateProvider |
getClusterStateProvider() |
String |
getDefaultCollection()
Gets the default collection for request
|
protected DocCollection |
getDocCollection(String collection,
Integer expectedVersion) |
String |
getIdField() |
protected abstract LBSolrClient |
getLbClient() |
int |
getMinAchievedReplicationFactor(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.
|
ResponseParser |
getParser() |
RequestWriter |
getRequestWriter() |
protected BaseCloudSolrClient.RouteException |
getRouteException(SolrException.ErrorCode serverError,
NamedList<Throwable> exceptions,
Map<String,? extends LBSolrClient.Req> routes) |
Map<String,Integer> |
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.
|
String |
getZkHost() |
ZkStateReader |
getZkStateReader() |
boolean |
isDirectUpdatesToLeadersOnly() |
boolean |
isParallelUpdates()
Gets whether direct updates are sent in parallel
|
boolean |
isUpdatesToLeaders() |
protected static ArrayList<Object> |
objectList(int n) |
void |
registerCollectionStateWatcher(String collection,
CollectionStateWatcher watcher)
Register a CollectionStateWatcher to be called when the cluster state for a collection changes
or the set of live nodes changes.
|
void |
registerDocCollectionWatcher(String collection,
DocCollectionWatcher watcher)
Register a DocCollectionWatcher to be called when the cluster state for a collection changes.
|
NamedList<Object> |
request(SolrRequest request,
String collection)
Execute a request against a Solr server for a given collection
|
protected NamedList<Object> |
requestWithRetryOnStaleState(SolrRequest request,
int retryCount,
List<String> inputCollections)
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.
|
protected NamedList<Object> |
sendRequest(SolrRequest request,
List<String> inputCollections) |
void |
setCollectionCacheTTl(int seconds)
Sets the cache ttl for DocCollection Objects cached .
|
void |
setDefaultCollection(String collection)
Sets the default collection for request
|
void |
setIdField(String idField) |
void |
setParallelCacheRefreshes(int n)
If caches are expired they are refreshed after acquiring a lock.
|
void |
setParser(ResponseParser processor)
Note: This setter method is not thread-safe.
|
void |
setRequestWriter(RequestWriter requestWriter) |
void |
setRetryExpiryTime(int secs)
This is the time to wait to refetch the state
after getting the same state version from ZK
|
void |
setZkClientTimeout(int zkClientTimeout)
Set the timeout to the zookeeper ensemble in ms
|
void |
setZkConnectTimeout(int zkConnectTimeout)
Set the connect timeout to the zookeeper ensemble in ms
|
void |
waitForState(String collection,
long wait,
TimeUnit unit,
CollectionStatePredicate predicate)
Block until a CollectionStatePredicate returns true, or the wait times out
|
void |
waitForState(String collection,
long wait,
TimeUnit unit,
Predicate<DocCollection> predicate)
Block until a Predicate returns true, or the wait times out
|
protected abstract boolean |
wasCommError(Throwable t) |
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, getBinder, getById, getById, getById, getById, getById, getById, getById, getById, optimize, optimize, optimize, optimize, optimize, optimize, ping, ping, query, query, query, query, queryAndStreamResponse, queryAndStreamResponse, queryAndStreamResponse, request, rollback, rollback
public static final String STATE_VERSION
protected final org.apache.solr.client.solrj.impl.BaseCloudSolrClient.StateCache collectionStateCache
protected BaseCloudSolrClient(boolean updatesToLeaders, boolean parallelUpdates, boolean directUpdatesToLeadersOnly)
public void setRetryExpiryTime(int secs)
secs
public void setCollectionCacheTTl(int seconds)
seconds
- ttl value in secondsprotected abstract LBSolrClient getLbClient()
public abstract ClusterStateProvider getClusterStateProvider()
protected abstract boolean wasCommError(Throwable t)
public void close() throws IOException
IOException
public ResponseParser getParser()
public void setParser(ResponseParser processor)
processor
- Default Response Parser chosen to parse the response if the parser
were not specified as part of the request.SolrRequest.getResponseParser()
public RequestWriter getRequestWriter()
public void setRequestWriter(RequestWriter requestWriter)
public String getZkHost()
public ZkStateReader getZkStateReader()
public void setIdField(String idField)
idField
- the field to route documents on.public String getIdField()
public void setDefaultCollection(String collection)
public String getDefaultCollection()
public void setZkConnectTimeout(int zkConnectTimeout)
public void setZkClientTimeout(int zkClientTimeout)
public boolean isParallelUpdates()
public void connect()
public void connect(long duration, TimeUnit timeUnit) throws TimeoutException, InterruptedException
duration
- the timeouttimeUnit
- the units of the timeoutTimeoutException
- if the cluster is not ready after the timeoutInterruptedException
- if the wait is interruptedpublic void waitForState(String collection, long wait, TimeUnit unit, CollectionStatePredicate predicate) throws InterruptedException, TimeoutException
Note that the predicate may be called again even after it has returned true, so implementors should avoid changing state within the predicate call itself.
This implementation utilizes CollectionStateWatcher
internally.
Callers that don't care about liveNodes are encouraged to use a DocCollection
Predicate
instead
collection
- the collection to watchwait
- how long to waitunit
- the units of the wait parameterpredicate
- a CollectionStatePredicate
to check the collection stateInterruptedException
- on interruptTimeoutException
- on timeoutwaitForState(String, long, TimeUnit, Predicate)
,
registerCollectionStateWatcher(java.lang.String, org.apache.solr.common.cloud.CollectionStateWatcher)
public void waitForState(String collection, long wait, TimeUnit unit, Predicate<DocCollection> predicate) throws InterruptedException, TimeoutException
Note that the predicate may be called again even after it has returned true, so implementors should avoid changing state within the predicate call itself.
collection
- the collection to watchwait
- how long to waitunit
- the units of the wait parameterpredicate
- a Predicate
to test against the DocCollection
InterruptedException
- on interruptTimeoutException
- on timeoutregisterDocCollectionWatcher(java.lang.String, org.apache.solr.common.cloud.DocCollectionWatcher)
public void registerCollectionStateWatcher(String collection, CollectionStateWatcher watcher)
The Watcher will automatically be removed when it's
onStateChanged
returns true
This implementation utilizes ZkStateReader.registerCollectionStateWatcher(java.lang.String, org.apache.solr.common.cloud.CollectionStateWatcher)
internally.
Callers that don't care about liveNodes are encouraged to use a DocCollectionWatcher
instead
collection
- the collection to watchwatcher
- a watcher that will be called when the state changesregisterDocCollectionWatcher(String, DocCollectionWatcher)
,
ZkStateReader.registerCollectionStateWatcher(java.lang.String, org.apache.solr.common.cloud.CollectionStateWatcher)
public void registerDocCollectionWatcher(String collection, DocCollectionWatcher watcher)
The Watcher will automatically be removed when it's
onStateChanged
returns true
collection
- the collection to watchwatcher
- a watcher that will be called when the state changesZkStateReader.registerDocCollectionWatcher(java.lang.String, org.apache.solr.common.cloud.DocCollectionWatcher)
protected BaseCloudSolrClient.RouteException getRouteException(SolrException.ErrorCode serverError, NamedList<Throwable> exceptions, Map<String,? extends LBSolrClient.Req> routes)
protected Map<String,? extends LBSolrClient.Req> createRoutes(UpdateRequest updateRequest, ModifiableSolrParams routableParams, DocCollection col, DocRouter router, Map<String,List<String>> urlMap, String idField)
protected <T extends BaseCloudSolrClient.RouteResponse> T condenseResponse(NamedList response, int timeMillis, Supplier<T> supplier)
public BaseCloudSolrClient.RouteResponse condenseResponse(NamedList response, int timeMillis)
public NamedList<Object> request(SolrRequest request, String collection) throws SolrServerException, IOException
SolrClient
request
in class SolrClient
request
- the request to executecollection
- the collection to execute the request againstNamedList
containing the response from the serverSolrServerException
- if there is an error on the serverIOException
- If there is a low-level I/O error.protected NamedList<Object> requestWithRetryOnStaleState(SolrRequest request, int retryCount, List<String> inputCollections) throws SolrServerException, IOException
SolrServerException
IOException
protected NamedList<Object> sendRequest(SolrRequest request, List<String> inputCollections) throws SolrServerException, IOException
SolrServerException
IOException
public boolean isUpdatesToLeaders()
public boolean isDirectUpdatesToLeadersOnly()
public void setParallelCacheRefreshes(int n)
protected DocCollection getDocCollection(String collection, Integer expectedVersion) throws SolrException
SolrException
public int getMinAchievedReplicationFactor(String collection, NamedList resp)
public Map<String,Integer> getShardReplicationFactor(String collection, NamedList resp)
Copyright © 2000-2019 Apache Software Foundation. All Rights Reserved.