org.apache.hadoop.hbase.zookeeper
Class ZooKeeperWatcher

java.lang.Object
  extended by org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher
All Implemented Interfaces:
Closeable, Abortable, org.apache.zookeeper.Watcher

@InterfaceAudience.Private
public class ZooKeeperWatcher
extends Object
implements org.apache.zookeeper.Watcher, Abortable, Closeable

Acts as the single ZooKeeper Watcher. One instance of this is instantiated for each Master, RegionServer, and client process.

This is the only class that implements Watcher. Other internal classes which need to be notified of ZooKeeper events must register with the local instance of this watcher via registerListener(org.apache.hadoop.hbase.zookeeper.ZooKeeperListener).

This class also holds and manages the connection to ZooKeeper. Code to deal with connection related events and exceptions are handled here.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.zookeeper.Watcher
org.apache.zookeeper.Watcher.Event
 
Field Summary
protected  Abortable abortable
           
 String assignmentZNode
           
 String backupMasterAddressesZNode
           
 String balancerZNode
           
 String baseZNode
           
 String clusterIdZNode
           
 String clusterStateZNode
           
static ArrayList<org.apache.zookeeper.data.ACL> CREATOR_ALL_AND_WORLD_READABLE
           
 String drainingZNode
           
 String metaServerZNode
           
static String namespaceZNode
           
 String recoveringRegionsZNode
           
 String rsZNode
           
 CountDownLatch saslLatch
           
 String splitLogZNode
           
 String tableLockZNode
           
 String tableZNode
           
 
Constructor Summary
ZooKeeperWatcher(org.apache.hadoop.conf.Configuration conf, String identifier, Abortable abortable)
          Instantiate a ZooKeeper connection and watcher.
ZooKeeperWatcher(org.apache.hadoop.conf.Configuration conf, String identifier, Abortable abortable, boolean canCreateBaseZNode)
          Instantiate a ZooKeeper connection and watcher.
 
Method Summary
 void abort(String why, Throwable e)
          Abort the server or client.
 void checkAndSetZNodeAcls()
          On master start, we check the znode ACLs under the root directory and set the ACLs properly if needed.
 void close()
          Close the connection to ZooKeeper.
 String getBaseZNode()
           
 org.apache.hadoop.conf.Configuration getConfiguration()
           
 List<ZooKeeperListener> getListeners()
          Get a copy of current registered listeners
 String getMasterAddressZNode()
           
 int getNumberOfListeners()
           
 String getQuorum()
          Get the quorum address of this instance.
 RecoverableZooKeeper getRecoverableZooKeeper()
          Get the connection to ZooKeeper.
 void interruptedException(InterruptedException ie)
          Handles InterruptedExceptions in client calls.
 boolean isAborted()
          Check if the server or client was aborted.
 boolean isClientReadable(String node)
          Returns whether the znode is supposed to be readable by the client and DOES NOT contain sensitive information (world readable).
 void keeperException(org.apache.zookeeper.KeeperException ke)
          Handles KeeperExceptions in client calls.
 String prefix(String str)
          Adds this instance's identifier as a prefix to the passed str
 void process(org.apache.zookeeper.WatchedEvent event)
          Method called from ZooKeeper for events and connection status.
 void reconnectAfterExpiration()
           
 void registerListener(ZooKeeperListener listener)
          Register the specified listener to receive ZooKeeper events.
 void registerListenerFirst(ZooKeeperListener listener)
          Register the specified listener to receive ZooKeeper events and add it as the first in the list of current listeners.
 void sync(String path)
          Forces a synchronization of this ZooKeeper client connection.
 String toString()
           
 void unregisterAllListeners()
          Clean all existing listeners
 void unregisterListener(ZooKeeperListener listener)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

abortable

protected Abortable abortable

saslLatch

public CountDownLatch saslLatch

baseZNode

public String baseZNode

metaServerZNode

public String metaServerZNode

rsZNode

public String rsZNode

drainingZNode

public String drainingZNode

backupMasterAddressesZNode

public String backupMasterAddressesZNode

clusterStateZNode

public String clusterStateZNode

assignmentZNode

public String assignmentZNode

tableZNode

public String tableZNode

clusterIdZNode

public String clusterIdZNode

splitLogZNode

public String splitLogZNode

balancerZNode

public String balancerZNode

tableLockZNode

public String tableLockZNode

recoveringRegionsZNode

public String recoveringRegionsZNode

namespaceZNode

public static String namespaceZNode

CREATOR_ALL_AND_WORLD_READABLE

public static final ArrayList<org.apache.zookeeper.data.ACL> CREATOR_ALL_AND_WORLD_READABLE
Constructor Detail

ZooKeeperWatcher

public ZooKeeperWatcher(org.apache.hadoop.conf.Configuration conf,
                        String identifier,
                        Abortable abortable)
                 throws ZooKeeperConnectionException,
                        IOException
Instantiate a ZooKeeper connection and watcher.

Parameters:
identifier - string that is passed to RecoverableZookeeper to be used as identifier for this instance. Use null for default.
Throws:
IOException
ZooKeeperConnectionException

