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
 - 
Field SummaryFields Modifier and Type Field Description static StringURL_SCHEMECluster Prop that is http or https.
 - 
Constructor SummaryConstructors Constructor Description ClusterState(Map<String,ClusterState.CollectionRef> collectionStates, Set<String> liveNodes)Use this if all the collection states are not readily available and some needs to be lazily loaded (parameter order different from constructor above to have different erasures)ClusterState(Set<String> liveNodes, Map<String,DocCollection> collectionStates)Use this constr when ClusterState is meant for consumption.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidclearReplicaStateProvider()ClusterStatecopyWith(String collectionName, DocCollection collection)Returns a new cluster state object modified with the given collection.static ClusterStatecreateFromCollectionMap(int version, Map<String,Object> stateMap, Set<String> liveNodes)static ClusterStatecreateFromJson(int version, byte[] bytes, Set<String> liveNodes)Create a ClusterState from Json.booleanequals(Object obj)voidforEachCollection(Consumer<DocCollection> consumer)Iterate over collections.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 objectsMap<String,ClusterState.CollectionRef>getCollectionStates()Be aware that this may return collections which may not exist now.Set<String>getHostAllowList()Gets the set of allowed hosts (host:port) built from the set of live nodes.Set<String>getLiveNodes()Get names of the currently live nodes.static org.apache.solr.common.cloud.ClusterState.ReplicaStatesProvidergetReplicaStatesProvider()StringgetShardId(String nodeName, String coreName)StringgetShardId(String collectionName, String nodeName, String coreName)booleanhasCollection(String collectionName)Returns true if the specified collection name exists, false otherwise.inthashCode()static voidinitReplicaStateProvider(Supplier<PerReplicaStates> replicaStatesSupplier)booleanliveNodesContain(String name)Check if node is alive.static voidsetStrInternerParser(Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> fun)intsize()StringtoString()voidwrite(org.noggit.JSONWriter jsonWriter)
 
- 
- 
- 
Field Detail- 
URL_SCHEMEpublic static final String URL_SCHEME Cluster Prop that is http or https.- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
ClusterStatepublic ClusterState(Set<String> liveNodes, Map<String,DocCollection> collectionStates) Use this constr when ClusterState is meant for consumption.
 - 
ClusterStatepublic ClusterState(Map<String,ClusterState.CollectionRef> collectionStates, Set<String> liveNodes) Use this if all the collection states are not readily available and some needs to be lazily loaded (parameter order different from constructor above to have different erasures)
 
- 
 - 
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
 
 - 
hasCollectionpublic boolean hasCollection(String collectionName) Returns true if the specified collection name exists, false otherwise.Implementation note: This method resolves the collection reference by calling ClusterState.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.
 - 
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.
 
 - 
getCollectionsMappublic Map<String,DocCollection> getCollectionsMap() Get a map of collection name vs DocCollection objectsImplementation note: This method resolves the collection reference by calling ClusterState.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.- Returns:
- a map of collection name vs DocCollection object
 
 - 
liveNodesContainpublic boolean liveNodesContain(String name) Check if node is alive.
 - 
createFromJsonpublic static ClusterState createFromJson(int version, byte[] bytes, Set<String> liveNodes) Create a ClusterState from Json. This method doesn't support legacy configName location and thus don't call it where that's important- Parameters:
- bytes- a byte array of a Json representation of a mapping from collection name to the Json representation of a- DocCollectionas written by- write(JSONWriter). It can represent one or more collections.
- liveNodes- list of live nodes
- Returns:
- the ClusterState
 
 - 
createFromCollectionMappublic static ClusterState createFromCollectionMap(int version, Map<String,Object> stateMap, Set<String> liveNodes) 
 - 
writepublic void write(org.noggit.JSONWriter jsonWriter) - Specified by:
- writein interface- org.noggit.JSONWriter.Writable
 
 - 
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
 - 
getHostAllowListpublic Set<String> getHostAllowList() Gets the set of allowed hosts (host:port) built from the set of live nodes. The set is cached to be reused.
 - 
forEachCollectionpublic void forEachCollection(Consumer<DocCollection> consumer) Iterate over collections. UnlikegetCollectionStates()collections passed to the consumer are guaranteed to exist.- Parameters:
- consumer- collection consumer.
 
 - 
sizepublic int size() 
 - 
getReplicaStatesProviderpublic static org.apache.solr.common.cloud.ClusterState.ReplicaStatesProvider getReplicaStatesProvider() 
 - 
initReplicaStateProviderpublic static void initReplicaStateProvider(Supplier<PerReplicaStates> replicaStatesSupplier) 
 - 
clearReplicaStateProviderpublic static void clearReplicaStateProvider() 
 - 
setStrInternerParserpublic static void setStrInternerParser(Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> fun) 
 
- 
 
-