org.apache.solr.common.cloud

## Class ZkStateReader

- java.lang.Object
- - org.apache.solr.common.cloud.ZkStateReader

All Implemented Interfaces:
  Closeable, AutoCloseable

    public class ZkStateReader
    extends Object
    implements Closeable

### Nested Class Summary

Nested Classes
`static class` `ZkStateReader.ConfigData`

### Field Summary

Fields
`static String` `ALIASES`
`static String` `AUTO_ADD_REPLICAS`
`static String` `BASE_URL_PROP`
`static String` `CLUSTER_PROPS`
`static String` `CLUSTER_STATE`
`protected ClusterState` `clusterState` A view of the current state of all collections; combines all the different state sources into a single view.
`static String` `COLLECTION_PROP`
`static String` `COLLECTIONS_ZKNODE`
`static String` `CONFIGNAME_PROP`
`static String` `CONFIGS_ZKNODE`
`static String` `CORE_NAME_PROP`
`static String` `CORE_NODE_NAME_PROP`
`static String` `ELECTION_NODE`
`static String` `ELECTION_NODE_PROP`
`static Set<String>` `KNOWN_CLUSTER_PROPS`
`static String` `LEADER_ELECT_ZKNODE`
`static String` `LEADER_PROP`
`static String` `LEGACY_CLOUD`
`static String` `LIVE_NODES_ZKNODE`
`static String` `MAX_AT_ONCE_PROP`
`static String` `MAX_SHARDS_PER_NODE`
`static String` `MAX_WAIT_SECONDS_PROP`
`static String` `NODE_NAME_PROP`
`static String` `NUM_SHARDS_PROP`
`static String` `PROPERTY_PROP`
`static String` `PROPERTY_VALUE_PROP`
`static String` `REJOIN_AT_HEAD_PROP`
`static String` `REPLICA_PROP`
`static String` `REPLICATION_FACTOR`
`static String` `ROLES`
`static String` `ROLES_PROP`
`static String` `SHARD_ID_PROP`
`static String` `SHARD_LEADERS_ZKNODE`
`static String` `SHARD_PARENT_PROP`
`static String` `SHARD_RANGE_PROP`
`static String` `SHARD_STATE_PROP`
`static String` `SOLR_SECURITY_CONF_PATH`
`static String` `STATE_PROP`
`static String` `URL_SCHEME`

### Constructor Summary

Constructors
Constructor and Description
`ZkStateReader(SolrZkClient zkClient)`
`ZkStateReader(SolrZkClient zkClient, Runnable securityNodeListener)`
`ZkStateReader(String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout)`

### Method Summary

Methods
`void` `addCollectionWatch(String coll)`
`void` `close()`
`Integer` `compareStateVersions(String coll, int version)`
`void` `createClusterStateWatchersAndUpdate()`
`Aliases` `getAliases()`
`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` `getClusterProps()`
`ClusterState` `getClusterState()`
`static DocCollection` `getCollectionLive(ZkStateReader zkStateReader, String coll)`
`static String` `getCollectionPath(String coll)`
`ZkConfigManager` `getConfigManager()`
`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)`
`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()`
`String` `readConfigName(String collection)` Returns config set name for collection.
`void` `removeZKWatch(String coll)` This is not a public API.
`void` `setClusterProperty(String propertyName, String propertyValue)` This method sets a cluster property.
`void` `updateAliases()`
`void` `updateClusterState()` Forcibly refresh cluster state from ZK.
`void` `updateLiveNodes()` Refresh the set of live nodes.

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

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### BASE_URL_PROP

    public static final String BASE_URL_PROP

See Also:
  Constant Field Values

#### NODE_NAME_PROP

    public static final String NODE_NAME_PROP

See Also:
  Constant Field Values

#### CORE_NODE_NAME_PROP

    public static final String CORE_NODE_NAME_PROP

See Also:
  Constant Field Values

#### ROLES_PROP

    public static final String ROLES_PROP

See Also:
  Constant Field Values

#### STATE_PROP

    public static final String STATE_PROP

See Also:
  Constant Field Values

#### CORE_NAME_PROP

    public static final String CORE_NAME_PROP

See Also:
  Constant Field Values

#### COLLECTION_PROP

    public static final String COLLECTION_PROP

See Also:
  Constant Field Values

