HBASE-26942 cache region locations when getAllRegionLocations (#4364)
Co-authored-by: huiruan <huiruan@tencent.com> Signed-off-by: Duo Zhang <zhangduo@apache.org> Signed-off-by: Bryan Beaudreault <bbeaudreault@apache.org>
This commit is contained in:
parent
6fae190413
commit
e2ac5a9338
|
@ -649,7 +649,7 @@ class AsyncNonMetaRegionLocator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addLocationToCache(HRegionLocation loc) {
|
void addLocationToCache(HRegionLocation loc) {
|
||||||
addToCache(getTableCache(loc.getRegion().getTable()), createRegionLocations(loc));
|
addToCache(getTableCache(loc.getRegion().getTable()), createRegionLocations(loc));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package org.apache.hadoop.hbase.client;
|
package org.apache.hadoop.hbase.client;
|
||||||
|
|
||||||
import static org.apache.hadoop.hbase.trace.TraceUtil.tracedFuture;
|
import static org.apache.hadoop.hbase.trace.TraceUtil.tracedFuture;
|
||||||
|
import static org.apache.hadoop.hbase.util.FutureUtils.addListener;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -61,8 +62,11 @@ class AsyncTableRegionLocatorImpl implements AsyncTableRegionLocator {
|
||||||
return conn.registry.getMetaRegionLocations()
|
return conn.registry.getMetaRegionLocations()
|
||||||
.thenApply(locs -> Arrays.asList(locs.getRegionLocations()));
|
.thenApply(locs -> Arrays.asList(locs.getRegionLocations()));
|
||||||
}
|
}
|
||||||
return AsyncMetaTableAccessor
|
CompletableFuture<List<HRegionLocation>> future = AsyncMetaTableAccessor
|
||||||
.getTableHRegionLocations(conn.getTable(TableName.META_TABLE_NAME), tableName);
|
.getTableHRegionLocations(conn.getTable(TableName.META_TABLE_NAME), tableName);
|
||||||
|
addListener(future, (locs, error) -> locs.forEach(loc -> conn.getLocator()
|
||||||
|
.getNonMetaRegionLocator().addLocationToCache(loc)));
|
||||||
|
return future;
|
||||||
}, getClass().getSimpleName() + ".getAllRegionLocations");
|
}, getClass().getSimpleName() + ".getAllRegionLocations");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -459,4 +460,17 @@ public class TestAsyncNonMetaRegionLocator {
|
||||||
IntStream.range(0, 100).parallel()
|
IntStream.range(0, 100).parallel()
|
||||||
.forEach(i -> locator.updateCachedLocationOnError(loc, new NotServingRegionException()));
|
.forEach(i -> locator.updateCachedLocationOnError(loc, new NotServingRegionException()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCacheLocationWhenGetAllLocations() throws Exception {
|
||||||
|
createMultiRegionTable();
|
||||||
|
AsyncConnectionImpl conn = (AsyncConnectionImpl)
|
||||||
|
ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get();
|
||||||
|
conn.getRegionLocator(TABLE_NAME).getAllRegionLocations().get();
|
||||||
|
List<RegionInfo> regions = TEST_UTIL.getAdmin().getRegions(TABLE_NAME);
|
||||||
|
for (RegionInfo region : regions) {
|
||||||
|
assertNotNull(conn.getLocator().getNonMetaRegionLocator()
|
||||||
|
.getRegionLocationInCache(TABLE_NAME, region.getStartKey()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue