HBASE-20822 TestAsyncNonMetaRegionLocator is flakey
This commit is contained in:
parent
6df7f2346c
commit
b5222f88b2
|
@ -334,14 +334,15 @@ class AsyncNonMetaRegionLocator {
|
||||||
|
|
||||||
private HRegionLocation locateRowBeforeInCache(TableCache tableCache, TableName tableName,
|
private HRegionLocation locateRowBeforeInCache(TableCache tableCache, TableName tableName,
|
||||||
byte[] row) {
|
byte[] row) {
|
||||||
|
boolean isEmptyStopRow = isEmptyStopRow(row);
|
||||||
Map.Entry<byte[], HRegionLocation> entry =
|
Map.Entry<byte[], HRegionLocation> entry =
|
||||||
isEmptyStopRow(row) ? tableCache.cache.lastEntry() : tableCache.cache.lowerEntry(row);
|
isEmptyStopRow ? tableCache.cache.lastEntry() : tableCache.cache.lowerEntry(row);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
HRegionLocation loc = entry.getValue();
|
HRegionLocation loc = entry.getValue();
|
||||||
if (isEmptyStopRow(loc.getRegion().getEndKey()) ||
|
if (isEmptyStopRow(loc.getRegion().getEndKey()) ||
|
||||||
Bytes.compareTo(loc.getRegion().getEndKey(), row) >= 0) {
|
(!isEmptyStopRow && Bytes.compareTo(loc.getRegion().getEndKey(), row) >= 0)) {
|
||||||
if (LOG.isTraceEnabled()) {
|
if (LOG.isTraceEnabled()) {
|
||||||
LOG.trace("Found " + loc + " in cache for '" + tableName + "', row='" +
|
LOG.trace("Found " + loc + " in cache for '" + tableName + "', row='" +
|
||||||
Bytes.toStringBinary(row) + "', locateType=" + RegionLocateType.BEFORE);
|
Bytes.toStringBinary(row) + "', locateType=" + RegionLocateType.BEFORE);
|
||||||
|
|
|
@ -36,7 +36,6 @@ import java.util.stream.IntStream;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
import org.apache.hadoop.hbase.HRegionInfo;
|
|
||||||
import org.apache.hadoop.hbase.HRegionLocation;
|
import org.apache.hadoop.hbase.HRegionLocation;
|
||||||
import org.apache.hadoop.hbase.NotServingRegionException;
|
import org.apache.hadoop.hbase.NotServingRegionException;
|
||||||
import org.apache.hadoop.hbase.ServerName;
|
import org.apache.hadoop.hbase.ServerName;
|
||||||
|
@ -76,7 +75,7 @@ public class TestAsyncNonMetaRegionLocator {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
TEST_UTIL.startMiniCluster(3);
|
TEST_UTIL.startMiniCluster(3);
|
||||||
TEST_UTIL.getAdmin().setBalancerRunning(false, true);
|
TEST_UTIL.getAdmin().balancerSwitch(false, true);
|
||||||
AsyncRegistry registry = AsyncRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
|
AsyncRegistry registry = AsyncRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
|
||||||
CONN = new AsyncConnectionImpl(TEST_UTIL.getConfiguration(), registry,
|
CONN = new AsyncConnectionImpl(TEST_UTIL.getConfiguration(), registry,
|
||||||
registry.getClusterId().get(), User.getCurrent());
|
registry.getClusterId().get(), User.getCurrent());
|
||||||
|
@ -136,7 +135,7 @@ public class TestAsyncNonMetaRegionLocator {
|
||||||
|
|
||||||
private void assertLocEquals(byte[] startKey, byte[] endKey, ServerName serverName,
|
private void assertLocEquals(byte[] startKey, byte[] endKey, ServerName serverName,
|
||||||
HRegionLocation loc) {
|
HRegionLocation loc) {
|
||||||
HRegionInfo info = loc.getRegionInfo();
|
RegionInfo info = loc.getRegion();
|
||||||
assertEquals(TABLE_NAME, info.getTable());
|
assertEquals(TABLE_NAME, info.getTable());
|
||||||
assertArrayEquals(startKey, info.getStartKey());
|
assertArrayEquals(startKey, info.getStartKey());
|
||||||
assertArrayEquals(endKey, info.getEndKey());
|
assertArrayEquals(endKey, info.getEndKey());
|
||||||
|
@ -240,7 +239,7 @@ public class TestAsyncNonMetaRegionLocator {
|
||||||
.map(t -> t.getRegionServer().getServerName()).filter(sn -> !sn.equals(serverName))
|
.map(t -> t.getRegionServer().getServerName()).filter(sn -> !sn.equals(serverName))
|
||||||
.findAny().get();
|
.findAny().get();
|
||||||
|
|
||||||
TEST_UTIL.getAdmin().move(Bytes.toBytes(loc.getRegionInfo().getEncodedName()),
|
TEST_UTIL.getAdmin().move(Bytes.toBytes(loc.getRegion().getEncodedName()),
|
||||||
Bytes.toBytes(newServerName.getServerName()));
|
Bytes.toBytes(newServerName.getServerName()));
|
||||||
while (!TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName()
|
while (!TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName()
|
||||||
.equals(newServerName)) {
|
.equals(newServerName)) {
|
||||||
|
@ -316,7 +315,7 @@ public class TestAsyncNonMetaRegionLocator {
|
||||||
.map(t -> t.getRegionServer().getServerName()).filter(sn -> !sn.equals(serverName))
|
.map(t -> t.getRegionServer().getServerName()).filter(sn -> !sn.equals(serverName))
|
||||||
.findAny().get();
|
.findAny().get();
|
||||||
Admin admin = TEST_UTIL.getAdmin();
|
Admin admin = TEST_UTIL.getAdmin();
|
||||||
HRegionInfo region = admin.getTableRegions(TABLE_NAME).stream().findAny().get();
|
RegionInfo region = admin.getRegions(TABLE_NAME).stream().findAny().get();
|
||||||
admin.move(region.getEncodedNameAsBytes(), Bytes.toBytes(newServerName.getServerName()));
|
admin.move(region.getEncodedNameAsBytes(), Bytes.toBytes(newServerName.getServerName()));
|
||||||
TEST_UTIL.waitFor(30000, new ExplainingPredicate<Exception>() {
|
TEST_UTIL.waitFor(30000, new ExplainingPredicate<Exception>() {
|
||||||
|
|
||||||
|
@ -346,4 +345,16 @@ public class TestAsyncNonMetaRegionLocator {
|
||||||
LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get());
|
LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Testcase for HBASE-20822
|
||||||
|
@Test
|
||||||
|
public void testLocateBeforeLastRegion()
|
||||||
|
throws IOException, InterruptedException, ExecutionException {
|
||||||
|
createMultiRegionTable();
|
||||||
|
LOCATOR.getRegionLocation(TABLE_NAME, SPLIT_KEYS[0], RegionLocateType.CURRENT, false).join();
|
||||||
|
HRegionLocation loc =
|
||||||
|
LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_END_ROW, RegionLocateType.BEFORE, false).get();
|
||||||
|
// should locate to the last region
|
||||||
|
assertArrayEquals(loc.getRegion().getEndKey(), EMPTY_END_ROW);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue