use of com.alipay.sofa.jraft.rhea.client.failover.ListRetryCallable in project sofa-jraft by sofastack.
the class DefaultRheaKVStore method internalScan.
private FutureGroup<List<KVEntry>> internalScan(final byte[] startKey, final byte[] endKey, final boolean readOnlySafe, final boolean returnValue, final int retriesLeft, final Throwable lastCause) {
Requires.requireNonNull(startKey, "startKey");
final List<Region> regionList = this.pdClient.findRegionsByKeyRange(startKey, endKey, ApiExceptionHelper.isInvalidEpoch(lastCause));
final List<CompletableFuture<List<KVEntry>>> futures = Lists.newArrayListWithCapacity(regionList.size());
final Errors lastError = lastCause == null ? null : Errors.forException(lastCause);
for (final Region region : regionList) {
final byte[] regionStartKey = region.getStartKey();
final byte[] regionEndKey = region.getEndKey();
final byte[] subStartKey = regionStartKey == null ? startKey : BytesUtil.max(regionStartKey, startKey);
final byte[] subEndKey = regionEndKey == null ? endKey : (endKey == null ? regionEndKey : BytesUtil.min(regionEndKey, endKey));
final ListRetryCallable<KVEntry> retryCallable = retryCause -> internalScan(subStartKey, subEndKey, readOnlySafe, returnValue, retriesLeft - 1, retryCause);
final ListFailoverFuture<KVEntry> future = new ListFailoverFuture<>(retriesLeft, retryCallable);
internalRegionScan(region, subStartKey, subEndKey, false, readOnlySafe, returnValue, future, retriesLeft, lastError, this.onlyLeaderRead);
futures.add(future);
}
return new FutureGroup<>(futures);
}
use of com.alipay.sofa.jraft.rhea.client.failover.ListRetryCallable in project sofa-jraft by sofastack.
the class DefaultRheaKVStore method internalReverseScan.
private FutureGroup<List<KVEntry>> internalReverseScan(final byte[] startKey, final byte[] endKey, final boolean readOnlySafe, final boolean returnValue, final int retriesLeft, final Throwable lastCause) {
Requires.requireNonNull(endKey, "endKey");
final List<Region> regionList = this.pdClient.findRegionsByKeyRange(endKey, startKey, ApiExceptionHelper.isInvalidEpoch(lastCause));
Collections.reverse(regionList);
final List<CompletableFuture<List<KVEntry>>> futures = Lists.newArrayListWithCapacity(regionList.size());
final Errors lastError = lastCause == null ? null : Errors.forException(lastCause);
for (final Region region : regionList) {
final byte[] regionEndKey = region.getEndKey();
final byte[] regionStartKey = region.getStartKey();
final byte[] subStartKey = regionEndKey == null ? startKey : (startKey == null ? regionEndKey : BytesUtil.min(regionEndKey, startKey));
final byte[] subEndKey = regionStartKey == null ? endKey : BytesUtil.max(regionStartKey, endKey);
final ListRetryCallable<KVEntry> retryCallable = retryCause -> internalReverseScan(subStartKey, subEndKey, readOnlySafe, returnValue, retriesLeft - 1, retryCause);
final ListFailoverFuture<KVEntry> future = new ListFailoverFuture<>(retriesLeft, retryCallable);
internalRegionScan(region, subStartKey, subEndKey, true, readOnlySafe, returnValue, future, retriesLeft, lastError, this.onlyLeaderRead);
futures.add(future);
}
return new FutureGroup<>(futures);
}
use of com.alipay.sofa.jraft.rhea.client.failover.ListRetryCallable in project sofa-jraft by sofastack.
the class ListFailoverFutureTest method scan.
private FutureGroup<List<Integer>> scan(final int start, final int end, final int retriesLeft, final Throwable lastCause) {
final Errors lastError = lastCause == null ? null : Errors.forException(lastCause);
final List<CompletableFuture<List<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 ListRetryCallable<Integer> retryCallable = retryCause -> scan(subStart, subEnd, retriesLeft - 1, retryCause);
final ListFailoverFuture<Integer> future = new ListFailoverFuture<>(retriesLeft, retryCallable);
regionScan(subStart, subEnd, future, retriesLeft, lastError);
futureList.add(future);
}
}
return new FutureGroup<>(futureList);
}
Aggregations