ZooKeeperWatcher

public ZooKeeperWatcher(org.apache.hadoop.conf.Configuration conf,
                        String identifier,
                        Abortable abortable,
                        boolean canCreateBaseZNode)
                 throws IOException,
                        ZooKeeperConnectionException
Instantiate a ZooKeeper connection and watcher.

Parameters:
conf -
identifier - string that is passed to RecoverableZookeeper to be used as identifier for this instance. Use null for default.
abortable - Can be null if there is on error there is no host to abort: e.g. client context.
canCreateBaseZNode -
Throws:
IOException
ZooKeeperConnectionException
Method Detail

isClientReadable

public boolean isClientReadable(String node)
Returns whether the znode is supposed to be readable by the client and DOES NOT contain sensitive information (world readable).


checkAndSetZNodeAcls

public void checkAndSetZNodeAcls()
On master start, we check the znode ACLs under the root directory and set the ACLs properly if needed. If the cluster goes from an unsecure setup to a secure setup, this step is needed so that the existing znodes created with open permissions are now changed with restrictive perms.


toString

public String toString()
Overrides:
toString in class Object

prefix

public String prefix(String str)
Adds this instance's identifier as a prefix to the passed str

Parameters:
str - String to amend.
Returns:
A new string with this instance's identifier as prefix: e.g. if passed 'hello world', the returned string could be

registerListener

public void registerListener(ZooKeeperListener listener)
Register the specified listener to receive ZooKeeper events.

Parameters:
listener -

registerListenerFirst

public void registerListenerFirst(ZooKeeperListener listener)
Register the specified listener to receive ZooKeeper events and add it as the first in the list of current listeners.

Parameters:
listener -

unregisterListener

public void unregisterListener(ZooKeeperListener listener)

unregisterAllListeners

public void unregisterAllListeners()
Clean all existing listeners


getListeners

public List<ZooKeeperListener> getListeners()
Get a copy of current registered listeners


getNumberOfListeners

public int getNumberOfListeners()
Returns:
The number of currently registered listeners

getRecoverableZooKeeper

public RecoverableZooKeeper getRecoverableZooKeeper()
Get the connection to ZooKeeper.

Returns:
connection reference to zookeeper

reconnectAfterExpiration

public void reconnectAfterExpiration()
                              throws IOException,
                                     org.apache.zookeeper.KeeperException,
                                     InterruptedException
Throws:
IOException
org.apache.zookeeper.KeeperException
InterruptedException

getQuorum

public String getQuorum()
Get the quorum address of this instance.

Returns:
quorum string of this zookeeper connection instance

getBaseZNode

public String getBaseZNode()
Returns:
the base znode of this zookeeper connection instance.

process

public void process(org.apache.zookeeper.WatchedEvent event)
Method called from ZooKeeper for events and connection status.

Valid events are passed along to listeners. Connection status changes are dealt with locally.

Specified by:
process in interface org.apache.zookeeper.Watcher

sync

public void sync(String path)
          throws org.apache.zookeeper.KeeperException
Forces a synchronization of this ZooKeeper client connection.

Executing this method before running other methods will ensure that the subsequent operations are up-to-date and consistent as of the time that the sync is complete.

This is used for compareAndSwap type operations where we need to read the data of an existing node and delete or transition that node, utilizing the previously read version and data. We want to ensure that the version read is up-to-date from when we begin the operation.

Throws:
org.apache.zookeeper.KeeperException

keeperException

public void keeperException(org.apache.zookeeper.KeeperException ke)
                     throws org.apache.zookeeper.KeeperException
Handles KeeperExceptions in client calls.

This may be temporary but for now this gives one place to deal with these.

TODO: Currently this method rethrows the exception to let the caller handle

Parameters:
ke -
Throws:
org.apache.zookeeper.KeeperException

interruptedException

public void interruptedException(InterruptedException ie)
Handles InterruptedExceptions in client calls.

This may be temporary but for now this gives one place to deal with these.

TODO: Currently, this method does nothing. Is this ever expected to happen? Do we abort or can we let it run? Maybe this should be logged as WARN? It shouldn't happen?

Parameters:
ie -

close

public void close()
Close the connection to ZooKeeper.

Specified by:
close in interface Closeable
Throws:
InterruptedException

getConfiguration

public org.apache.hadoop.conf.Configuration getConfiguration()

abort

public void abort(String why,
                  Throwable e)
Description copied from interface: Abortable
Abort the server or client.

Specified by:
abort in interface Abortable
Parameters:
why - Why we're aborting.
e - Throwable that caused abort. Can be null.

isAborted

public boolean isAborted()
Description copied from interface: Abortable
Check if the server or client was aborted.

Specified by:
isAborted in interface Abortable
Returns:
true if the server or client was aborted, false otherwise

getMasterAddressZNode

public String getMasterAddressZNode()
Returns:
Path to the currently active master.


Copyright © 2007-2015 The Apache Software Foundation. All Rights Reserved.