org.apache.solr.cloud

## Class ZkController

- java.lang.Object
- - org.apache.solr.cloud.ZkController

-     public class ZkController
      extends Object

  Handle ZooKeeper interactions.

  notes: loads everything on init, creates what's not there - further updates are prompted with Watches.

  TODO: exceptions during close on attempts to update cloud state

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `ZkController.NotLeaderException` Thrown during leader initiated recovery process if current node is not leader
    `static class` | `ZkController.ResourceModifiedInZkException`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `COLLECTION_PARAM_PREFIX`
    `static String` | `CONFIGNAME_PROP`
    `protected Overseer` | `overseer`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ZkController(CoreContainer cc, String zkServerAddress, int zkClientConnectTimeout, CloudConfig cloudConfig, CurrentCoreDescriptorProvider registerOnReconnect)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addOnReconnectListener(OnReconnect listener)` Add a listener to be notified once there is a new session created after a ZooKeeper session expiration occurs; in most cases, listeners will be components that have watchers that need to be re-created.
    `static void` | `bootstrapConf(SolrZkClient zkClient, CoreContainer cc, String solrHome)` If in SolrCloud mode, upload config sets for each SolrCore in solr.xml.
    `static boolean` | `checkChrootPath(String zkHost, boolean create)` Validates if the chroot exists in zk (or if it is successfully created).
    `boolean` | `checkIfCoreNodeNameAlreadyExists(CoreDescriptor dcore)`
    `void` | `checkOverseerDesignate()`
    `void` | `close()` Closes the underlying ZooKeeper client.
    `boolean` | `configFileExists(String collection, String fileName)` Returns true if config file exists
    `static void` | `createClusterZkNodes(SolrZkClient zkClient)` Create the zknodes necessary for a cluster to operate
    `void` | `createCollection(String collection)`
    `void` | `createCollectionZkNode(CloudDescriptor cd)`
    `boolean` | `ensureReplicaInLeaderInitiatedRecovery(CoreContainer container, String collection, String shardId, ZkCoreNodeProps replicaCoreProps, CoreDescriptor leaderCd, boolean forcePublishState)` When a leader receives a communication error when trying to send a request to a replica, it calls this method to ensure the replica enters recovery when connectivity is restored.
    `String` | `getBaseUrl()`
    `int` | `getClientTimeout()`
    `ClusterState` | `getClusterState()`
    `OnReconnect` | `getConfigDirListener()`
    `byte[]` | `getConfigFileData(String zkConfigName, String fileName)` Returns config file data (in bytes)
    `String` | `getCoreNodeName(CoreDescriptor descriptor)`
    `String` | `getHostName()`
    `int` | `getHostPort()`
    `int` | `getLeaderConflictResolveWait()`
    `Replica.State` | `getLeaderInitiatedRecoveryState(String collection, String shardId, String coreNodeName)`
    `Map<String,Object>` | `getLeaderInitiatedRecoveryStateObject(String collection, String shardId, String coreNodeName)`
    `String` | `getLeaderInitiatedRecoveryZnodePath(String collection, String shardId)`
    `String` | `getLeaderInitiatedRecoveryZnodePath(String collection, String shardId, String coreNodeName)`
    `ZkCoreNodeProps` | `getLeaderProps(String collection, String slice, int timeoutms)` Get leader props directly from zk nodes.
    `ZkCoreNodeProps` | `getLeaderProps(String collection, String slice, int timeoutms, boolean failImmediatelyOnExpiration)` Get leader props directly from zk nodes.
    `String` | `getLeaderSeqPath(String collection, String coreNodeName)`
    `int` | `getLeaderVoteWait()`
    `String` | `getNodeName()`
    `Overseer` | `getOverseer()`
    `OverseerTaskQueue` | `getOverseerCollectionQueue()`
    `DistributedMap` | `getOverseerCompletedMap()`
    `OverseerTaskQueue` | `getOverseerConfigSetQueue()`
    `LeaderElector` | `getOverseerElector()`
    `DistributedMap` | `getOverseerFailureMap()`
    `DistributedQueue` | `getOverseerJobQueue()`
    `DistributedMap` | `getOverseerRunningMap()`
    `SolrZkClient` | `getZkClient()`
    `String` | `getZkServerAddress()`
    `ZkStateReader` | `getZkStateReader()`
    `boolean` | `isConnected()`
    `boolean` | `isReplicaInRecoveryHandling(String replicaUrl)`
    `static void` | `linkConfSet(SolrZkClient zkClient, String collection, String confSetName)`
    `boolean` | `pathExists(String path)` Returns true if the path exists
    `static int` | `persistConfigResourceToZooKeeper(ZkSolrResourceLoader zkLoader, int znodeVersion, String resourceName, byte[] content, boolean createIfNotExists)` Persists a config file to ZooKeeper using optimistic concurrency.
    `void` | `preRegister(CoreDescriptor cd)`
    `void` | `publish(CoreDescriptor cd, Replica.State state)`
    `void` | `publish(CoreDescriptor cd, Replica.State state, boolean updateLastState)`
    `void` | `publish(CoreDescriptor cd, Replica.State state, boolean updateLastState, boolean forcePublish)` Publish core state to overseer.
    `void` | `publishAndWaitForDownStates()`
    `void` | `publishNodeAsDown(String nodeName)` Best effort to set DOWN state for all replicas on node.
    `String` | `register(String coreName, CoreDescriptor desc, boolean skipRecovery)` Register shard with ZooKeeper.
    `String` | `register(String coreName, CoreDescriptor desc, boolean recoverReloadedCores, boolean afterExpiration, boolean skipRecovery)` Register shard with ZooKeeper.
    `void` | `registerConfListenerForCore(String confDir, SolrCore core, Runnable listener)` This will give a callback to the listener whenever a child is modified in the conf directory.
    `void` | `rejoinOverseerElection(String electionNode, boolean joinAtHead)`
    `void` | `rejoinShardLeaderElection(SolrParams params)`
    `void` | `removeOnReconnectListener(OnReconnect listener)` Removed a previously registered OnReconnect listener, such as when a core is removed or reloaded.
    `void` | `removeReplicaFromLeaderInitiatedRecoveryHandling(String replicaUrl)`
    `void` | `throwErrorIfReplicaReplaced(CoreDescriptor desc)`
    `static void` | `touchConfDir(ZkSolrResourceLoader zkLoader)`
    `static String` | `trimLeadingAndTrailingSlashes(String in)` Utility method for trimming and leading and/or trailing slashes from its input.
    `void` | `unregister(String coreName, CoreDescriptor cd)`
    `void` | `updateLeaderInitiatedRecoveryState(String collection, String shardId, String coreNodeName, Replica.State state, CoreDescriptor leaderCd, boolean retryOnConnLoss)`

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

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

- - ### Field Detail

    - #### COLLECTION_PARAM_PREFIX

          public static final String COLLECTION_PARAM_PREFIX

      See Also:
        Constant Field Values

    - #### CONFIGNAME_PROP

          public static final String CONFIGNAME_PROP

      See Also:
        Constant Field Values

    - #### overseer

          protected volatile Overseer overseer

  - ### Constructor Detail

    - #### ZkController

          public ZkController(CoreContainer cc,
                              String zkServerAddress,
                              int zkClientConnectTimeout,
                              CloudConfig cloudConfig,
                              CurrentCoreDescriptorProvider registerOnReconnect)
                       throws InterruptedException,
                              TimeoutException,
                              IOException

      Throws:
        `InterruptedException`
        `TimeoutException`
        `IOException`

  - ### Method Detail

    - #### getLeaderVoteWait

          public int getLeaderVoteWait()

    - #### getLeaderConflictResolveWait

          public int getLeaderConflictResolveWait()

    - #### close

          public void close()

      Closes the underlying ZooKeeper client.

    - #### configFileExists

          public boolean configFileExists(String collection,
                                          String fileName)
                                   throws org.apache.zookeeper.KeeperException,
                                          InterruptedException

      Returns true if config file exists
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### getClusterState

          public ClusterState getClusterState()

      Returns:
        information about the cluster from ZooKeeper

    - #### getConfigFileData

          public byte[] getConfigFileData(String zkConfigName,
                                          String fileName)
                                   throws org.apache.zookeeper.KeeperException,
                                          InterruptedException

      Returns config file data (in bytes)
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### getHostName

          public String getHostName()

    - #### getHostPort

          public int getHostPort()

    - #### getZkClient

          public SolrZkClient getZkClient()

    - #### getZkServerAddress

          public String getZkServerAddress()

      Returns:
        zookeeper server address

    - #### createClusterZkNodes

          public static void createClusterZkNodes(SolrZkClient zkClient)
                                           throws org.apache.zookeeper.KeeperException,
                                                  InterruptedException

      Create the zknodes necessary for a cluster to operate
      Parameters:
        `zkClient` - a SolrZkClient
      Throws:
        `org.apache.zookeeper.KeeperException` - if there is a Zookeeper error
        `InterruptedException` - on interrupt

    - #### publishAndWaitForDownStates

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

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

    - #### checkChrootPath

          public static boolean checkChrootPath(String zkHost,
                                                boolean create)
                                         throws org.apache.zookeeper.KeeperException,
                                                InterruptedException

      Validates if the chroot exists in zk (or if it is successfully created). Optionally, if create is set to true this method will create the path in case it doesn't exist
      Returns:
        true if the path exists or is created false if the path doesn't exist and 'create' = false
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### isConnected

          public boolean isConnected()

    - #### getNodeName

          public String getNodeName()

    - #### pathExists

          public boolean pathExists(String path)
                             throws org.apache.zookeeper.KeeperException,
                                    InterruptedException

      Returns true if the path exists
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### register

          public String register(String coreName,
                                 CoreDescriptor desc,
                                 boolean skipRecovery)
                          throws Exception

      Register shard with ZooKeeper.
      Returns:
        the shardId for the SolrCore
      Throws:
        `Exception`

    - #### register

          public String register(String coreName,
                                 CoreDescriptor desc,
                                 boolean recoverReloadedCores,
                                 boolean afterExpiration,
                                 boolean skipRecovery)
                          throws Exception

      Register shard with ZooKeeper.
      Returns:
        the shardId for the SolrCore
      Throws:
        `Exception`

    - #### getLeaderProps

          public ZkCoreNodeProps getLeaderProps(String collection,
                                                String slice,
                                                int timeoutms)
                                         throws InterruptedException

      Get leader props directly from zk nodes.
      Throws:
        `InterruptedException`

    - #### getLeaderProps

          public ZkCoreNodeProps getLeaderProps(String collection,
                                                String slice,
                                                int timeoutms,
                                                boolean failImmediatelyOnExpiration)
                                         throws InterruptedException

      Get leader props directly from zk nodes.
      Returns:
        leader props
      Throws:
        `InterruptedException`

    - #### getBaseUrl

          public String getBaseUrl()

    - #### publish

          public void publish(CoreDescriptor cd,
                              Replica.State state)
                       throws org.apache.zookeeper.KeeperException,
                              InterruptedException

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

    - #### publish

          public void publish(CoreDescriptor cd,
                              Replica.State state,
                              boolean updateLastState)
                       throws org.apache.zookeeper.KeeperException,
                              InterruptedException

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

    - #### publish

          public void publish(CoreDescriptor cd,
                              Replica.State state,
                              boolean updateLastState,
                              boolean forcePublish)
                       throws org.apache.zookeeper.KeeperException,
                              InterruptedException

      Publish core state to overseer.
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### unregister

          public void unregister(String coreName,
                                 CoreDescriptor cd)
                          throws InterruptedException,
                                 org.apache.zookeeper.KeeperException

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

    - #### createCollection

          public void createCollection(String collection)
                                throws org.apache.zookeeper.KeeperException,
                                       InterruptedException

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

    - #### createCollectionZkNode

          public void createCollectionZkNode(CloudDescriptor cd)

    - #### getZkStateReader

          public ZkStateReader getZkStateReader()

    - #### getCoreNodeName

          public String getCoreNodeName(CoreDescriptor descriptor)

    - #### preRegister

          public void preRegister(CoreDescriptor cd)

    - #### linkConfSet

          public static void linkConfSet(SolrZkClient zkClient,
                                         String collection,
                                         String confSetName)
                                  throws org.apache.zookeeper.KeeperException,
                                         InterruptedException

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

    - #### bootstrapConf

          public static void bootstrapConf(SolrZkClient zkClient,
                                           CoreContainer cc,
                                           String solrHome)
                                    throws IOException

      If in SolrCloud mode, upload config sets for each SolrCore in solr.xml.
      Throws:
        `IOException`

    - #### getOverseerJobQueue

          public DistributedQueue getOverseerJobQueue()

    - #### getOverseerCollectionQueue

          public OverseerTaskQueue getOverseerCollectionQueue()

    - #### getOverseerConfigSetQueue

          public OverseerTaskQueue getOverseerConfigSetQueue()

    - #### getOverseerRunningMap

          public DistributedMap getOverseerRunningMap()

    - #### getOverseerCompletedMap

          public DistributedMap getOverseerCompletedMap()

    - #### getOverseerFailureMap

          public DistributedMap getOverseerFailureMap()

    - #### getClientTimeout

          public int getClientTimeout()

    - #### getOverseer

          public Overseer getOverseer()

    - #### getOverseerElector

          public LeaderElector getOverseerElector()

    - #### trimLeadingAndTrailingSlashes

          public static String trimLeadingAndTrailingSlashes(String in)

      Utility method for trimming and leading and/or trailing slashes from its input. May return the empty string. May return null if and only if the input is null.

    - #### rejoinOverseerElection

          public void rejoinOverseerElection(String electionNode,
                                             boolean joinAtHead)

    - #### rejoinShardLeaderElection

          public void rejoinShardLeaderElection(SolrParams params)

    - #### checkOverseerDesignate

          public void checkOverseerDesignate()

    - #### ensureReplicaInLeaderInitiatedRecovery

          public boolean ensureReplicaInLeaderInitiatedRecovery(CoreContainer container,
                                                                String collection,
                                                                String shardId,
                                                                ZkCoreNodeProps replicaCoreProps,
                                                                CoreDescriptor leaderCd,
                                                                boolean forcePublishState)
                                                         throws org.apache.zookeeper.KeeperException,
                                                                InterruptedException

      When a leader receives a communication error when trying to send a request to a replica, it calls this method to ensure the replica enters recovery when connectivity is restored.

      returns true if the node hosting the replica is still considered "live" by ZooKeeper; false means the node is not live either, so no point in trying to send recovery commands to it.

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

    - #### isReplicaInRecoveryHandling

          public boolean isReplicaInRecoveryHandling(String replicaUrl)

    - #### removeReplicaFromLeaderInitiatedRecoveryHandling

          public void removeReplicaFromLeaderInitiatedRecoveryHandling(String replicaUrl)

    - #### getLeaderInitiatedRecoveryState

          public Replica.State getLeaderInitiatedRecoveryState(String collection,
                                                               String shardId,
                                                               String coreNodeName)

    - #### getLeaderInitiatedRecoveryStateObject

          public Map<String,Object> getLeaderInitiatedRecoveryStateObject(String collection,
                                                                          String shardId,
                                                                          String coreNodeName)

    - #### updateLeaderInitiatedRecoveryState

          public void updateLeaderInitiatedRecoveryState(String collection,
                                                         String shardId,
                                                         String coreNodeName,
                                                         Replica.State state,
                                                         CoreDescriptor leaderCd,
                                                         boolean retryOnConnLoss)

    - #### getLeaderInitiatedRecoveryZnodePath

          public String getLeaderInitiatedRecoveryZnodePath(String collection,
                                                            String shardId)

    - #### getLeaderInitiatedRecoveryZnodePath

          public String getLeaderInitiatedRecoveryZnodePath(String collection,
                                                            String shardId,
                                                            String coreNodeName)

    - #### throwErrorIfReplicaReplaced

          public void throwErrorIfReplicaReplaced(CoreDescriptor desc)

    - #### addOnReconnectListener

          public void addOnReconnectListener(OnReconnect listener)

      Add a listener to be notified once there is a new session created after a ZooKeeper session expiration occurs; in most cases, listeners will be components that have watchers that need to be re-created.

    - #### removeOnReconnectListener

          public void removeOnReconnectListener(OnReconnect listener)

      Removed a previously registered OnReconnect listener, such as when a core is removed or reloaded.

    - #### persistConfigResourceToZooKeeper

          public static int persistConfigResourceToZooKeeper(ZkSolrResourceLoader zkLoader,
                                                             int znodeVersion,
                                                             String resourceName,
                                                             byte[] content,
                                                             boolean createIfNotExists)

      Persists a config file to ZooKeeper using optimistic concurrency.
      Returns:
        true on success

    - #### touchConfDir

          public static void touchConfDir(ZkSolrResourceLoader zkLoader)

    - #### registerConfListenerForCore

          public void registerConfListenerForCore(String confDir,
                                                  SolrCore core,
                                                  Runnable listener)

      This will give a callback to the listener whenever a child is modified in the conf directory. It is the responsibility of the listener to check if the individual item of interest has been modified. When the last core which was interested in this conf directory is gone the listeners will be removed automatically.

    - #### getConfigDirListener

          public OnReconnect getConfigDirListener()

    - #### getLeaderSeqPath

          public String getLeaderSeqPath(String collection,
                                         String coreNodeName)

    - #### checkIfCoreNodeNameAlreadyExists

          public boolean checkIfCoreNodeNameAlreadyExists(CoreDescriptor dcore)

    - #### publishNodeAsDown

          public void publishNodeAsDown(String nodeName)

      Best effort to set DOWN state for all replicas on node.
      Parameters:
        `nodeName` - to operate on

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