diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKAsyncRegistry.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKAsyncRegistry.java index 34069d1a067..efeb887e5ed 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKAsyncRegistry.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKAsyncRegistry.java @@ -138,6 +138,9 @@ class ZKAsyncRegistry implements AsyncRegistry { private void getMetaRegionLocation(CompletableFuture future, List metaReplicaZNodes) { + if (metaReplicaZNodes.isEmpty()) { + future.completeExceptionally(new IOException("No meta znode available")); + } HRegionLocation[] locs = new HRegionLocation[metaReplicaZNodes.size()]; MutableInt remaining = new MutableInt(locs.length); for (String metaReplicaZNode : metaReplicaZNodes) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java index 00a92ab71bf..2b40b3bbad8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java @@ -18,10 +18,13 @@ package org.apache.hadoop.hbase.client; import static org.apache.hadoop.hbase.HConstants.META_REPLICAS_NUM; +import static org.hamcrest.CoreMatchers.instanceOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; import java.io.IOException; import java.util.concurrent.ExecutionException; @@ -114,4 +117,18 @@ public class TestZKAsyncRegistry { LOG.info("DONE!"); } } + + @Test + public void testNoMetaAvailable() throws InterruptedException { + Configuration conf = new Configuration(TEST_UTIL.getConfiguration()); + conf.set("zookeeper.znode.metaserver", "whatever"); + try (ZKAsyncRegistry registry = new ZKAsyncRegistry(conf)) { + try { + registry.getMetaRegionLocation().get(); + fail("Should have failed since we set an incorrect meta znode prefix"); + } catch (ExecutionException e) { + assertThat(e.getCause(), instanceOf(IOException.class)); + } + } + } }