Class ZKUtils

java.lang.Object
com.mapr.baseutils.zookeeper.ZKUtils

public class ZKUtils extends Object
Class to take care of zookeeper handling utilities with "connection loss" and "session expiration" handling to do: getData check for znode existence getChildren
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final int
     
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.apache.zookeeper.data.Stat
    checkZKNodeForExistence(org.apache.zookeeper.ZooKeeper s_zk, String nodeName, org.apache.zookeeper.Watcher watcher, int retrials)
    Helper method to check for node existence in ZK with retrial logic in case of connection loss
    static byte[]
    getData(org.apache.zookeeper.ZooKeeper s_zk, String nodeName, org.apache.zookeeper.Watcher watcher, org.apache.zookeeper.data.Stat stat, int retrials)
    Helper method to get data from ZK with retrial logic in case of connection loss
    static List<String>
    getZkNodeChildren(org.apache.zookeeper.ZooKeeper s_zk, String nodeName, org.apache.zookeeper.Watcher watcher, int retrials)
    Helper method to get znode children from ZK with retrial logic in case of connection loss
    static void
    resetZookeeper(String zkAddresses, org.apache.zookeeper.ZooKeeper s_zk, org.apache.zookeeper.Watcher watcher)
    Method to reset ZK - in case of KeeperException.SessionExpiredException that exception should actually remove znode from ZK - at least for nodes, as they are going to be EPHEMERAL_SEQUENTIAL, so we need to make sure that even new "master" is in place because of this (worst case master got SessionExpiredException) we do not restart service on any other node if it is running on "this one" Using writelock to prevent "reading" threads to get data that is in inconsistent state - during reset

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ZKUtils

      public ZKUtils()
  • Method Details

    • getData

      public static byte[] getData(org.apache.zookeeper.ZooKeeper s_zk, String nodeName, org.apache.zookeeper.Watcher watcher, org.apache.zookeeper.data.Stat stat, int retrials) throws org.apache.zookeeper.KeeperException, InterruptedException, ZKClosedException
      Helper method to get data from ZK with retrial logic in case of connection loss
      Parameters:
      s_zk -
      nodeName -
      watcher -
      stat -
      retrials -
      Returns:
      Throws:
      org.apache.zookeeper.KeeperException
      InterruptedException
      ZKClosedException
    • checkZKNodeForExistence

      public static org.apache.zookeeper.data.Stat checkZKNodeForExistence(org.apache.zookeeper.ZooKeeper s_zk, String nodeName, org.apache.zookeeper.Watcher watcher, int retrials) throws org.apache.zookeeper.KeeperException, InterruptedException, ZKClosedException
      Helper method to check for node existence in ZK with retrial logic in case of connection loss
      Parameters:
      s_zk -
      nodeName -
      watcher -
      retrials -
      Returns:
      Throws:
      org.apache.zookeeper.KeeperException
      InterruptedException
      ZKClosedException
    • getZkNodeChildren

      public static List<String> getZkNodeChildren(org.apache.zookeeper.ZooKeeper s_zk, String nodeName, org.apache.zookeeper.Watcher watcher, int retrials) throws org.apache.zookeeper.KeeperException, InterruptedException, ZKClosedException
      Helper method to get znode children from ZK with retrial logic in case of connection loss
      Parameters:
      s_zk -
      nodeName -
      watcher -
      retrials -
      Returns:
      Throws:
      org.apache.zookeeper.KeeperException
      InterruptedException
      ZKClosedException
    • resetZookeeper

      public static void resetZookeeper(String zkAddresses, org.apache.zookeeper.ZooKeeper s_zk, org.apache.zookeeper.Watcher watcher) throws IOException
      Method to reset ZK - in case of KeeperException.SessionExpiredException that exception should actually remove znode from ZK - at least for nodes, as they are going to be EPHEMERAL_SEQUENTIAL, so we need to make sure that even new "master" is in place because of this (worst case master got SessionExpiredException) we do not restart service on any other node if it is running on "this one" Using writelock to prevent "reading" threads to get data that is in inconsistent state - during reset
      Parameters:
      s_zk -
      watcher -
      Throws:
      IOException