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 using `ZkStateReader.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 and Description
    --- | ---
    `static class` | `ClusterState.CollectionRef`

  - ### Constructor Summary

    Constructors
    Constructor and 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 Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `ClusterState` | `copyWith(String collectionName, DocCollection collection)` Returns a new cluster state object modified with the given collection.
    `boolean` | `equals(Object obj)`
    `Collection<Slice>` | `getActiveSlices(String collection)` Deprecated. use `DocCollection.getActiveSlices()` instead
    `Map<String,Slice>` | `getActiveSlicesMap(String collection)` Deprecated. use `DocCollection.getActiveSlicesMap()` instead
    `DocCollection` | `getCollection(String collection)` Get the named DocCollection object, or throw an exception if it doesn't exist.
    `DocCollection` | `getCollectionOrNull(String collectionName)` Returns the corresponding `DocCollection` object for the given collection name if such a collection exists.
    `ClusterState.CollectionRef` | `getCollectionRef(String coll)`
    `Set<String>` | `getCollections()` Deprecated. use `getCollectionsMap()` to avoid a second lookup for lazy collections
    `Map<String,DocCollection>` | `getCollectionsMap()` Get a map of collection name vs DocCollection objects Implementation note: This method resolves the collection reference by calling `ClusterState.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.
    `Replica` | `getLeader(String collection, String sliceName)` Deprecated. Use `DocCollection.getLeader(String)` instead
    `Set<String>` | `getLiveNodes()` Get names of the currently live nodes.
    `Replica` | `getReplica(String collection, String coreNodeName)` Deprecated. use `DocCollection.getReplica(String)` instead
    `String` | `getShardId(String nodeName, String coreName)`
    `String` | `getShardId(String collectionName, String nodeName, String coreName)`
    `Slice` | `getSlice(String collection, String sliceName)` Deprecated. use `DocCollection.getSlice(String)` instead
    `Collection<Slice>` | `getSlices(String collection)` Deprecated. use `DocCollection.getSlices()` instead
    `Map<String,Slice>` | `getSlicesMap(String collection)` Deprecated. use `DocCollection.getSlicesMap()` instead
    `Integer` | `getZkClusterStateVersion()` Deprecated. true cluster state spans many ZK nodes, stop depending on the version number of the shared node!
    `boolean` | `hasCollection(String collectionName)` Returns true if the specified collection name exists, false otherwise.
    `int` | `hashCode()`
    `boolean` | `liveNodesContain(String name)` Check if node is alive.
    `static Aliases` | `load(byte[] bytes)`
    `static ClusterState` | `load(Integer version, byte[] bytes, Set<String> liveNodes)`
    `static ClusterState` | `load(Integer version, byte[] bytes, Set<String> liveNodes, String znode)` Create ClusterState from json string that is typically stored in zookeeper.
    `String` | `toString()`
    `void` | `write(org.noggit.JSONWriter jsonWriter)`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ClusterState

          public ClusterState(Integer znodeVersion,
                              Set<String> liveNodes,
                              Map<String,DocCollection> collectionStates)

      Use this constr when ClusterState is meant for consumption.

    - #### ClusterState

          public 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 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) 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

    - #### getLeader

          @Deprecated
          public Replica getLeader(String collection,
                                               String sliceName)

      Deprecated. Use `DocCollection.getLeader(String)` instead
      Get the lead replica for specific collection, or null if one currently doesn't exist.

    - #### 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. Please see javadocs in `ZkStateReader.refreshCollectionList(Watcher)`

    - #### getReplica

          @Deprecated
          public Replica getReplica(String collection,
                                                String coreNodeName)

      Deprecated. use `DocCollection.getReplica(String)` instead
      Gets the replica by the core node name (assuming the slice is unknown) or null if replica is not found. If the slice is known, do not use this method. coreNodeName is the same as replicaName

    - #### getSlice

          @Deprecated
          public Slice getSlice(String collection,
                                            String sliceName)

      Deprecated. use `DocCollection.getSlice(String)` instead
      Get the named Slice for collection, or null if not found.

    - #### getSlicesMap

          @Deprecated
          public Map<String,Slice> getSlicesMap(String collection)

      Deprecated. use `DocCollection.getSlicesMap()` instead

    - #### getActiveSlicesMap

          @Deprecated
          public Map<String,Slice> getActiveSlicesMap(String collection)

      Deprecated. use `DocCollection.getActiveSlicesMap()` instead

    - #### getSlices

          @Deprecated
          public Collection<Slice> getSlices(String collection)

      Deprecated. use `DocCollection.getSlices()` instead

    - #### getActiveSlices

          @Deprecated
          public Collection<Slice> getActiveSlices(String collection)

      Deprecated. use `DocCollection.getActiveSlices()` instead

    - #### 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 corresponding `DocCollection` object for the given collection name if such a collection exists. Returns null otherwise. 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)`

    - #### getCollections

          @Deprecated
          public Set<String> getCollections()

      Deprecated. use `getCollectionsMap()` to avoid a second lookup for lazy collections
      Get collection names. 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. Please see javadocs in `ZkStateReader.refreshCollectionList(Watcher)`

    - #### getCollectionsMap

          public Map<String,DocCollection> getCollectionsMap()

      Get a map of collection name vs DocCollection objects 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. Please see javadocs in `ZkStateReader.refreshCollectionList(Watcher)`
      Returns:
        a map of collection name vs DocCollection object

    - #### getLiveNodes

          public Set<String> getLiveNodes()

      Get names of the currently live nodes.

    - #### getShardId

          public String getShardId(String nodeName,
                                   String coreName)

    - #### getShardId

          public String getShardId(String collectionName,
                                   String nodeName,
                                   String coreName)

    - #### liveNodesContain

          public boolean liveNodesContain(String name)

      Check if node is alive.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### load

          public static ClusterState load(Integer version,
                                          byte[] bytes,
                                          Set<String> liveNodes)

    - #### load

          public 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

    - #### load

          public static Aliases load(byte[] bytes)

    - #### write

          public void write(org.noggit.JSONWriter jsonWriter)

      Specified by:
        `write` in 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!
      The version of clusterstate.json in ZooKeeper.
      Returns:
        null if ClusterState was created for publication, not consumption

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### 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

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.