#### ELECTION_NODE_PROP

    public static final String ELECTION_NODE_PROP

See Also:
  Constant Field Values

#### SHARD_ID_PROP

    public static final String SHARD_ID_PROP

See Also:
  Constant Field Values

#### REPLICA_PROP

    public static final String REPLICA_PROP

See Also:
  Constant Field Values

#### SHARD_RANGE_PROP

    public static final String SHARD_RANGE_PROP

See Also:
  Constant Field Values

#### SHARD_STATE_PROP

    public static final String SHARD_STATE_PROP

See Also:
  Constant Field Values

#### SHARD_PARENT_PROP

    public static final String SHARD_PARENT_PROP

See Also:
  Constant Field Values

#### NUM_SHARDS_PROP

    public static final String NUM_SHARDS_PROP

See Also:
  Constant Field Values

#### LEADER_PROP

    public static final String LEADER_PROP

See Also:
  Constant Field Values

#### PROPERTY_PROP

    public static final String PROPERTY_PROP

See Also:
  Constant Field Values

#### PROPERTY_VALUE_PROP

    public static final String PROPERTY_VALUE_PROP

See Also:
  Constant Field Values

#### MAX_AT_ONCE_PROP

    public static final String MAX_AT_ONCE_PROP

See Also:
  Constant Field Values

#### MAX_WAIT_SECONDS_PROP

    public static final String MAX_WAIT_SECONDS_PROP

See Also:
  Constant Field Values

#### COLLECTIONS_ZKNODE

    public static final String COLLECTIONS_ZKNODE

See Also:
  Constant Field Values

#### LIVE_NODES_ZKNODE

    public static final String LIVE_NODES_ZKNODE

See Also:
  Constant Field Values

#### ALIASES

    public static final String ALIASES

See Also:
  Constant Field Values

#### CLUSTER_STATE

    public static final String CLUSTER_STATE

See Also:
  Constant Field Values

#### CLUSTER_PROPS

    public static final String CLUSTER_PROPS

See Also:
  Constant Field Values

#### REJOIN_AT_HEAD_PROP

    public static final String REJOIN_AT_HEAD_PROP

See Also:
  Constant Field Values

#### SOLR_SECURITY_CONF_PATH

    public static final String SOLR_SECURITY_CONF_PATH

See Also:
  Constant Field Values

#### REPLICATION_FACTOR

    public static final String REPLICATION_FACTOR

See Also:
  Constant Field Values

#### MAX_SHARDS_PER_NODE

    public static final String MAX_SHARDS_PER_NODE

See Also:
  Constant Field Values

#### AUTO_ADD_REPLICAS

    public static final String AUTO_ADD_REPLICAS

See Also:
  Constant Field Values

#### ROLES

    public static final String ROLES

See Also:
  Constant Field Values

#### CONFIGS_ZKNODE

    public static final String CONFIGS_ZKNODE

See Also:
  Constant Field Values

#### CONFIGNAME_PROP

    public static final String CONFIGNAME_PROP

See Also:
  Constant Field Values

#### LEGACY_CLOUD

    public static final String LEGACY_CLOUD

See Also:
  Constant Field Values

#### URL_SCHEME

    public static final String URL_SCHEME

See Also:
  Constant Field Values

#### clusterState

    protected volatile ClusterState clusterState

A view of the current state of all collections; combines all the different state sources into a single view.

#### LEADER_ELECT_ZKNODE

    public static final String LEADER_ELECT_ZKNODE

See Also:
  Constant Field Values

#### SHARD_LEADERS_ZKNODE

    public static final String SHARD_LEADERS_ZKNODE

See Also:
  Constant Field Values

#### ELECTION_NODE

    public static final String ELECTION_NODE

See Also:
  Constant Field Values

#### KNOWN_CLUSTER_PROPS

    public static final Set<String> KNOWN_CLUSTER_PROPS

### Constructor Detail

#### ZkStateReader

    public ZkStateReader(SolrZkClient zkClient)

#### ZkStateReader

    public ZkStateReader(SolrZkClient zkClient,
                 Runnable securityNodeListener)

#### ZkStateReader

    public ZkStateReader(String zkServerAddress,
                 int zkClientTimeout,
                 int zkClientConnectTimeout)

### Method Detail

#### readConfigName

    public String readConfigName(String collection)

Returns config set name for collection.

