use of com.alipay.sofa.jraft.rhea.client.failover.impl.MapFailoverFuture in project sofa-jraft by sofastack.
the class MapFailoverFutureTest method multiGet.
private FutureGroup<Map<Integer, Integer>> multiGet(final int start, final int end, final int retriesLeft, final Throwable lastCause) {
final Errors lastError = lastCause == null ? null : Errors.forException(lastCause);
final List<CompletableFuture<Map<Integer, Integer>>> futureList = Lists.newArrayList();
final int mid = ((end - start) / 2) + start;
for (int i = 0; i < 2; i++) {
final int subStart = i == 0 ? start : mid;
final int subEnd = i == 0 ? mid : end;
if (subEnd - subStart > 0) {
final RetryCallable<Map<Integer, Integer>> retryCallable = retryCause -> multiGet(subStart, subEnd, retriesLeft - 1, retryCause);
final MapFailoverFuture<Integer, Integer> future = new MapFailoverFuture<>(retriesLeft, retryCallable);
regionMultiGet(subStart, subEnd, future, retriesLeft, lastError);
futureList.add(future);
}
}
return new FutureGroup<>(futureList);
}
use of com.alipay.sofa.jraft.rhea.client.failover.impl.MapFailoverFuture in project sofa-jraft by sofastack.
the class DefaultRheaKVStore method internalMultiGet.
private FutureGroup<Map<ByteArray, byte[]>> internalMultiGet(final List<byte[]> keys, final boolean readOnlySafe, final int retriesLeft, final Throwable lastCause) {
final Map<Region, List<byte[]>> regionMap = this.pdClient.findRegionsByKeys(keys, ApiExceptionHelper.isInvalidEpoch(lastCause));
final List<CompletableFuture<Map<ByteArray, byte[]>>> futures = Lists.newArrayListWithCapacity(regionMap.size());
final Errors lastError = lastCause == null ? null : Errors.forException(lastCause);
for (final Map.Entry<Region, List<byte[]>> entry : regionMap.entrySet()) {
final Region region = entry.getKey();
final List<byte[]> subKeys = entry.getValue();
final RetryCallable<Map<ByteArray, byte[]>> retryCallable = retryCause -> internalMultiGet(subKeys, readOnlySafe, retriesLeft - 1, retryCause);
final MapFailoverFuture<ByteArray, byte[]> future = new MapFailoverFuture<>(retriesLeft, retryCallable);
internalRegionMultiGet(region, subKeys, readOnlySafe, future, retriesLeft, lastError, this.onlyLeaderRead);
futures.add(future);
}
return new FutureGroup<>(futures);
}
Aggregations