@InterfaceAudience.Private public class ZooKeeperWatcher extends Object implements org.apache.zookeeper.Watcher, Abortable, Closeable
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.
Modifier and Type | Field and Description |
---|---|
protected Abortable |
abortable |
private boolean |
aborted |
String |
assignmentZNode |
String |
backupMasterAddressesZNode |
String |
balancerZNode |
String |
baseZNode |
String |
clusterIdZNode |
String |
clusterStateZNode |
private org.apache.hadoop.conf.Configuration |
conf |
private Exception |
constructorCaller |
static ArrayList<org.apache.zookeeper.data.ACL> |
CREATOR_ALL_AND_WORLD_READABLE |
String |
drainingZNode |
private String |
identifier |
private List<ZooKeeperListener> |
listeners |
private static org.apache.commons.logging.Log |
LOG |
private String |
masterAddressZNode |
static String |
META_ZNODE_PREFIX |
private Map<Integer,String> |
metaReplicaZnodes |
private static Pattern |
NAME_PATTERN |
static String |
namespaceZNode |
private String |
prefix |
private String |
quorum |
private RecoverableZooKeeper |
recoverableZooKeeper |
String |
recoveringRegionsZNode |
private String |
regionNormalizerZNode |
String |
rsZNode |
CountDownLatch |
saslLatch |
String |
splitLogZNode |
String |
tableLockZNode |
String |
tableZNode |
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
abort(String why,
Throwable e)
Abort the server or client.
|
private boolean |
checkACLForSuperUsers(String[] superUsers,
List<org.apache.zookeeper.data.ACL> acls) |
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.
|
private void |
connectionEvent(org.apache.zookeeper.WatchedEvent event)
Called when there is a connection-related event via the Watcher callback.
|
private void |
createBaseZNodes() |
String |
getBaseZNode() |
org.apache.hadoop.conf.Configuration |
getConfiguration() |
List<ZooKeeperListener> |
getListeners()
Get a copy of current registered listeners
|
String |
getMasterAddressZNode() |
int |
getMetaReplicaIdFromZnode(String znode)
Parse the meta replicaId from the passed znode
|
List<String> |
getMetaReplicaNodes()
Get the znodes corresponding to the meta replicas from ZK
|
int |
getNumberOfListeners() |
String |
getQuorum()
Get the quorum address of this instance.
|
RecoverableZooKeeper |
getRecoverableZooKeeper()
Get the connection to ZooKeeper.
|
String |
getRegionNormalizerZNode() |
String |
getZNodeForReplica(int replicaId)
Get the znode string corresponding to a replicaId
|
void |
interruptedException(InterruptedException ie)
Handles InterruptedExceptions in client calls.
|
void |
interruptedExceptionNoThrow(InterruptedException ie,
boolean throwLater)
Log the InterruptedException and interrupt current thread
|
boolean |
isAborted()
Check if the server or client was aborted.
|
boolean |
isAnyMetaReplicaZnode(String node)
Is the znode of any meta replica
|
private boolean |
isBaseZnodeAclSetup(List<org.apache.zookeeper.data.ACL> acls)
Checks whether the ACLs returned from the base znode (/hbase) is set for secure setup.
|
boolean |
isClientReadable(String node)
Returns whether the znode is supposed to be readable by the client
and DOES NOT contain sensitive information (world readable).
|
boolean |
isDefaultMetaReplicaZnode(String node)
Is it the default meta replica's znode
|
static boolean |
isSuperUserId(String[] superUsers,
org.apache.zookeeper.data.Id id) |
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.
|
private void |
setNodeNames(org.apache.hadoop.conf.Configuration conf)
Set the local variable node names using the specified configuration.
|
private void |
setZnodeAclsRecursive(String znode)
Set the znode perms recursively.
|
void |
sync(String path)
Forces a synchronization of this ZooKeeper client connection.
|
String |
toString() |
void |
unregisterAllListeners()
Clean all existing listeners
|
void |
unregisterListener(ZooKeeperListener listener) |
private static final org.apache.commons.logging.Log LOG
private String prefix
private String identifier
private String quorum
private RecoverableZooKeeper recoverableZooKeeper
protected Abortable abortable
private boolean aborted
private final List<ZooKeeperListener> listeners
public CountDownLatch saslLatch
public String baseZNode
public String rsZNode
public String drainingZNode
private String masterAddressZNode
public String backupMasterAddressesZNode
public String clusterStateZNode
public String assignmentZNode
public String tableZNode
public String clusterIdZNode
public String splitLogZNode
public String balancerZNode
private String regionNormalizerZNode
public String tableLockZNode
public String recoveringRegionsZNode
public static String namespaceZNode
public static final ArrayList<org.apache.zookeeper.data.ACL> CREATOR_ALL_AND_WORLD_READABLE
public static final String META_ZNODE_PREFIX
private final org.apache.hadoop.conf.Configuration conf
private final Exception constructorCaller
private static final Pattern NAME_PATTERN
public ZooKeeperWatcher(org.apache.hadoop.conf.Configuration conf, String identifier, Abortable abortable) throws ZooKeeperConnectionException, IOException
identifier
- string that is passed to RecoverableZookeeper to be used as
identifier for this instance. Use null for default.IOException
ZooKeeperConnectionException
public ZooKeeperWatcher(org.apache.hadoop.conf.Configuration conf, String identifier, Abortable abortable, boolean canCreateBaseZNode) throws IOException, ZooKeeperConnectionException
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
- IOException
ZooKeeperConnectionException
private void createBaseZNodes() throws ZooKeeperConnectionException
ZooKeeperConnectionException
public boolean isClientReadable(String node)
public void checkAndSetZNodeAcls()
private void setZnodeAclsRecursive(String znode) throws org.apache.zookeeper.KeeperException, InterruptedException
znode
- org.apache.zookeeper.KeeperException
InterruptedException
private boolean isBaseZnodeAclSetup(List<org.apache.zookeeper.data.ACL> acls) throws IOException
acls
- acls from zookeeperIOException
private boolean checkACLForSuperUsers(String[] superUsers, List<org.apache.zookeeper.data.ACL> acls)
public static boolean isSuperUserId(String[] superUsers, org.apache.zookeeper.data.Id id)
public String prefix(String str)
str
str
- String to amend.private void setNodeNames(org.apache.hadoop.conf.Configuration conf)
public boolean isAnyMetaReplicaZnode(String node)
node
- public boolean isDefaultMetaReplicaZnode(String node)
node
- public List<String> getMetaReplicaNodes() throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperException
public String getZNodeForReplica(int replicaId)
replicaId
- public int getMetaReplicaIdFromZnode(String znode)
znode
- public void registerListener(ZooKeeperListener listener)
listener
- public void registerListenerFirst(ZooKeeperListener listener)
listener
- public void unregisterListener(ZooKeeperListener listener)
public void unregisterAllListeners()
public List<ZooKeeperListener> getListeners()
public int getNumberOfListeners()
public RecoverableZooKeeper getRecoverableZooKeeper()
public void reconnectAfterExpiration() throws IOException, org.apache.zookeeper.KeeperException, InterruptedException
IOException
org.apache.zookeeper.KeeperException
InterruptedException
public String getQuorum()
public String getBaseZNode()
public void process(org.apache.zookeeper.WatchedEvent event)
Valid events are passed along to listeners. Connection status changes are dealt with locally.
process
in interface org.apache.zookeeper.Watcher
private void connectionEvent(org.apache.zookeeper.WatchedEvent event)
If Disconnected or Expired, this should shutdown the cluster. But, since we send a KeeperException.SessionExpiredException along with the abort call, it's possible for the Abortable to catch it and try to create a new session with ZooKeeper. This is what the client does in HCM.
event
- public void sync(String path) throws org.apache.zookeeper.KeeperException
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.
org.apache.zookeeper.KeeperException
public void keeperException(org.apache.zookeeper.KeeperException ke) throws org.apache.zookeeper.KeeperException
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
ke
- org.apache.zookeeper.KeeperException
public void interruptedException(InterruptedException ie) throws org.apache.zookeeper.KeeperException
ie
- the InterruptedException instance thrownorg.apache.zookeeper.KeeperException
- the exception to throw, transformed from the InterruptedExceptionpublic void interruptedExceptionNoThrow(InterruptedException ie, boolean throwLater)
ie
- The IterruptedException to logthrowLater
- Whether we will throw the exception latterpublic void close()
close
in interface Closeable
close
in interface AutoCloseable
public org.apache.hadoop.conf.Configuration getConfiguration()
public void abort(String why, Throwable e)
Abortable
public boolean isAborted()
Abortable
public String getMasterAddressZNode()
public String getRegionNormalizerZNode()
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.