Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ private void removeLocationFromCache(HRegionLocation loc) {
}
}

private void addLocationToCache(HRegionLocation loc) {
void addLocationToCache(HRegionLocation loc) {
addToCache(getTableCache(loc.getRegion().getTable()), createRegionLocations(loc));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hbase.client;

import static org.apache.hadoop.hbase.util.FutureUtils.addListener;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -58,8 +60,11 @@ public CompletableFuture<List<HRegionLocation>> getAllRegionLocations() {
return conn.registry.getMetaRegionLocations()
.thenApply(locs -> Arrays.asList(locs.getRegionLocations()));
}
return AsyncMetaTableAccessor.getTableHRegionLocations(conn.getTable(TableName.META_TABLE_NAME),
tableName);
CompletableFuture<List<HRegionLocation>> future = AsyncMetaTableAccessor
.getTableHRegionLocations(conn.getTable(TableName.META_TABLE_NAME), tableName);
addListener(future, (locs, error) -> locs.forEach(loc -> conn.getLocator()
.getNonMetaRegionLocator().addLocationToCache(loc)));
return future;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;

import java.io.IOException;
Expand Down Expand Up @@ -466,4 +467,17 @@ public void testConcurrentUpdateCachedLocationOnError() throws Exception {
IntStream.range(0, 100).parallel()
.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()));
}
}
}