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 Summary
Nested Classes Modifier and Type Class Description static class
ClusterState.CollectionRef
-
Constructor Summary
Constructors 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 Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
clearReplicaStateProvider()
ClusterState
copyWith(String collectionName, DocCollection collection)
Returns a new cluster state object modified with the given collection.static ClusterState
createFromCollectionMap(int version, Map<String,Object> stateMap, Set<String> liveNodes)
static ClusterState
createFromJson(int version, byte[] bytes, Set<String> liveNodes)
Create a ClusterState from Json.static ClusterState
createFromJsonSupportingLegacyConfigName(int version, byte[] bytes, Set<String> liveNodes, String coll, SolrZkClient zkClient)
Deprecated.boolean
equals(Object obj)
void
forEachCollection(Consumer<DocCollection> consumer)
Iterate over collections.DocCollection
getCollection(String collection)
Get the named DocCollection object, or throw an exception if it doesn't exist.DocCollection
getCollectionOrNull(String collectionName)
Returns the correspondingDocCollection
object for the given collection name if such a collection exists.DocCollection
getCollectionOrNull(String collectionName, boolean allowCached)
Returns the correspondingDocCollection
object for the given collection name if such a collection exists.ClusterState.CollectionRef
getCollectionRef(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.ReplicaStatesProvider
getReplicaStatesProvider()
String
getShardId(String nodeName, String coreName)
String
getShardId(String collectionName, String nodeName, String coreName)
boolean
hasCollection(String collectionName)
Returns true if the specified collection name exists, false otherwise.int
hashCode()
static void
initReplicaStateProvider(Supplier<PerReplicaStates> replicaStatesSupplier)
boolean
liveNodesContain(String name)
Check if node is alive.int
size()
String
toString()
void
write(org.noggit.JSONWriter jsonWriter)
-
-
-
Constructor Detail
-
ClusterState
public ClusterState(Set<String> liveNodes, Map<String,DocCollection> collectionStates)
Use this constr when ClusterState is meant for consumption.
-
ClusterState
public 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
-
copyWith
public 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) collectioncollection
- the collection object. A null value deletes the collection from the state- Returns:
- the updated cluster state which preserves the current live nodes
-
hasCollection
public 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.
-
getCollection
public DocCollection getCollection(String collection)
Get the named DocCollection object, or throw an exception if it doesn't exist.
-
getCollectionRef
public ClusterState.CollectionRef getCollectionRef(String coll)
-
getCollectionOrNull
public DocCollection getCollectionOrNull(String collectionName)
Returns the correspondingDocCollection
object for the given collection name if such a collection exists. Returns null otherwise. Equivalent to getCollectionOrNull(collectionName, false)
-
getCollectionOrNull
public DocCollection getCollectionOrNull(String collectionName, boolean allowCached)
Returns the correspondingDocCollection
object for the given collection name if such a collection exists. Returns null otherwise.- Parameters:
collectionName
- Name of the collectionallowCached
- allow LazyCollectionRefs to use a time-based cached valueImplementation 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.
-
getCollectionsMap
public 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
-
liveNodesContain
public boolean liveNodesContain(String name)
Check if node is alive.
-
createFromJson
public 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 aDocCollection
as written bywrite(JSONWriter)
. It can represent one or more collections.liveNodes
- list of live nodes- Returns:
- the ClusterState
-
createFromJsonSupportingLegacyConfigName
@Deprecated public static ClusterState createFromJsonSupportingLegacyConfigName(int version, byte[] bytes, Set<String> liveNodes, String coll, SolrZkClient zkClient)
Deprecated.Create a ClusterState from Json. This method supports legacy configName location- Parameters:
bytes
- a byte array of a Json representation of a mapping from collection name to the Json representation of aDocCollection
as written bywrite(JSONWriter)
. It can represent one or more collections.liveNodes
- list of live nodescoll
- collection namezkClient
- ZK client- Returns:
- the ClusterState
-
createFromCollectionMap
public static ClusterState createFromCollectionMap(int version, Map<String,Object> stateMap, Set<String> liveNodes)
-
write
public void write(org.noggit.JSONWriter jsonWriter)
- Specified by:
write
in interfaceorg.noggit.JSONWriter.Writable
-
getCollectionStates
public 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
-
getHostAllowList
public 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.
-
forEachCollection
public void forEachCollection(Consumer<DocCollection> consumer)
Iterate over collections. UnlikegetCollectionStates()
collections passed to the consumer are guaranteed to exist.- Parameters:
consumer
- collection consumer.
-
size
public int size()
-
getReplicaStatesProvider
public static org.apache.solr.common.cloud.ClusterState.ReplicaStatesProvider getReplicaStatesProvider()
-
initReplicaStateProvider
public static void initReplicaStateProvider(Supplier<PerReplicaStates> replicaStatesSupplier)
-
clearReplicaStateProvider
public static void clearReplicaStateProvider()
-
-