HBASE-16732 Avoid possible NPE in MetaTableLocator
This commit is contained in:
parent
bf3c928b74
commit
3757da643d
|
@ -550,17 +550,20 @@ public class MetaTableLocator {
|
|||
final long timeout, Configuration conf)
|
||||
throws InterruptedException {
|
||||
int numReplicasConfigured = 1;
|
||||
|
||||
List<ServerName> servers = new ArrayList<ServerName>();
|
||||
// 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<String> metaReplicaNodes = zkw.getMetaReplicaNodes();
|
||||
numReplicasConfigured = metaReplicaNodes.size();
|
||||
} catch (KeeperException e) {
|
||||
LOG.warn("Got ZK exception " + e);
|
||||
}
|
||||
List<ServerName> servers = new ArrayList<ServerName>(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));
|
||||
|
|
|
@ -481,9 +481,11 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable {
|
|||
public List<String> getMetaReplicaNodes() throws KeeperException {
|
||||
List<String> childrenOfBaseNode = ZKUtil.listChildrenNoWatch(this, baseZNode);
|
||||
List<String> metaReplicaNodes = new ArrayList<String>(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) {
|
||||
String pattern = conf.get("zookeeper.znode.metaserver","meta-region-server");
|
||||
for (String child : childrenOfBaseNode) {
|
||||
if (child.startsWith(pattern)) metaReplicaNodes.add(child);
|
||||
}
|
||||
}
|
||||
return metaReplicaNodes;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue