org.apache.solr.common.cloud

## Class SolrZkClient

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

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class SolrZkClient
      extends Object
      implements Closeable

  All Solr ZooKeeper interactions should go through this class rather than ZooKeeper. This class handles synchronous connects and reconnections.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME`
    `static String` | `ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SolrZkClient()`
    `SolrZkClient(String zkServerAddress, int zkClientTimeout)`
    `SolrZkClient(String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout)`
    `SolrZkClient(String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout, OnReconnect onReonnect)`
    `SolrZkClient(String zkServerAddress, int zkClientTimeout, int clientConnectTimeout, ZkClientConnectionStrategy strat, OnReconnect onReconnect)`
    `SolrZkClient(String zkServerAddress, int zkClientTimeout, int clientConnectTimeout, ZkClientConnectionStrategy strat, OnReconnect onReconnect, BeforeReconnect beforeReconnect)`
    `SolrZkClient(String zkServerAddress, int zkClientTimeout, int clientConnectTimeout, ZkClientConnectionStrategy strat, OnReconnect onReconnect, BeforeReconnect beforeReconnect, ZkACLProvider zkACLProvider)`
    `SolrZkClient(String zkServerAddress, int zkClientTimeout, ZkClientConnectionStrategy strat, OnReconnect onReconnect)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Throwable` | `checkInterrupted(Throwable e)` Check to see if a Throwable is an InterruptedException, and if it is, set the thread interrupt flag
    `void` | `clean(String path)`
    `void` | `close()`
    `static boolean` | `containsChroot(String zkHost)` Validates if zkHost contains a chroot.
    `String` | `create(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss)` Returns path of created node
    `protected ZkACLProvider` | `createZkACLProvider()`
    `protected ZkCredentialsProvider` | `createZkCredentialsToAddAutomatically()`
    `void` | `delete(String path, int version, boolean retryOnConnLoss)`
    `void` | `downConfig(String confName, Path confPath)`
    `void` | `downloadFromZK(String zkPath, Path dir)`
    `Boolean` | `exists(String path, boolean retryOnConnLoss)` Returns true if path exists
    `org.apache.zookeeper.data.Stat` | `exists(String path, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss)` Return the stat of the node of the given path.
    `List<String>` | `getChildren(String path, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss)` Returns children of the node at the path
    `ConnectionManager` | `getConnectionManager()`
    `byte[]` | `getData(String path, org.apache.zookeeper.Watcher watcher, org.apache.zookeeper.data.Stat stat, boolean retryOnConnLoss)` Returns node's data
    `SolrZooKeeper` | `getSolrZooKeeper()`
    `ZkACLProvider` | `getZkACLProvider()`
    `ZkClientConnectionStrategy` | `getZkClientConnectionStrategy()`
    `int` | `getZkClientTimeout()`
    `String` | `getZkServerAddress()`
    `boolean` | `isClosed()`
    `boolean` | `isConnected()` Returns true if client is connected
    `String` | `listZnode(String path, Boolean recurse)`
    `void` | `makePath(String path, boolean retryOnConnLoss)` Creates the path in ZooKeeper, creating each node as necessary.
    `void` | `makePath(String path, boolean failOnExists, boolean retryOnConnLoss)`
    `void` | `makePath(String path, byte[] data, boolean retryOnConnLoss)` Creates the path in ZooKeeper, creating each node as necessary.
    `void` | `makePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss)` Creates the path in ZooKeeper, creating each node as necessary.
    `void` | `makePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss)` Creates the path in ZooKeeper, creating each node as necessary.
    `void` | `makePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean failOnExists, boolean retryOnConnLoss)` Creates the path in ZooKeeper, creating each node as necessary.
    `void` | `makePath(String path, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss)`
    `void` | `makePath(String zkPath, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss)`
    `void` | `makePath(String path, File file, boolean retryOnConnLoss)`
    `void` | `makePath(String path, File file, boolean failOnExists, boolean retryOnConnLoss)`
    `void` | `moveZnode(String src, String dst)`
    `List<org.apache.zookeeper.OpResult>` | `multi(Iterable<org.apache.zookeeper.Op> ops, boolean retryOnConnLoss)`
    `static String` | `prettyPrint(String input, int indent)`
    `void` | `printLayout(String path, int indent, StringBuilder string)` Fills string with printout of current ZooKeeper layout.
    `void` | `printLayoutToStdOut()` Prints current ZooKeeper layout to stdout.
    `org.apache.zookeeper.data.Stat` | `setACL(String path, List<org.apache.zookeeper.data.ACL> acls, boolean retryOnConnLoss)` Set the ACL on a single node in ZooKeeper.
    `org.apache.zookeeper.data.Stat` | `setData(String path, byte[] data, boolean retryOnConnLoss)` Write data to ZooKeeper.
    `org.apache.zookeeper.data.Stat` | `setData(String path, byte[] data, int version, boolean retryOnConnLoss)` Returns node's state
    `org.apache.zookeeper.data.Stat` | `setData(String path, File file, boolean retryOnConnLoss)` Write file to ZooKeeper - default system encoding used.
    `void` | `upConfig(Path confPath, String confName)`
    `void` | `updateACLs(String root)` Update all ACLs for a zk tree based on our configured `ZkACLProvider`.
    `void` | `uploadToZK(Path rootPath, String zkPath, Pattern filenameExclusions)`
    `org.apache.zookeeper.Watcher` | `wrapWatcher(org.apache.zookeeper.Watcher watcher)` Wraps the watcher so that it doesn't fire off ZK's event queue.
    `void` | `zkTransfer(String src, Boolean srcIsZk, String dst, Boolean dstIsZk, Boolean recurse)`

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

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

- - ### Field Detail

    - #### ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME

          public static final String ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME

      See Also:
        Constant Field Values

    - #### ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME

          public static final String ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SolrZkClient

          public SolrZkClient()

    - #### SolrZkClient

          public SolrZkClient(String zkServerAddress,
                              int zkClientTimeout)

    - #### SolrZkClient

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

    - #### SolrZkClient

          public SolrZkClient(String zkServerAddress,
                              int zkClientTimeout,
                              int zkClientConnectTimeout,
                              OnReconnect onReonnect)

    - #### SolrZkClient

          public SolrZkClient(String zkServerAddress,
                              int zkClientTimeout,
                              ZkClientConnectionStrategy strat,
                              OnReconnect onReconnect)

    - #### SolrZkClient

          public SolrZkClient(String zkServerAddress,
                              int zkClientTimeout,
                              int clientConnectTimeout,
                              ZkClientConnectionStrategy strat,
                              OnReconnect onReconnect)

    - #### SolrZkClient

          public SolrZkClient(String zkServerAddress,
                              int zkClientTimeout,
                              int clientConnectTimeout,
                              ZkClientConnectionStrategy strat,
                              OnReconnect onReconnect,
                              BeforeReconnect beforeReconnect)

    - #### SolrZkClient

          public SolrZkClient(String zkServerAddress,
                              int zkClientTimeout,
                              int clientConnectTimeout,
                              ZkClientConnectionStrategy strat,
                              OnReconnect onReconnect,
                              BeforeReconnect beforeReconnect,
                              ZkACLProvider zkACLProvider)

  - ### Method Detail

    - #### getZkClientTimeout

          public int getZkClientTimeout()

    - #### getConnectionManager

          public ConnectionManager getConnectionManager()

    - #### getZkClientConnectionStrategy

          public ZkClientConnectionStrategy getZkClientConnectionStrategy()

    - #### createZkCredentialsToAddAutomatically

          protected ZkCredentialsProvider createZkCredentialsToAddAutomatically()

    - #### createZkACLProvider

          protected ZkACLProvider createZkACLProvider()

    - #### isConnected

          public boolean isConnected()

      Returns true if client is connected

    - #### delete

          public void delete(String path,
                             int version,
                             boolean retryOnConnLoss)
                      throws InterruptedException,
                             org.apache.zookeeper.KeeperException

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

    - #### wrapWatcher

          public org.apache.zookeeper.Watcher wrapWatcher(org.apache.zookeeper.Watcher watcher)

      Wraps the watcher so that it doesn't fire off ZK's event queue. In order to guarantee that a watch object will only be triggered once for a given notification, users need to wrap their watcher using this method before calling `exists(String, org.apache.zookeeper.Watcher, boolean)` or `getData(String, org.apache.zookeeper.Watcher, org.apache.zookeeper.data.Stat, boolean)`.

    - #### exists

          public org.apache.zookeeper.data.Stat exists(String path,
                                                       org.apache.zookeeper.Watcher watcher,
                                                       boolean retryOnConnLoss)
                                                throws org.apache.zookeeper.KeeperException,
                                                       InterruptedException

      Return the stat of the node of the given path. Return null if no such a node exists.

      If the watch is non-null and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch will be triggered by a successful operation that creates/delete the node or sets the data on the node.

      Parameters:
        `path` - the node path
        `watcher` - explicit watcher
      Returns:
        the stat of the node of the given path; return null if no such a node exists.
      Throws:
        `org.apache.zookeeper.KeeperException` - If the server signals an error
        `InterruptedException` - If the server transaction is interrupted.
        `IllegalArgumentException` - if an invalid path is specified

    - #### exists

          public Boolean exists(String path,
                                boolean retryOnConnLoss)
                         throws org.apache.zookeeper.KeeperException,
                                InterruptedException

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

    - #### getChildren

          public List<String> getChildren(String path,
                                          org.apache.zookeeper.Watcher watcher,
                                          boolean retryOnConnLoss)
                                   throws org.apache.zookeeper.KeeperException,
                                          InterruptedException

      Returns children of the node at the path
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### getData

          public byte[] getData(String path,
                                org.apache.zookeeper.Watcher watcher,
                                org.apache.zookeeper.data.Stat stat,
                                boolean retryOnConnLoss)
                         throws org.apache.zookeeper.KeeperException,
                                InterruptedException

      Returns node's data
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### setData

          public org.apache.zookeeper.data.Stat setData(String path,
                                                        byte[] data,
                                                        int version,
                                                        boolean retryOnConnLoss)
                                                 throws org.apache.zookeeper.KeeperException,
                                                        InterruptedException

      Returns node's state
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### create

          public String create(String path,
                               byte[] data,
                               org.apache.zookeeper.CreateMode createMode,
                               boolean retryOnConnLoss)
                        throws org.apache.zookeeper.KeeperException,
                               InterruptedException

      Returns path of created node
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### makePath

          public void makePath(String path,
                               boolean retryOnConnLoss)
                        throws org.apache.zookeeper.KeeperException,
                               InterruptedException

      Creates the path in ZooKeeper, creating each node as necessary. e.g. If `path=/solr/group/node` and none of the nodes, solr, group, node exist, each will be created.
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### makePath

          public void makePath(String path,
                               boolean failOnExists,
                               boolean retryOnConnLoss)
                        throws org.apache.zookeeper.KeeperException,
                               InterruptedException

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

    - #### makePath

          public void makePath(String path,
                               File file,
                               boolean failOnExists,
                               boolean retryOnConnLoss)
                        throws IOException,
                               org.apache.zookeeper.KeeperException,
                               InterruptedException

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

    - #### makePath

          public void makePath(String path,
                               File file,
                               boolean retryOnConnLoss)
                        throws IOException,
                               org.apache.zookeeper.KeeperException,
                               InterruptedException

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

    - #### makePath

          public void makePath(String path,
                               org.apache.zookeeper.CreateMode createMode,
                               boolean retryOnConnLoss)
                        throws org.apache.zookeeper.KeeperException,
                               InterruptedException

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

    - #### makePath

          public void makePath(String path,
                               byte[] data,
                               boolean retryOnConnLoss)
                        throws org.apache.zookeeper.KeeperException,
                               InterruptedException

      Creates the path in ZooKeeper, creating each node as necessary.
      Parameters:
        `data` - to set on the last zkNode
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### makePath

          public void makePath(String path,
                               byte[] data,
                               org.apache.zookeeper.CreateMode createMode,
                               boolean retryOnConnLoss)
                        throws org.apache.zookeeper.KeeperException,
                               InterruptedException

      Creates the path in ZooKeeper, creating each node as necessary. e.g. If `path=/solr/group/node` and none of the nodes, solr, group, node exist, each will be created.
      Parameters:
        `data` - to set on the last zkNode
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### makePath

          public void makePath(String path,
                               byte[] data,
                               org.apache.zookeeper.CreateMode createMode,
                               org.apache.zookeeper.Watcher watcher,
                               boolean retryOnConnLoss)
                        throws org.apache.zookeeper.KeeperException,
                               InterruptedException

      Creates the path in ZooKeeper, creating each node as necessary. e.g. If `path=/solr/group/node` and none of the nodes, solr, group, node exist, each will be created.
      Parameters:
        `data` - to set on the last zkNode
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### makePath

          public void makePath(String path,
                               byte[] data,
                               org.apache.zookeeper.CreateMode createMode,
                               org.apache.zookeeper.Watcher watcher,
                               boolean failOnExists,
                               boolean retryOnConnLoss)
                        throws org.apache.zookeeper.KeeperException,
                               InterruptedException

      Creates the path in ZooKeeper, creating each node as necessary. e.g. If `path=/solr/group/node` and none of the nodes, solr, group, node exist, each will be created. Note: retryOnConnLoss is only respected for the final node - nodes before that are always retried on connection loss.
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### makePath

          public void makePath(String zkPath,
                               org.apache.zookeeper.CreateMode createMode,
                               org.apache.zookeeper.Watcher watcher,
                               boolean retryOnConnLoss)
                        throws org.apache.zookeeper.KeeperException,
                               InterruptedException

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

    - #### setData

          public org.apache.zookeeper.data.Stat setData(String path,
                                                        byte[] data,
                                                        boolean retryOnConnLoss)
                                                 throws org.apache.zookeeper.KeeperException,
                                                        InterruptedException

      Write data to ZooKeeper.
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### setData

          public org.apache.zookeeper.data.Stat setData(String path,
                                                        File file,
                                                        boolean retryOnConnLoss)
                                                 throws IOException,
                                                        org.apache.zookeeper.KeeperException,
                                                        InterruptedException

      Write file to ZooKeeper - default system encoding used.
      Parameters:
        `path` - path to upload file to e.g. /solr/conf/solrconfig.xml
        `file` - path to file to be uploaded
      Throws:
        `IOException`
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### multi

          public List<org.apache.zookeeper.OpResult> multi(Iterable<org.apache.zookeeper.Op> ops,
                                                           boolean retryOnConnLoss)
                                                    throws InterruptedException,
                                                           org.apache.zookeeper.KeeperException

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

    - #### printLayout

          public void printLayout(String path,
                                  int indent,
                                  StringBuilder string)
                           throws org.apache.zookeeper.KeeperException,
                                  InterruptedException

      Fills string with printout of current ZooKeeper layout.
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### printLayoutToStdOut

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

      Prints current ZooKeeper layout to stdout.
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### prettyPrint

          public static String prettyPrint(String input,
                                           int indent)

    - #### close

          public void close()

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

    - #### isClosed

          public boolean isClosed()

    - #### getSolrZooKeeper

          public SolrZooKeeper getSolrZooKeeper()

    - #### containsChroot

          public static boolean containsChroot(String zkHost)

      Validates if zkHost contains a chroot. See http://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#ch_zkSessions

    - #### checkInterrupted

          public static Throwable checkInterrupted(Throwable e)

      Check to see if a Throwable is an InterruptedException, and if it is, set the thread interrupt flag
      Parameters:
        `e` - the Throwable
      Returns:
        the Throwable

    - #### getZkServerAddress

          public String getZkServerAddress()

      Returns:
        the address of the zookeeper cluster

    - #### getZkACLProvider

          public ZkACLProvider getZkACLProvider()

    - #### setACL

          public org.apache.zookeeper.data.Stat setACL(String path,
                                                       List<org.apache.zookeeper.data.ACL> acls,
                                                       boolean retryOnConnLoss)
                                                throws InterruptedException,
                                                       org.apache.zookeeper.KeeperException

      Set the ACL on a single node in ZooKeeper. This will replace all existing ACL on that node.
      Parameters:
        `path` - path to set ACL on e.g. /solr/conf/solrconfig.xml
        `acls` - a list of `ACL`s to be applied
        `retryOnConnLoss` - true if the command should be retried on connection loss
      Throws:
        `InterruptedException`
        `org.apache.zookeeper.KeeperException`

    - #### updateACLs

          public void updateACLs(String root)
                          throws org.apache.zookeeper.KeeperException,
                                 InterruptedException

      Update all ACLs for a zk tree based on our configured `ZkACLProvider`.
      Parameters:
        `root` - the root node to recursively update
      Throws:
        `org.apache.zookeeper.KeeperException`
        `InterruptedException`

    - #### clean

          public void clean(String path)
                     throws InterruptedException,
                            org.apache.zookeeper.KeeperException

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

    - #### upConfig

          public void upConfig(Path confPath,
                               String confName)
                        throws IOException

      Throws:
        `IOException`

    - #### listZnode

          public String listZnode(String path,
                                  Boolean recurse)
                           throws org.apache.zookeeper.KeeperException,
                                  InterruptedException,
                                  SolrServerException

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

    - #### downConfig

          public void downConfig(String confName,
                                 Path confPath)
                          throws IOException

      Throws:
        `IOException`

    - #### zkTransfer

          public void zkTransfer(String src,
                                 Boolean srcIsZk,
                                 String dst,
                                 Boolean dstIsZk,
                                 Boolean recurse)
                          throws SolrServerException,
                                 org.apache.zookeeper.KeeperException,
                                 InterruptedException,
                                 IOException

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

    - #### moveZnode

          public void moveZnode(String src,
                                String dst)
                         throws SolrServerException,
                                org.apache.zookeeper.KeeperException,
                                InterruptedException

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

    - #### uploadToZK

          public void uploadToZK(Path rootPath,
                                 String zkPath,
                                 Pattern filenameExclusions)
                          throws IOException

      Throws:
        `IOException`

    - #### downloadFromZK

          public void downloadFromZK(String zkPath,
                                     Path dir)
                              throws IOException

      Throws:
        `IOException`

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