HBASE-21658 Addendum fix infinite wait when there are no meta locations yet

This commit is contained in:
zhangduo 2019-05-13 21:20:50 +08:00
parent 0797243365
commit 0b8493f886
2 changed files with 20 additions and 0 deletions

View File

@ -138,6 +138,9 @@ class ZKAsyncRegistry implements AsyncRegistry {
private void getMetaRegionLocation(CompletableFuture<RegionLocations> future,
List<String> 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) {

View File

@ -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;
@ -115,4 +118,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));
}
}
}
}