use of com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl in project sofa-jraft by sofastack.
the class DefaultRheaKVStore method internalRegionPut.
private void internalRegionPut(final Region region, final List<KVEntry> subEntries, final CompletableFuture<Boolean> future, final int retriesLeft, final Errors lastCause) {
final RegionEngine regionEngine = getRegionEngine(region.getId(), true);
final RetryRunner retryRunner = retryCause -> internalRegionPut(region, subEntries, future, retriesLeft - 1, retryCause);
final FailoverClosure<Boolean> closure = new FailoverClosureImpl<>(future, false, retriesLeft, retryRunner);
if (regionEngine != null) {
if (ensureOnValidEpoch(region, regionEngine, closure)) {
final RawKVStore rawKVStore = getRawKVStore(regionEngine);
if (this.kvDispatcher == null) {
rawKVStore.put(subEntries, closure);
} else {
this.kvDispatcher.execute(() -> rawKVStore.put(subEntries, closure));
}
}
} else {
final BatchPutRequest request = new BatchPutRequest();
request.setKvEntries(subEntries);
request.setRegionId(region.getId());
request.setRegionEpoch(region.getRegionEpoch());
this.rheaKVRpcService.callAsyncWithRpc(request, closure, lastCause);
}
}
use of com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl 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.client.failover.impl.FailoverClosureImpl 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.client.failover.impl.FailoverClosureImpl 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.client.failover.impl.FailoverClosureImpl 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