use of org.apache.hadoop.hbase.CacheEvictionStatsAggregator in project hbase by apache.
the class RawAsyncHBaseAdmin method clearBlockCache.
@Override
public CompletableFuture<CacheEvictionStats> clearBlockCache(TableName tableName) {
CompletableFuture<CacheEvictionStats> future = new CompletableFuture<>();
addListener(getTableHRegionLocations(tableName), (locations, err) -> {
if (err != null) {
future.completeExceptionally(err);
return;
}
Map<ServerName, List<RegionInfo>> regionInfoByServerName = locations.stream().filter(l -> l.getRegion() != null).filter(l -> !l.getRegion().isOffline()).filter(l -> l.getServerName() != null).collect(Collectors.groupingBy(l -> l.getServerName(), Collectors.mapping(l -> l.getRegion(), Collectors.toList())));
List<CompletableFuture<CacheEvictionStats>> futures = new ArrayList<>();
CacheEvictionStatsAggregator aggregator = new CacheEvictionStatsAggregator();
for (Map.Entry<ServerName, List<RegionInfo>> entry : regionInfoByServerName.entrySet()) {
futures.add(clearBlockCache(entry.getKey(), entry.getValue()).whenComplete((stats, err2) -> {
if (err2 != null) {
future.completeExceptionally(unwrapCompletionException(err2));
} else {
aggregator.append(stats);
}
}));
}
addListener(CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])), (ret, err3) -> {
if (err3 != null) {
future.completeExceptionally(unwrapCompletionException(err3));
} else {
future.complete(aggregator.sum());
}
});
});
return future;
}
Aggregations