Class ZkUtils

java.lang.Object
org.apache.bookkeeper.util.ZkUtils

public class ZkUtils extends Object
Provided utilities for zookeeper access, etc.
  • Constructor Details

    • ZkUtils

      public ZkUtils()
  • Method Details

    • asyncCreateFullPathOptimistic

      public static void asyncCreateFullPathOptimistic(org.apache.zookeeper.ZooKeeper zk, String originalPath, byte[] data, List<org.apache.zookeeper.data.ACL> acl, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.AsyncCallback.StringCallback callback, Object ctx)
      Asynchronously create zookeeper path recursively and optimistically.
      Parameters:
      zk - Zookeeper client
      originalPath - Zookeeper full path
      data - Zookeeper data
      acl - Acl of the zk path
      createMode - Create mode of zk path
      callback - Callback
      ctx - Context object
      See Also:
    • asyncDeleteFullPathOptimistic

      public static void asyncDeleteFullPathOptimistic(org.apache.zookeeper.ZooKeeper zk, String originalPath, int znodeVersion, org.apache.zookeeper.AsyncCallback.VoidCallback callback, String leafNodePath)
      Asynchronously deletes zookeeper path recursively and optimistically. This method is used for deleting the leaf nodes and its corresponding parents if they don't have anymore children after deleting the child node. For deleting the parent nodes it uses -1 as znodeversion. If it fails to delete the leafnode then it will callback with the received error code, but it fails to delete the parent node for whatsoever reason it stops proceeding further and it will callback with ok error code.
      Parameters:
      zk - Zookeeper client
      originalPath - Zookeeper full path
      znodeVersion - the expected node version of the leafnode
      callback - callback
      leafNodePath - for actual caller this leafNodePath should be same as the originalPath. But when it is called recursively leafNodePath remains the same, but the originalPath will be internal nodes.
    • createFullPathOptimistic

      public static void createFullPathOptimistic(org.apache.zookeeper.ZooKeeper zkc, String path, byte[] data, List<org.apache.zookeeper.data.ACL> acl, org.apache.zookeeper.CreateMode createMode) throws org.apache.zookeeper.KeeperException, InterruptedException
      Create zookeeper path recursively and optimistically. This method can throw any of the KeeperExceptions which can be thrown by ZooKeeper#create. KeeperException.NodeExistsException will only be thrown if the full path specified by _path_ already exists. The existence of any parent znodes is not an error condition.
      Parameters:
      zkc - - ZK instance
      path - - znode path
      data - - znode data
      acl - - Acl of the zk path
      createMode - - Create mode of zk path
      Throws:
      org.apache.zookeeper.KeeperException - if the server returns a non-zero error code, or invalid ACL
      InterruptedException - if the transaction is interrupted
    • deleteFullPathOptimistic

      public static void deleteFullPathOptimistic(org.apache.zookeeper.ZooKeeper zkc, String path, int znodeVersion) throws org.apache.zookeeper.KeeperException, InterruptedException
      Throws:
      org.apache.zookeeper.KeeperException
      InterruptedException
    • getChildrenInSingleNode

      public static List<String> getChildrenInSingleNode(org.apache.zookeeper.ZooKeeper zk, String node, long zkOpTimeoutMs) throws InterruptedException, IOException, org.apache.zookeeper.KeeperException.NoNodeException
      Sync get all children under single zk node.
      Parameters:
      zk - zookeeper client
      node - node path
      Returns:
      direct children
      Throws:
      InterruptedException
      IOException
      org.apache.zookeeper.KeeperException.NoNodeException
    • getChildrenInSingleNode

      public static void getChildrenInSingleNode(org.apache.zookeeper.ZooKeeper zk, String node, BookkeeperInternalCallbacks.GenericCallback<List<String>> cb)
      Async get direct children under single node.
      Parameters:
      zk - zookeeper client
      node - node path
      cb - callback function
    • getACLs

      public static List<org.apache.zookeeper.data.ACL> getACLs(AbstractConfiguration conf)
      Compute ZooKeeper ACLs using actual configuration.
      Parameters:
      conf - Bookie or BookKeeper configuration