use of com.alipay.sofa.jraft.rhea.errors.Errors in project sofa-jraft by sofastack.
the class DefaultRheaKVStore method internalContainsKey.
private void internalContainsKey(final byte[] key, final CompletableFuture<Boolean> future, final int retriesLeft, final Errors lastCause) {
final Region region = this.pdClient.findRegionByKey(key, ErrorsHelper.isInvalidEpoch(lastCause));
final RegionEngine regionEngine = getRegionEngine(region.getId(), true);
final RetryRunner retryRunner = retryCause -> internalContainsKey(key, future, retriesLeft - 1, retryCause);
final FailoverClosure<Boolean> closure = new FailoverClosureImpl<>(future, retriesLeft, retryRunner);
if (regionEngine != null) {
if (ensureOnValidEpoch(region, regionEngine, closure)) {
getRawKVStore(regionEngine).containsKey(key, closure);
}
} else {
final ContainsKeyRequest request = new ContainsKeyRequest();
request.setKey(key);
request.setRegionId(region.getId());
request.setRegionEpoch(region.getRegionEpoch());
this.rheaKVRpcService.callAsyncWithRpc(request, closure, lastCause);
}
}
use of com.alipay.sofa.jraft.rhea.errors.Errors in project sofa-jraft by sofastack.
the class MetadataRpcClient method internalGetClusterInfo.
private void internalGetClusterInfo(final long clusterId, final CompletableFuture<Cluster> future, final int retriesLeft, final Errors lastCause) {
final RetryRunner retryRunner = retryCause -> internalGetClusterInfo(clusterId, future, retriesLeft - 1, retryCause);
final FailoverClosure<Cluster> closure = new FailoverClosureImpl<>(future, retriesLeft, retryRunner);
final GetClusterInfoRequest request = new GetClusterInfoRequest();
request.setClusterId(clusterId);
this.pdRpcService.callPdServerWithRpc(request, closure, lastCause);
}
use of com.alipay.sofa.jraft.rhea.errors.Errors in project sofa-jraft by sofastack.
the class MetadataRpcClient method internalCreateRegionId.
private void internalCreateRegionId(final long clusterId, final Endpoint endpoint, final CompletableFuture<Long> future, final int retriesLeft, final Errors lastCause) {
final RetryRunner retryRunner = retryCause -> internalCreateRegionId(clusterId, endpoint, future, retriesLeft - 1, retryCause);
final FailoverClosure<Long> closure = new FailoverClosureImpl<>(future, retriesLeft, retryRunner);
final CreateRegionIdRequest request = new CreateRegionIdRequest();
request.setClusterId(clusterId);
request.setEndpoint(endpoint);
this.pdRpcService.callPdServerWithRpc(request, closure, lastCause);
}
use of com.alipay.sofa.jraft.rhea.errors.Errors 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);
}
use of com.alipay.sofa.jraft.rhea.errors.Errors in project sofa-jraft by sofastack.
the class ListFailoverFutureTest method regionScan.
@SuppressWarnings("unused")
private void regionScan(final int start, final int end, final CompletableFuture<List<Integer>> future, final int retriesLeft, final Errors lastCause) {
System.out.println("start=" + start + ", end=" + end);
final RetryRunner retryRunner = retryCause -> regionScan(start, end, future, retriesLeft - 1, retryCause);
final FailoverClosure<List<Integer>> closure = new FailoverClosureImpl<>(future, false, retriesLeft, retryRunner);
if (getCounter(start, end).incrementAndGet() < 2) {
System.err.println("fail: " + start + " - " + end);
closure.failure(Errors.INVALID_REGION_MEMBERSHIP);
} else {
final List<Integer> result = new ArrayList<>();
for (int i = start; i < end; i++) {
result.add(i);
}
closure.success(result);
}
}
Aggregations