public class ZkStateReader extends Object implements SolrCloseable
| 限定符和类型 | 类和说明 |
|---|---|
class |
ZkStateReader.AliasesManager
A class to manage the aliases instance, including watching for changes.
|
static class |
ZkStateReader.ConfigData |
| 构造器和说明 |
|---|
ZkStateReader(SolrZkClient zkClient) |
ZkStateReader(SolrZkClient zkClient,
Runnable securityNodeListener) |
ZkStateReader(String zkServerAddress,
int zkClientTimeout,
int zkClientConnectTimeout) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close() |
Integer |
compareStateVersions(String coll,
int version) |
void |
createClusterStateWatchersAndUpdate() |
DocCollection |
fetchCollectionState(String coll,
org.apache.zookeeper.Watcher watcher,
String path) |
void |
forceUpdateCollection(String collection)
Forcibly refresh a collection's internal state from ZK.
|
void |
forciblyRefreshAllClusterStateSlow()
Forcibly refresh cluster state from ZK.
|
Aliases |
getAliases()
Get an immutable copy of the present state of the aliases.
|
AutoScalingConfig |
getAutoScalingConfig()
Get current
AutoScalingConfig. |
AutoScalingConfig |
getAutoScalingConfig(org.apache.zookeeper.Watcher watcher)
Get current
AutoScalingConfig. |
String |
getBaseUrlForNodeName(String nodeName)
Returns the baseURL corresponding to a given node's nodeName --
NOTE: does not (currently) imply that the nodeName (or resulting
baseURL) exists in the cluster.
|
Map<String,Object> |
getClusterProperties()
Get all cluster properties for this cluster
N.B.
|
<T> T |
getClusterProperty(List<String> keyPath,
T defaultValue)
Same as the above but allows a full json path as a list of parts
|
<T> T |
getClusterProperty(String key,
T defaultValue)
Get a cluster property
N.B.
|
ClusterState |
getClusterState() |
DocCollection |
getCollection(String collection) |
static DocCollection |
getCollectionLive(ZkStateReader zkStateReader,
String coll) |
static String |
getCollectionPath(String coll) |
static String |
getCollectionPathRoot(String coll) |
Map<String,String> |
getCollectionProperties(String collection)
Get collection properties for a given collection.
|
Map<String,String> |
getCollectionProperties(String collection,
long cacheForMillis)
Get and cache collection properties for a given collection.
|
ZkConfigManager |
getConfigManager() |
Replica |
getLeader(Set<String> liveNodes,
DocCollection docCollection,
String shard) |
Replica |
getLeader(String collection,
String shard) |
Replica |
getLeaderRetry(String collection,
String shard)
Get shard leader properties, with retry if none exist.
|
Replica |
getLeaderRetry(String collection,
String shard,
int timeout)
Get shard leader properties, with retry if none exist.
|
String |
getLeaderUrl(String collection,
String shard,
int timeout) |
List<ZkCoreNodeProps> |
getReplicaProps(String collection,
String shardId,
String thisCoreNodeName) |
List<ZkCoreNodeProps> |
getReplicaProps(String collection,
String shardId,
String thisCoreNodeName,
Replica.State mustMatchStateFilter) |
List<ZkCoreNodeProps> |
getReplicaProps(String collection,
String shardId,
String thisCoreNodeName,
Replica.State mustMatchStateFilter,
Replica.State mustNotMatchStateFilter) |
List<ZkCoreNodeProps> |
getReplicaProps(String collection,
String shardId,
String thisCoreNodeName,
Replica.State mustMatchStateFilter,
Replica.State mustNotMatchStateFilter,
EnumSet<Replica.Type> acceptReplicaType) |
ZkStateReader.ConfigData |
getSecurityProps(boolean getFresh)
Returns the content of /security.json from ZooKeeper as a Map
If the files doesn't exist, it returns null.
|
static String |
getShardLeadersElectPath(String collection,
String shardId)
Get path where shard leader elections ephemeral nodes are.
|
static String |
getShardLeadersPath(String collection,
String shardId)
Get path where shard leader properties live in zookeeper.
|
Object |
getUpdateLock() |
SolrZkClient |
getZkClient() |
boolean |
isClosed() |
boolean |
isNodeLive(String node) |
String |
readConfigName(String collection)
Returns config set name for collection.
|
void |
registerCloudCollectionsListener(CloudCollectionsListener cloudCollectionsListener)
Register a CloudCollectionsListener to be called when the set of collections within a cloud changes.
|
void |
registerClusterPropertiesListener(ClusterPropertiesListener listener) |
void |
registerCollectionPropsWatcher(String collection,
CollectionPropsWatcher propsWatcher) |
void |
registerCollectionStateWatcher(String collection,
CollectionStateWatcher stateWatcher)
Register a CollectionStateWatcher to be called when the state of a collection changes
or the set of live nodes changes.
|
void |
registerCore(String collection)
Notify this reader that a local Core is a member of a collection, and so that collection
state should be watched.
|
void |
registerDocCollectionWatcher(String collection,
DocCollectionWatcher stateWatcher)
Register a DocCollectionWatcher to be called when the state of a collection changes
The Watcher will automatically be removed when it's
onStateChanged returns true
|
void |
registerLiveNodesListener(LiveNodesListener listener) |
void |
removeCloudCollectionsListener(CloudCollectionsListener cloudCollectionsListener)
Remove a registered CloudCollectionsListener.
|
void |
removeClusterPropertiesListener(ClusterPropertiesListener listener) |
void |
removeCollectionPropsWatcher(String collection,
CollectionPropsWatcher watcher) |
void |
removeCollectionStateWatcher(String collection,
CollectionStateWatcher watcher)
Remove a watcher from a collection's watch list.
|
void |
removeDocCollectionWatcher(String collection,
DocCollectionWatcher watcher)
Remove a watcher from a collection's watch list.
|
void |
removeLiveNodesListener(LiveNodesListener listener) |
void |
unregisterCore(String collection)
Notify this reader that a local core that is a member of a collection has been closed.
|
void |
updateLiveNodes()
Refresh the set of live nodes.
|
void |
waitForLiveNodes(long wait,
TimeUnit unit,
LiveNodesPredicate predicate)
Block until a LiveNodesStatePredicate returns true, or the wait times out
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.
|
void |
waitForState(String collection,
long wait,
TimeUnit unit,
CollectionStatePredicate predicate)
Block until a CollectionStatePredicate returns true, or the wait times out
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.
|
void |
waitForState(String collection,
long wait,
TimeUnit unit,
Predicate<DocCollection> predicate)
Block until a Predicate returns true, or the wait times out
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.
|
public static final int STATE_UPDATE_DELAY
public static final String SOLR_AUTOSCALING_TRIGGER_STATE_PATH
public static final String SOLR_AUTOSCALING_NODE_ADDED_PATH
public static final String SOLR_AUTOSCALING_NODE_LOST_PATH
public static final Map DEFAULT_CLUSTER_PROPS
@Deprecated public static final String COLLECTION_DEF
CollectionAdminParams.DEFAULTS instead.protected volatile ClusterState clusterState
public final ZkStateReader.AliasesManager aliasesManager
Aliases.public ZkStateReader(SolrZkClient zkClient)
public ZkStateReader(SolrZkClient zkClient, Runnable securityNodeListener)
public ZkStateReader(String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout)
public AutoScalingConfig getAutoScalingConfig() throws org.apache.zookeeper.KeeperException, InterruptedException
AutoScalingConfig.autoscaling.json. NOTE:
this data is retrieved from ZK on each call.org.apache.zookeeper.KeeperExceptionInterruptedExceptionpublic AutoScalingConfig getAutoScalingConfig(org.apache.zookeeper.Watcher watcher) throws org.apache.zookeeper.KeeperException, InterruptedException
AutoScalingConfig.watcher - optional Watcher to set on a znode to watch for config changes.autoscaling.json. NOTE:
this data is retrieved from ZK on each call.org.apache.zookeeper.KeeperExceptionInterruptedExceptionpublic String readConfigName(String collection) throws org.apache.zookeeper.KeeperException
collection - to return config set name fororg.apache.zookeeper.KeeperExceptionpublic ZkConfigManager getConfigManager()
public void forciblyRefreshAllClusterStateSlow()
throws org.apache.zookeeper.KeeperException,
InterruptedException
It is cheaper to call forceUpdateCollection(String) on a single collection if you must.
org.apache.zookeeper.KeeperExceptionInterruptedExceptionpublic void forceUpdateCollection(String collection) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperExceptionInterruptedExceptionpublic void updateLiveNodes()
throws org.apache.zookeeper.KeeperException,
InterruptedException
org.apache.zookeeper.KeeperExceptionInterruptedExceptionpublic void createClusterStateWatchersAndUpdate()
throws org.apache.zookeeper.KeeperException,
InterruptedException
org.apache.zookeeper.KeeperExceptionInterruptedExceptionpublic void registerCloudCollectionsListener(CloudCollectionsListener cloudCollectionsListener)
public void removeCloudCollectionsListener(CloudCollectionsListener cloudCollectionsListener)
public void registerClusterPropertiesListener(ClusterPropertiesListener listener)
public void removeClusterPropertiesListener(ClusterPropertiesListener listener)
public void registerLiveNodesListener(LiveNodesListener listener)
public void removeLiveNodesListener(LiveNodesListener listener)
public ClusterState getClusterState()
public Object getUpdateLock()
public void close()
close 在接口中 Closeableclose 在接口中 AutoCloseablepublic boolean isClosed()
isClosed 在接口中 SolrCloseablepublic String getLeaderUrl(String collection, String shard, int timeout) throws InterruptedException
public Replica getLeader(Set<String> liveNodes, DocCollection docCollection, String shard)
public boolean isNodeLive(String node)
public Replica getLeaderRetry(String collection, String shard) throws InterruptedException
public Replica getLeaderRetry(String collection, String shard, int timeout) throws InterruptedException
public static String getShardLeadersPath(String collection, String shardId)
public static String getShardLeadersElectPath(String collection, String shardId)
public List<ZkCoreNodeProps> getReplicaProps(String collection, String shardId, String thisCoreNodeName)
public List<ZkCoreNodeProps> getReplicaProps(String collection, String shardId, String thisCoreNodeName, Replica.State mustMatchStateFilter)
public List<ZkCoreNodeProps> getReplicaProps(String collection, String shardId, String thisCoreNodeName, Replica.State mustMatchStateFilter, Replica.State mustNotMatchStateFilter)
public List<ZkCoreNodeProps> getReplicaProps(String collection, String shardId, String thisCoreNodeName, Replica.State mustMatchStateFilter, Replica.State mustNotMatchStateFilter, EnumSet<Replica.Type> acceptReplicaType)
public SolrZkClient getZkClient()
public <T> T getClusterProperty(String key, T defaultValue)
N.B. Cluster properties are updated via ZK watchers, and so may not necessarily
be completely up-to-date. If you need to get the latest version, then use a
ClusterProperties instance.
T - the type of the propertykey - the property to readdefaultValue - a default value to use if no such property existspublic <T> T getClusterProperty(List<String> keyPath, T defaultValue)
keyPath - path to the property example ["collectionDefauls", "numShards"]defaultValue - a default value to use if no such property existspublic Map<String,Object> getClusterProperties()
N.B. Cluster properties are updated via ZK watchers, and so may not necessarily
be completely up-to-date. If you need to get the latest version, then use a
ClusterProperties instance.
public Map<String,String> getCollectionProperties(String collection)
getCollectionProperties(collection,0)collection - the collection for which properties are desiredpublic Map<String,String> getCollectionProperties(String collection, long cacheForMillis)
getCollectionProperties should be used when properties need to be consulted
frequently in the absence of an active CollectionPropsWatcher.collection - The collection for which properties are desiredcacheForMillis - The minimum number of milliseconds to maintain a cache for the specified collection's
properties. Setting a CollectionPropsWatcher will override this value and retain
the cache for the life of the watcher. A lack of changes in zookeeper may allow the
caching to remain for a greater duration up to the cycle time of CacheCleaner.
Passing zero for this value will explicitly remove the cached copy if and only if it is
due to expire and no watch exists. Any positive value will extend the expiration time
if required.public ZkStateReader.ConfigData getSecurityProps(boolean getFresh)
public String getBaseUrlForNodeName(String nodeName)
public static DocCollection getCollectionLive(ZkStateReader zkStateReader, String coll)
public DocCollection fetchCollectionState(String coll, org.apache.zookeeper.Watcher watcher, String path) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperExceptionInterruptedExceptionpublic void registerCore(String collection)
Not a public API. This method should only be called from ZkController.
The number of cores per-collection is tracked, and adding multiple cores from the same collection does not increase the number of watches.
collection - the collection that the core is a member ofunregisterCore(String)public void unregisterCore(String collection)
Not a public API. This method should only be called from ZkController.
If no cores are registered for a collection, and there are no CollectionStateWatchers
for that collection either, the collection watch will be removed.
collection - the collection that the core belongs topublic void registerCollectionStateWatcher(String collection, CollectionStateWatcher stateWatcher)
The Watcher will automatically be removed when it's
onStateChanged returns true
This is method is just syntactic sugar for registering both a DocCollectionWatcher and
a LiveNodesListener. Callers that only care about one or the other (but not both) are
encouraged to use the more specific methods register methods as it may reduce the number of
ZooKeeper watchers needed, and reduce the amount of network/cpu used.
public void registerDocCollectionWatcher(String collection, DocCollectionWatcher stateWatcher)
The Watcher will automatically be removed when it's
onStateChanged returns true
public 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 - the predicate to call on state changesInterruptedException - 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 - the predicate to call on state changesInterruptedException - on interruptTimeoutException - on timeoutpublic void waitForLiveNodes(long wait,
TimeUnit unit,
LiveNodesPredicate 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.
wait - how long to waitunit - the units of the wait parameterpredicate - the predicate to call on state changesInterruptedException - on interruptTimeoutException - on timeoutpublic void removeCollectionStateWatcher(String collection, CollectionStateWatcher watcher)
This allows Zookeeper watches to be removed if there is no interest in the collection.
collection - the collectionwatcher - the watcherregisterCollectionStateWatcher(java.lang.String, org.apache.solr.common.cloud.CollectionStateWatcher)public void removeDocCollectionWatcher(String collection, DocCollectionWatcher watcher)
This allows Zookeeper watches to be removed if there is no interest in the collection.
collection - the collectionwatcher - the watcherregisterDocCollectionWatcher(java.lang.String, org.apache.solr.common.cloud.DocCollectionWatcher)public void registerCollectionPropsWatcher(String collection, CollectionPropsWatcher propsWatcher)
public void removeCollectionPropsWatcher(String collection, CollectionPropsWatcher watcher)
public Aliases getAliases()
public DocCollection getCollection(String collection)
Copyright © 2006–2022 The Apache Software Foundation. All rights reserved.