From 401be133d8f0169273e872cdb27f4114f8ce8157 Mon Sep 17 00:00:00 2001 From: zhangduo Date: Mon, 13 May 2019 21:20:50 +0800 Subject: [PATCH] HBASE-21658 Addendum fix infinite wait when there are no meta locations yet --- .../hadoop/hbase/client/ZKAsyncRegistry.java | 3 +++ .../hbase/client/TestZKAsyncRegistry.java | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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 34069d1a06..efeb887e5e 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 a4441b81d9..1543b4dced 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 @@ -21,7 +21,8 @@ import static org.apache.hadoop.hbase.HConstants.META_REPLICAS_NUM; 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.*; +import static org.hamcrest.CoreMatchers.*; import java.io.IOException; import java.util.concurrent.ExecutionException; @@ -115,4 +116,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)); + } + } + } } -- 2.17.1