HBASE-21859 Add clearRegionLocationCache method for AsyncConnection

Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
zhangduo 2019-02-08 15:29:11 +08:00 committed by Duo Zhang
parent 9ef6bc4323
commit f1e5999ad2
5 changed files with 30 additions and 0 deletions

View File

@ -52,6 +52,16 @@ public interface AsyncConnection extends Closeable {
*/
AsyncTableRegionLocator getRegionLocator(TableName tableName);
/**
* Clear all the entries in the region location cache, for all the tables.
* <p/>
* If you only want to clear the cache for a specific table, use
* {@link AsyncTableRegionLocator#clearRegionLocationCache()}.
* <p/>
* This may cause performance issue so use it with caution.
*/
void clearRegionLocationCache();
/**
* Retrieve an {@link AsyncTable} implementation for accessing a table.
* <p>

View File

@ -353,4 +353,9 @@ class AsyncConnectionImpl implements AsyncConnection {
return new HBaseHbck(MasterProtos.HbckService.newBlockingStub(
rpcClient.createBlockingRpcChannel(masterServer, user, rpcTimeout)), rpcControllerFactory);
}
@Override
public void clearRegionLocationCache() {
locator.clearCache();
}
}

View File

@ -569,6 +569,10 @@ class AsyncNonMetaRegionLocator {
}
}
void clearCache() {
cache.clear();
}
// only used for testing whether we have cached the location for a region.
@VisibleForTesting
RegionLocations getRegionLocationInCache(TableName tableName, byte[] row) {

View File

@ -159,4 +159,9 @@ class AsyncRegionLocator {
nonMetaRegionLocator.clearCache(tableName);
}
}
void clearCache() {
metaRegionLocator.clearCache();
nonMetaRegionLocator.clearCache();
}
}

View File

@ -49,6 +49,7 @@ import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Threads;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
@ -109,6 +110,11 @@ public class TestAsyncRegionLocator {
TEST_UTIL.shutdownMiniCluster();
}
@After
public void tearDownAfterTest() {
LOCATOR.clearCache();
}
@Test
public void testTimeout() throws InterruptedException, ExecutionException {
SLEEP_MS = 1000;