Package org.apache.solr.common.cloud
Class ClusterState
- java.lang.Object
- 
- org.apache.solr.common.cloud.ClusterState
 
- 
- All Implemented Interfaces:
- org.noggit.JSONWriter.Writable
 
 public class ClusterState extends Object implements org.noggit.JSONWriter.Writable Immutable state of the cloud. Normally you can get the state by usingZkStateReader.getClusterState().- WARNING: This API is experimental and might change in incompatible ways in the next release.
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classClusterState.CollectionRef
 - 
Constructor SummaryConstructors Constructor Description ClusterState(Integer znodeVersion, Set<String> liveNodes, Map<String,DocCollection> collectionStates)Use this constr when ClusterState is meant for consumption.ClusterState(Set<String> liveNodes, Map<String,ClusterState.CollectionRef> collectionStates, Integer znodeVersion)Use this if all the collection states are not readily available and some needs to be lazily loaded
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ClusterStatecopyWith(String collectionName, DocCollection collection)Returns a new cluster state object modified with the given collection.booleanequals(Object obj)voidforEachCollection(Consumer<DocCollection> consumer)DocCollectiongetCollection(String collection)Get the named DocCollection object, or throw an exception if it doesn't exist.DocCollectiongetCollectionOrNull(String collectionName)Returns the correspondingDocCollectionobject for the given collection name if such a collection exists.DocCollectiongetCollectionOrNull(String collectionName, boolean allowCached)Returns the correspondingDocCollectionobject for the given collection name if such a collection exists.ClusterState.CollectionRefgetCollectionRef(String coll)Map<String,DocCollection>getCollectionsMap()Get a map of collection name vs DocCollection objects Implementation note: This method resolves the collection reference by callingClusterState.CollectionRef.get()which can make a call to ZooKeeper.Map<String,ClusterState.CollectionRef>getCollectionStates()Be aware that this may return collections which may not exist now.Set<String>getLiveNodes()Get names of the currently live nodes.StringgetShardId(String nodeName, String coreName)StringgetShardId(String collectionName, String nodeName, String coreName)IntegergetZkClusterStateVersion()Deprecated.true cluster state spans many ZK nodes, stop depending on the version number of the shared node! will be removed in 8.0intgetZNodeVersion()Returns the zNode version that was used to construct this instance.booleanhasCollection(String collectionName)Returns true if the specified collection name exists, false otherwise.inthashCode()booleanliveNodesContain(String name)Check if node is alive.static ClusterStateload(Integer version, byte[] bytes, Set<String> liveNodes)static ClusterStateload(Integer version, byte[] bytes, Set<String> liveNodes, String znode)Create ClusterState from json string that is typically stored in zookeeper.static ClusterStateload(Integer version, Map<String,Object> stateMap, Set<String> liveNodes, String znode)StringtoString()voidwrite(org.noggit.JSONWriter jsonWriter)
 
- 
- 
- 
Method Detail- 
copyWithpublic ClusterState copyWith(String collectionName, DocCollection collection) Returns a new cluster state object modified with the given collection.- Parameters:
- collectionName- the name of the modified (or deleted) collection
- collection- the collection object. A null value deletes the collection from the state
- Returns:
- the updated cluster state which preserves the current live nodes and zk node version
 
 - 
getZNodeVersionpublic int getZNodeVersion() Returns the zNode version that was used to construct this instance.
 - 
hasCollectionpublic boolean hasCollection(String collectionName) Returns true if the specified collection name exists, false otherwise. Implementation note: This method resolves the collection reference by callingClusterState.CollectionRef.get()which can make a call to ZooKeeper. This is necessary because the semantics of how collection list is loaded have changed in SOLR-6629. Please see javadocs inZkStateReader.refreshCollectionList(Watcher)
 - 
getCollectionpublic DocCollection getCollection(String collection) Get the named DocCollection object, or throw an exception if it doesn't exist.
 - 
getCollectionRefpublic ClusterState.CollectionRef getCollectionRef(String coll) 
 - 
getCollectionOrNullpublic DocCollection getCollectionOrNull(String collectionName) Returns the correspondingDocCollectionobject for the given collection name if such a collection exists. Returns null otherwise. Equivalent to getCollectionOrNull(collectionName, false)
 - 
getCollectionOrNullpublic DocCollection getCollectionOrNull(String collectionName, boolean allowCached) Returns the correspondingDocCollectionobject for the given collection name if such a collection exists. Returns null otherwise.- Parameters:
- collectionName- Name of the collection
- allowCached- allow LazyCollectionRefs to use a time-based cached value Implementation note: This method resolves the collection reference by calling- ClusterState.CollectionRef.get()which may make a call to ZooKeeper. This is necessary because the semantics of how collection list is loaded have changed in SOLR-6629. Please see javadocs in- ZkStateReader.refreshCollectionList(Watcher)
 
 - 
getCollectionsMappublic Map<String,DocCollection> getCollectionsMap() Get a map of collection name vs DocCollection objects Implementation note: This method resolves the collection reference by callingClusterState.CollectionRef.get()which can make a call to ZooKeeper. This is necessary because the semantics of how collection list is loaded have changed in SOLR-6629. Please see javadocs inZkStateReader.refreshCollectionList(Watcher)- Returns:
- a map of collection name vs DocCollection object
 
 - 
liveNodesContainpublic boolean liveNodesContain(String name) Check if node is alive.
 - 
loadpublic static ClusterState load(Integer version, byte[] bytes, Set<String> liveNodes) 
 - 
loadpublic static ClusterState load(Integer version, byte[] bytes, Set<String> liveNodes, String znode) Create ClusterState from json string that is typically stored in zookeeper.- Parameters:
- version- zk version of the clusterstate.json file (bytes)
- bytes- clusterstate.json as a byte array
- liveNodes- list of live nodes
- Returns:
- the ClusterState
 
 - 
loadpublic static ClusterState load(Integer version, Map<String,Object> stateMap, Set<String> liveNodes, String znode) 
 - 
writepublic void write(org.noggit.JSONWriter jsonWriter) - Specified by:
- writein interface- org.noggit.JSONWriter.Writable
 
 - 
getZkClusterStateVersion@Deprecated public Integer getZkClusterStateVersion() Deprecated.true cluster state spans many ZK nodes, stop depending on the version number of the shared node! will be removed in 8.0The version of clusterstate.json in ZooKeeper.- Returns:
- null if ClusterState was created for publication, not consumption
 
 - 
getCollectionStatespublic Map<String,ClusterState.CollectionRef> getCollectionStates() Be aware that this may return collections which may not exist now. You can confirm that this collection exists after verifying CollectionRef.get() != null
 - 
forEachCollectionpublic void forEachCollection(Consumer<DocCollection> consumer) 
 
- 
 
-