diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java index 359617a..7b64e0c 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java @@ -550,17 +550,20 @@ public class MetaTableLocator { final long timeout, Configuration conf) throws InterruptedException { int numReplicasConfigured = 1; + + List servers = new ArrayList(); + // Make the blocking call first so that we do the wait to know + // the znodes are all in place or timeout. + ServerName server = blockUntilAvailable(zkw, timeout); + if (server == null) return null; + servers.add(server); + try { List metaReplicaNodes = zkw.getMetaReplicaNodes(); numReplicasConfigured = metaReplicaNodes.size(); } catch (KeeperException e) { LOG.warn("Got ZK exception " + e); } - List servers = new ArrayList(numReplicasConfigured); - ServerName server = blockUntilAvailable(zkw, timeout); - if (server == null) return null; - servers.add(server); - for (int replicaId = 1; replicaId < numReplicasConfigured; replicaId++) { // return all replica locations for the meta servers.add(getMetaRegionLocation(zkw, replicaId)); diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java index f7d7e26..fc9388b 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java @@ -482,8 +482,10 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable { List childrenOfBaseNode = ZKUtil.listChildrenNoWatch(this, baseZNode); List metaReplicaNodes = new ArrayList(2); String pattern = conf.get("zookeeper.znode.metaserver","meta-region-server"); - for (String child : childrenOfBaseNode) { - if (child.startsWith(pattern)) metaReplicaNodes.add(child); + if (childrenOfBaseNode != null) { + for (String child : childrenOfBaseNode) { + if (child.startsWith(pattern)) metaReplicaNodes.add(child); + } } return metaReplicaNodes; }