List of usage examples for org.apache.zookeeper KeeperException getMessage
@Override
public String getMessage()
From source file:org.apache.hadoop.hbase.client.ConnectionImplementation.java
License:Apache License
private void checkIfBaseNodeAvailable(ZooKeeperWatcher zkw) throws MasterNotRunningException { String errorMsg;//ww w.ja v a2s.c om try { if (ZKUtil.checkExists(zkw, zkw.baseZNode) == -1) { errorMsg = "The node " + zkw.baseZNode + " is not in ZooKeeper. " + "It should have been written by the master. " + "Check the value configured in 'zookeeper.znode.parent'. " + "There could be a mismatch with the one configured in the master."; LOG.error(errorMsg); throw new MasterNotRunningException(errorMsg); } } catch (KeeperException e) { errorMsg = "Can't get connection to ZooKeeper: " + e.getMessage(); LOG.error(errorMsg); throw new MasterNotRunningException(errorMsg, e); } }
From source file:org.apache.hadoop.hbase.master.zksyncer.ClientZKSyncer.java
License:Apache License
/** * Set data for client ZK and retry until succeed. Be very careful to prevent dead loop when * modifying this method/* www. jav a 2 s . com*/ * @param node the znode to set on client ZK * @param data the data to set to client ZK * @throws InterruptedException if the thread is interrupted during process */ private final void setDataForClientZkUntilSuccess(String node, byte[] data) throws InterruptedException { while (!server.isStopped()) { try { LOG.debug("Set data for remote " + node + ", client zk wather: " + clientZkWatcher); ZKUtil.setData(clientZkWatcher, node, data); break; } catch (KeeperException.NoNodeException nne) { // Node doesn't exist, create it and set value try { ZKUtil.createNodeIfNotExistsNoWatch(clientZkWatcher, node, data, CreateMode.PERSISTENT); break; } catch (KeeperException.ConnectionLossException | KeeperException.SessionExpiredException ee) { reconnectAfterExpiration(); } catch (KeeperException e) { LOG.warn( "Failed to create znode " + node + " due to: " + e.getMessage() + ", will retry later"); } } catch (KeeperException.ConnectionLossException | KeeperException.SessionExpiredException ee) { reconnectAfterExpiration(); } catch (KeeperException e) { LOG.debug("Failed to set data to client ZK, will retry later", e); } Threads.sleep(HConstants.SOCKET_RETRY_WAIT_MS); } }
From source file:org.apache.hadoop.hbase.replication.ReplicationQueuesZKImpl.java
License:Apache License
/** * Try to set a lock in another region server's znode. * @param znode the server names of the other server * @return true if the lock was acquired, false in every other cases */// w w w .ja v a2 s.c o m private boolean lockOtherRS(String znode) { try { String parent = ZKUtil.joinZNode(this.queuesZNode, znode); if (parent.equals(this.myQueuesZnode)) { LOG.warn("Won't lock because this is us, we're dead!"); return false; } String p = ZKUtil.joinZNode(parent, RS_LOCK_ZNODE); ZKUtil.createAndWatch(this.zookeeper, p, lockToByteArray(this.myQueuesZnode)); } catch (KeeperException e) { // This exception will pop up if the znode under which we're trying to // create the lock is already deleted by another region server, meaning // that the transfer already occurred. // NoNode => transfer is done and znodes are already deleted // NodeExists => lock znode already created by another RS if (e instanceof KeeperException.NoNodeException || e instanceof KeeperException.NodeExistsException) { LOG.info("Won't transfer the queue," + " another RS took care of it because of: " + e.getMessage()); } else { LOG.info("Failed lock other rs", e); } return false; } return true; }
From source file:org.apache.hadoop.hbase.replication.ReplicationZookeeper.java
License:Apache License
/** * Try to set a lock in another server's znode. * @param znode the server names of the other server * @return true if the lock was acquired, false in every other cases *//*ww w. j a v a 2 s. c o m*/ public boolean lockOtherRS(String znode) { try { String parent = ZKUtil.joinZNode(this.rsZNode, znode); if (parent.equals(rsServerNameZnode)) { LOG.warn("Won't lock because this is us, we're dead!"); return false; } String p = ZKUtil.joinZNode(parent, RS_LOCK_ZNODE); ZKUtil.createAndWatch(this.zookeeper, p, Bytes.toBytes(rsServerNameZnode)); } catch (KeeperException e) { // This exception will pop up if the znode under which we're trying to // create the lock is already deleted by another region server, meaning // that the transfer already occurred. // NoNode => transfer is done and znodes are already deleted // NodeExists => lock znode already created by another RS if (e instanceof KeeperException.NoNodeException || e instanceof KeeperException.NodeExistsException) { LOG.info("Won't transfer the queue," + " another RS took care of it because of: " + e.getMessage()); } else { LOG.info("Failed lock other rs", e); } return false; } return true; }
From source file:org.apache.hadoop.hbase.zookeeper.ZKLeaderManager.java
License:Apache License
public void start() { try {/* w w w . j av a 2 s . c om*/ watcher.registerListener(this); String parent = ZKUtil.getParent(leaderZNode); if (ZKUtil.checkExists(watcher, parent) < 0) { ZKUtil.createWithParents(watcher, parent); } } catch (KeeperException ke) { watcher.abort("Unhandled zk exception when starting", ke); candidate.stop("Unhandled zk exception starting up: " + ke.getMessage()); } }
From source file:org.apache.hadoop.hbase.zookeeper.ZKLeaderManager.java
License:Apache License
private void handleLeaderChange() { try {// w w w .j a va 2 s .co m synchronized (leaderExists) { if (ZKUtil.watchAndCheckExists(watcher, leaderZNode)) { LOG.info("Found new leader for znode: " + leaderZNode); leaderExists.set(true); } else { LOG.info("Leader change, but no new leader found"); leaderExists.set(false); leaderExists.notifyAll(); } } } catch (KeeperException ke) { watcher.abort("ZooKeeper error checking for leader znode", ke); candidate.stop("ZooKeeper error checking for leader: " + ke.getMessage()); } }
From source file:org.apache.hadoop.hbase.zookeeper.ZKLeaderManager.java
License:Apache License
/** * Blocks until this instance has claimed the leader ZNode in ZooKeeper *///from w w w . j av a2 s . c om public void waitToBecomeLeader() { while (!candidate.isStopped()) { try { if (ZKUtil.createEphemeralNodeAndWatch(watcher, leaderZNode, nodeId)) { // claimed the leader znode leaderExists.set(true); if (LOG.isDebugEnabled()) { LOG.debug("Claimed the leader znode as '" + Bytes.toStringBinary(nodeId) + "'"); } return; } // if claiming the node failed, there should be another existing node byte[] currentId = ZKUtil.getDataAndWatch(watcher, leaderZNode); if (currentId != null && Bytes.equals(currentId, nodeId)) { // claimed with our ID, but we didn't grab it, possibly restarted? LOG.info("Found existing leader with our ID (" + Bytes.toStringBinary(nodeId) + "), removing"); ZKUtil.deleteNode(watcher, leaderZNode); leaderExists.set(false); } else { LOG.info("Found existing leader with ID: " + Bytes.toStringBinary(nodeId)); leaderExists.set(true); } } catch (KeeperException ke) { watcher.abort("Unexpected error from ZK, stopping candidate", ke); candidate.stop("Unexpected error from ZK: " + ke.getMessage()); return; } // wait for next chance synchronized (leaderExists) { while (leaderExists.get() && !candidate.isStopped()) { try { leaderExists.wait(); } catch (InterruptedException ie) { LOG.debug("Interrupted waiting on leader", ie); } } } } }
From source file:org.apache.hadoop.hbase.zookeeper.ZKLeaderManager.java
License:Apache License
/** * Removes the leader znode, if it is currently claimed by this instance. *///from ww w.ja va 2 s . c om public void stepDownAsLeader() { try { synchronized (leaderExists) { if (!leaderExists.get()) { return; } byte[] leaderId = ZKUtil.getData(watcher, leaderZNode); if (leaderId != null && Bytes.equals(nodeId, leaderId)) { LOG.info("Stepping down as leader"); ZKUtil.deleteNodeFailSilent(watcher, leaderZNode); leaderExists.set(false); } else { LOG.info("Not current leader, no need to step down"); } } } catch (KeeperException ke) { watcher.abort("Unhandled zookeeper exception removing leader node", ke); candidate.stop("Unhandled zookeeper exception removing leader node: " + ke.getMessage()); } catch (InterruptedException e) { watcher.abort("Unhandled zookeeper exception removing leader node", e); candidate.stop("Unhandled zookeeper exception removing leader node: " + e.getMessage()); } }
From source file:org.apache.hadoop.hbase.zookeeper.ZKUtil.java
License:Apache License
/** @return String dump of everything in ZooKeeper. */ public static String dump(ZooKeeperWatcher zkw) { StringBuilder sb = new StringBuilder(); try {/* ww w. j a va 2 s . c o m*/ sb.append("HBase is rooted at ").append(zkw.baseZNode); sb.append("\nActive master address: "); try { sb.append(MasterAddressTracker.getMasterAddress(zkw)); } catch (IOException e) { sb.append("<<FAILED LOOKUP: " + e.getMessage() + ">>"); } sb.append("\nBackup master addresses:"); for (String child : listChildrenNoWatch(zkw, zkw.backupMasterAddressesZNode)) { sb.append("\n ").append(child); } sb.append("\nRegion server holding hbase:meta: " + new MetaTableLocator().getMetaRegionLocation(zkw)); Configuration conf = HBaseConfiguration.create(); int numMetaReplicas = conf.getInt(HConstants.META_REPLICAS_NUM, HConstants.DEFAULT_META_REPLICA_NUM); for (int i = 1; i < numMetaReplicas; i++) { sb.append("\nRegion server holding hbase:meta, replicaId " + i + " " + new MetaTableLocator().getMetaRegionLocation(zkw, i)); } sb.append("\nRegion servers:"); for (String child : listChildrenNoWatch(zkw, zkw.rsZNode)) { sb.append("\n ").append(child); } try { getReplicationZnodesDump(zkw, sb); } catch (KeeperException ke) { LOG.warn("Couldn't get the replication znode dump", ke); } sb.append("\nQuorum Server Statistics:"); String[] servers = zkw.getQuorum().split(","); for (String server : servers) { sb.append("\n ").append(server); try { String[] stat = getServerStats(server, ZKUtil.zkDumpConnectionTimeOut); if (stat == null) { sb.append("[Error] invalid quorum server: " + server); break; } for (String s : stat) { sb.append("\n ").append(s); } } catch (Exception e) { sb.append("\n ERROR: ").append(e.getMessage()); } } } catch (KeeperException ke) { sb.append("\nFATAL ZooKeeper Exception!\n"); sb.append("\n" + ke.getMessage()); } return sb.toString(); }
From source file:org.apache.hadoop.hbase.zookeeper.ZooKeeperWrapper.java
License:Apache License
public HServerInfo readAddress(String znode, Watcher watcher) { try {/*from w ww.ja v a 2 s.c o m*/ LOG.debug("<" + instanceName + ">" + "Trying to read " + znode); return readAddressOrThrow(znode, watcher); } catch (KeeperException e) { LOG.debug("<" + instanceName + ">" + "Failed to read " + e.getMessage()); return null; } }