use of com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl in project sofa-jraft by sofastack.
the class DefaultRheaKVStore method internalRegionScan.
private void internalRegionScan(final Region region, final byte[] subStartKey, final byte[] subEndKey, final boolean reverse, final boolean readOnlySafe, final boolean returnValue, final CompletableFuture<List<KVEntry>> future, final int retriesLeft, final Errors lastCause, final boolean requireLeader) {
final RegionEngine regionEngine = getRegionEngine(region.getId(), requireLeader);
// require leader on retry
final RetryRunner retryRunner = retryCause -> internalRegionScan(region, subStartKey, subEndKey, reverse, readOnlySafe, returnValue, future, retriesLeft - 1, retryCause, true);
final FailoverClosure<List<KVEntry>> closure = new FailoverClosureImpl<>(future, false, retriesLeft, retryRunner);
if (regionEngine != null) {
if (ensureOnValidEpoch(region, regionEngine, closure)) {
final RawKVStore rawKVStore = getRawKVStore(regionEngine);
if (reverse) {
if (this.kvDispatcher == null) {
rawKVStore.reverseScan(subStartKey, subEndKey, readOnlySafe, returnValue, closure);
} else {
this.kvDispatcher.execute(() -> rawKVStore.reverseScan(subStartKey, subEndKey, readOnlySafe, returnValue, closure));
}
} else {
if (this.kvDispatcher == null) {
rawKVStore.scan(subStartKey, subEndKey, readOnlySafe, returnValue, closure);
} else {
this.kvDispatcher.execute(() -> rawKVStore.scan(subStartKey, subEndKey, readOnlySafe, returnValue, closure));
}
}
}
} else {
final ScanRequest request = new ScanRequest();
request.setStartKey(subStartKey);
request.setEndKey(subEndKey);
request.setReadOnlySafe(readOnlySafe);
request.setReturnValue(returnValue);
request.setRegionId(region.getId());
request.setRegionEpoch(region.getRegionEpoch());
request.setReverse(reverse);
this.rheaKVRpcService.callAsyncWithRpc(request, closure, lastCause, requireLeader);
}
}
use of com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl in project sofa-jraft by sofastack.
the class DefaultRheaKVStore method internalMerge.
private void internalMerge(final byte[] key, final byte[] value, 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 -> internalMerge(key, value, future, retriesLeft - 1, retryCause);
final FailoverClosure<Boolean> closure = new FailoverClosureImpl<>(future, retriesLeft, retryRunner);
if (regionEngine != null) {
if (ensureOnValidEpoch(region, regionEngine, closure)) {
getRawKVStore(regionEngine).merge(key, value, closure);
}
} else {
final MergeRequest request = new MergeRequest();
request.setKey(key);
request.setValue(value);
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 internalResetSequence.
private void internalResetSequence(final byte[] seqKey, final CompletableFuture<Boolean> future, final int retriesLeft, final Errors lastCause) {
final Region region = this.pdClient.findRegionByKey(seqKey, ErrorsHelper.isInvalidEpoch(lastCause));
final RegionEngine regionEngine = getRegionEngine(region.getId(), true);
final RetryRunner retryRunner = retryCause -> internalResetSequence(seqKey, future, retriesLeft - 1, retryCause);
final FailoverClosure<Boolean> closure = new FailoverClosureImpl<>(future, retriesLeft, retryRunner);
if (regionEngine != null) {
if (ensureOnValidEpoch(region, regionEngine, closure)) {
getRawKVStore(regionEngine).resetSequence(seqKey, closure);
}
} else {
final ResetSequenceRequest request = new ResetSequenceRequest();
request.setSeqKey(seqKey);
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 internalGet.
private void internalGet(final byte[] key, final boolean readOnlySafe, final CompletableFuture<byte[]> future, final int retriesLeft, final Errors lastCause, final boolean requireLeader) {
final Region region = this.pdClient.findRegionByKey(key, ErrorsHelper.isInvalidEpoch(lastCause));
final RegionEngine regionEngine = getRegionEngine(region.getId(), requireLeader);
// require leader on retry
final RetryRunner retryRunner = retryCause -> internalGet(key, readOnlySafe, future, retriesLeft - 1, retryCause, true);
final FailoverClosure<byte[]> closure = new FailoverClosureImpl<>(future, retriesLeft, retryRunner);
if (regionEngine != null) {
if (ensureOnValidEpoch(region, regionEngine, closure)) {
getRawKVStore(regionEngine).get(key, readOnlySafe, closure);
}
} else {
final GetRequest request = new GetRequest();
request.setKey(key);
request.setReadOnlySafe(readOnlySafe);
request.setRegionId(region.getId());
request.setRegionEpoch(region.getRegionEpoch());
this.rheaKVRpcService.callAsyncWithRpc(request, closure, lastCause, requireLeader);
}
}
use of com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl in project sofa-jraft by sofastack.
the class DefaultRheaKVStore method internalGetAndPut.
private void internalGetAndPut(final byte[] key, final byte[] value, final CompletableFuture<byte[]> 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 -> internalGetAndPut(key, value, future, retriesLeft - 1, retryCause);
final FailoverClosure<byte[]> closure = new FailoverClosureImpl<>(future, retriesLeft, retryRunner);
if (regionEngine != null) {
if (ensureOnValidEpoch(region, regionEngine, closure)) {
getRawKVStore(regionEngine).getAndPut(key, value, closure);
}
} else {
final GetAndPutRequest request = new GetAndPutRequest();
request.setKey(key);
request.setValue(value);
request.setRegionId(region.getId());
request.setRegionEpoch(region.getRegionEpoch());
this.rheaKVRpcService.callAsyncWithRpc(request, closure, lastCause);
}
}
Aggregations