public static byte[] blockUntilAvailable(final ZooKeeperWatcher zkw, final String znode, final long timeout) throws InterruptedException { if (timeout < 0) throw new IllegalArgumentException(); if (zkw == null) throw new IllegalArgumentException(); if (znode == null) throw new IllegalArgumentException(); byte[] data = null; boolean finished = false; final long endTime = System.currentTimeMillis() + timeout; while (!finished) { try { data = ZKUtil.getData(zkw, znode); } catch (KeeperException e) { LOG.warn("Unexpected exception handling blockUntilAvailable", e); } if (data == null && (System.currentTimeMillis() + HConstants.SOCKET_RETRY_WAIT_MS < endTime)) { Thread.sleep(HConstants.SOCKET_RETRY_WAIT_MS); } else { finished = true; } } return data; }
public static ClusterId readClusterIdZNode(ZooKeeperWatcher watcher) throws KeeperException { if (ZKUtil.checkExists(watcher, watcher.clusterIdZNode) != -1) { byte[] data = ZKUtil.getData(watcher, watcher.clusterIdZNode); if (data != null) { try { return ClusterId.parseFrom(data); } catch (DeserializationException e) { throw ZKUtil.convert(e); } } } return null; }
/** * Get master address. Use this instead of {@link #getMasterAddress()} if you * do not have an instance of this tracker in your context. * * @param zkw * ZooKeeperWatcher to use * @return ServerName stored in the the master address znode or null if no * znode present. * @throws org.apache.zookeeper.KeeperException * @throws java.io.IOException */ public static ServerName getMasterAddress(final ZooKeeperWatcher zkw) throws KeeperException, IOException { byte[] data = ZKUtil.getData(zkw, zkw.getMasterAddressZNode()); if (data == null) { throw new IOException( "Can't get master address from ZooKeeper; znode data == null"); } try { return ServerName.parseFrom(data); } catch (DeserializationException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } }
for (String s : backupMasterStrings) { try { byte[] bytes = ZKUtil.getData(this.zooKeeper, ZKUtil.joinZNode(this.zooKeeper.backupMasterAddressesZNode, s)); if (bytes != null) {
/** * @param zkw * @param child * @return Null or {@link org.apache.hadoop.hbase.zookeeper.ZKTable.TableState} found in znode. * @throws org.apache.zookeeper.KeeperException */ static ZooKeeperProtos.Table.State getTableState(final ZooKeeperWatcher zkw, final String child) throws KeeperException { String znode = ZKUtil.joinZNode(zkw.tableZNode, child); byte[] data = ZKUtil.getData(zkw, znode); if (data == null || data.length <= 0) return null; try { ZooKeeperProtos.Table.Builder builder = ZooKeeperProtos.Table .newBuilder(); ZooKeeperProtos.Table t = builder.mergeFrom(data, 0, data.length).build(); return t.getState(); } catch (InvalidProtocolBufferException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } } }