Skip to content

Commit 0b8493f

Browse files
committed
HBASE-21658 Addendum fix infinite wait when there are no meta locations yet
1 parent 0797243 commit 0b8493f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKAsyncRegistry.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ private Pair<RegionState.State, ServerName> getStateAndServerName(
138138

139139
private void getMetaRegionLocation(CompletableFuture<RegionLocations> future,
140140
List<String> metaReplicaZNodes) {
141+
if (metaReplicaZNodes.isEmpty()) {
142+
future.completeExceptionally(new IOException("No meta znode available"));
143+
}
141144
HRegionLocation[] locs = new HRegionLocation[metaReplicaZNodes.size()];
142145
MutableInt remaining = new MutableInt(locs.length);
143146
for (String metaReplicaZNode : metaReplicaZNodes) {

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
package org.apache.hadoop.hbase.client;
1919

2020
import static org.apache.hadoop.hbase.HConstants.META_REPLICAS_NUM;
21+
import static org.hamcrest.CoreMatchers.instanceOf;
2122
import static org.junit.Assert.assertEquals;
2223
import static org.junit.Assert.assertNotEquals;
2324
import static org.junit.Assert.assertNotNull;
2425
import static org.junit.Assert.assertNotSame;
26+
import static org.junit.Assert.assertThat;
27+
import static org.junit.Assert.fail;
2528

2629
import java.io.IOException;
2730
import java.util.concurrent.ExecutionException;
@@ -115,4 +118,18 @@ public void testIndependentZKConnections() throws IOException {
115118
LOG.info("DONE!");
116119
}
117120
}
121+
122+
@Test
123+
public void testNoMetaAvailable() throws InterruptedException {
124+
Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
125+
conf.set("zookeeper.znode.metaserver", "whatever");
126+
try (ZKAsyncRegistry registry = new ZKAsyncRegistry(conf)) {
127+
try {
128+
registry.getMetaRegionLocation().get();
129+
fail("Should have failed since we set an incorrect meta znode prefix");
130+
} catch (ExecutionException e) {
131+
assertThat(e.getCause(), instanceOf(IOException.class));
132+
}
133+
}
134+
}
118135
}

0 commit comments

Comments
 (0)