Parameters:
  `collection` - to return config set name for

#### getConfigManager

    public ZkConfigManager getConfigManager()

#### updateClusterState

    public void updateClusterState()
                            throws org.apache.zookeeper.KeeperException,
                                   InterruptedException

Forcibly refresh cluster state from ZK. Do this only to avoid race conditions because it's expensive.

Throws:
  `org.apache.zookeeper.KeeperException`
  `InterruptedException`

#### updateLiveNodes

    public void updateLiveNodes()
                         throws org.apache.zookeeper.KeeperException,
                                InterruptedException

Refresh the set of live nodes.

Throws:
  `org.apache.zookeeper.KeeperException`
  `InterruptedException`

#### getAliases

    public Aliases getAliases()

#### compareStateVersions

    public Integer compareStateVersions(String coll,
                               int version)

#### createClusterStateWatchersAndUpdate

    public void createClusterStateWatchersAndUpdate()
                                             throws org.apache.zookeeper.KeeperException,
                                                    InterruptedException

Throws:
  `org.apache.zookeeper.KeeperException`
  `InterruptedException`

#### getClusterState

    public ClusterState getClusterState()

Returns:
  information about the cluster from ZooKeeper

#### getUpdateLock

    public Object getUpdateLock()

#### close

    public void close()

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`

#### getLeaderUrl

    public String getLeaderUrl(String collection,
                      String shard,
                      int timeout)
                        throws InterruptedException,
                               org.apache.zookeeper.KeeperException

Throws:
  `InterruptedException`
  `org.apache.zookeeper.KeeperException`

#### getLeader

    public Replica getLeader(String collection,
                    String shard)
                      throws InterruptedException

Throws:
  `InterruptedException`

#### getLeaderRetry

    public Replica getLeaderRetry(String collection,
                         String shard)
                           throws InterruptedException

Get shard leader properties, with retry if none exist.

Throws:
  `InterruptedException`

#### getLeaderRetry

    public Replica getLeaderRetry(String collection,
                         String shard,
                         int timeout)
                           throws InterruptedException

Get shard leader properties, with retry if none exist.

Throws:
  `InterruptedException`

#### getShardLeadersPath

    public static String getShardLeadersPath(String collection,
                             String shardId)

Get path where shard leader properties live in zookeeper.

#### getShardLeadersElectPath

    public static String getShardLeadersElectPath(String collection,
                                  String shardId)

Get path where shard leader elections ephemeral nodes are.

#### getReplicaProps

    public List<ZkCoreNodeProps> getReplicaProps(String collection,
                                        String shardId,
                                        String thisCoreNodeName)

#### getReplicaProps

    public List<ZkCoreNodeProps> getReplicaProps(String collection,
                                        String shardId,
                                        String thisCoreNodeName,
                                        Replica.State mustMatchStateFilter)

#### getReplicaProps

    public List<ZkCoreNodeProps> getReplicaProps(String collection,
                                        String shardId,
                                        String thisCoreNodeName,
                                        Replica.State mustMatchStateFilter,
                                        Replica.State mustNotMatchStateFilter)

#### getZkClient

    public SolrZkClient getZkClient()

#### updateAliases

    public void updateAliases()
                       throws org.apache.zookeeper.KeeperException,
                              InterruptedException

Throws:
  `org.apache.zookeeper.KeeperException`
  `InterruptedException`

#### getClusterProps

    public Map getClusterProps()

#### setClusterProperty

    public void setClusterProperty(String propertyName,
                          String propertyValue)

This method sets a cluster property.

Parameters:
  `propertyName` - The property name to be set.
  `propertyValue` - The value of the property.

#### getSecurityProps

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

#### getBaseUrlForNodeName

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

WARNING: This API is experimental and might change in incompatible ways in the next release.

#### getCollectionLive

    public static DocCollection getCollectionLive(ZkStateReader zkStateReader,
                                  String coll)

#### getCollectionPath

    public static String getCollectionPath(String coll)

#### addCollectionWatch

    public void addCollectionWatch(String coll)
                            throws org.apache.zookeeper.KeeperException,
                                   InterruptedException

Throws:
  `org.apache.zookeeper.KeeperException`
  `InterruptedException`

#### removeZKWatch

    public void removeZKWatch(String coll)

This is not a public API. Only used by ZkController