Search in sources :

Example 6 with RetryRunner

use of com.alipay.sofa.jraft.rhea.client.failover.RetryRunner 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);
    }
}
Also used : NamedThreadFactory(com.alipay.sofa.jraft.rhea.util.concurrent.NamedThreadFactory) PlacementDriverClient(com.alipay.sofa.jraft.rhea.client.pd.PlacementDriverClient) BatchingOptions(com.alipay.sofa.jraft.rhea.options.BatchingOptions) LoggerFactory(org.slf4j.LoggerFactory) FailoverClosure(com.alipay.sofa.jraft.rhea.client.failover.FailoverClosure) ExtSerializerSupports(com.alipay.sofa.jraft.rhea.rpc.ExtSerializerSupports) Region(com.alipay.sofa.jraft.rhea.metadata.Region) Lists(com.alipay.sofa.jraft.rhea.util.Lists) ListFailoverFuture(com.alipay.sofa.jraft.rhea.client.failover.impl.ListFailoverFuture) DescriberManager(com.alipay.sofa.jraft.rhea.DescriberManager) Map(java.util.Map) Constants(com.alipay.sofa.jraft.rhea.util.Constants) ApiExceptionHelper(com.alipay.sofa.jraft.rhea.errors.ApiExceptionHelper) ScanRequest(com.alipay.sofa.jraft.rhea.cmd.store.ScanRequest) Endpoint(com.alipay.sofa.jraft.util.Endpoint) MergeRequest(com.alipay.sofa.jraft.rhea.cmd.store.MergeRequest) ThreadFactory(java.util.concurrent.ThreadFactory) DeleteRequest(com.alipay.sofa.jraft.rhea.cmd.store.DeleteRequest) WaitStrategyType(com.alipay.sofa.jraft.rhea.util.concurrent.disruptor.WaitStrategyType) CASEntry(com.alipay.sofa.jraft.rhea.storage.CASEntry) DistributedLock(com.alipay.sofa.jraft.rhea.util.concurrent.DistributedLock) LogExceptionHandler(com.alipay.sofa.jraft.util.LogExceptionHandler) CASAllRequest(com.alipay.sofa.jraft.rhea.cmd.store.CASAllRequest) TaskDispatcher(com.alipay.sofa.jraft.rhea.util.concurrent.disruptor.TaskDispatcher) PeerId(com.alipay.sofa.jraft.entity.PeerId) RouteTable(com.alipay.sofa.jraft.RouteTable) PlacementDriverOptions(com.alipay.sofa.jraft.rhea.options.PlacementDriverOptions) KVStoreClosure(com.alipay.sofa.jraft.rhea.storage.KVStoreClosure) KVMetrics(com.alipay.sofa.jraft.rhea.metrics.KVMetrics) CompareAndPutRequest(com.alipay.sofa.jraft.rhea.cmd.store.CompareAndPutRequest) PutRequest(com.alipay.sofa.jraft.rhea.cmd.store.PutRequest) FakePlacementDriverClient(com.alipay.sofa.jraft.rhea.client.pd.FakePlacementDriverClient) ContainsKeyRequest(com.alipay.sofa.jraft.rhea.cmd.store.ContainsKeyRequest) RawKVStore(com.alipay.sofa.jraft.rhea.storage.RawKVStore) DeleteRangeRequest(com.alipay.sofa.jraft.rhea.cmd.store.DeleteRangeRequest) Strings(com.alipay.sofa.jraft.rhea.util.Strings) List(java.util.List) ResetSequenceRequest(com.alipay.sofa.jraft.rhea.cmd.store.ResetSequenceRequest) RegionEngine(com.alipay.sofa.jraft.rhea.RegionEngine) BoolFailoverFuture(com.alipay.sofa.jraft.rhea.client.failover.impl.BoolFailoverFuture) JRaftHelper(com.alipay.sofa.jraft.rhea.JRaftHelper) ZipStrategyManager(com.alipay.sofa.jraft.rhea.storage.zip.ZipStrategyManager) RemotePlacementDriverClient(com.alipay.sofa.jraft.rhea.client.pd.RemotePlacementDriverClient) FailoverClosureImpl(com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl) RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) Requires(com.alipay.sofa.jraft.util.Requires) Histogram(com.codahale.metrics.Histogram) RheaRuntimeException(com.alipay.sofa.jraft.rhea.errors.RheaRuntimeException) BatchPutRequest(com.alipay.sofa.jraft.rhea.cmd.store.BatchPutRequest) StackTraceUtil(com.alipay.sofa.jraft.rhea.util.StackTraceUtil) CompletableFuture(java.util.concurrent.CompletableFuture) FollowerStateListener(com.alipay.sofa.jraft.rhea.FollowerStateListener) Utils(com.alipay.sofa.jraft.util.Utils) ErrorsHelper(com.alipay.sofa.jraft.rhea.errors.ErrorsHelper) BatchDeleteRequest(com.alipay.sofa.jraft.rhea.cmd.store.BatchDeleteRequest) StateListenerContainer(com.alipay.sofa.jraft.rhea.StateListenerContainer) RetryCallable(com.alipay.sofa.jraft.rhea.client.failover.RetryCallable) GetRequest(com.alipay.sofa.jraft.rhea.cmd.store.GetRequest) Errors(com.alipay.sofa.jraft.rhea.errors.Errors) StateListener(com.alipay.sofa.jraft.rhea.StateListener) GetAndPutRequest(com.alipay.sofa.jraft.rhea.cmd.store.GetAndPutRequest) KeyLockRequest(com.alipay.sofa.jraft.rhea.cmd.store.KeyLockRequest) KeyUnlockRequest(com.alipay.sofa.jraft.rhea.cmd.store.KeyUnlockRequest) MapFailoverFuture(com.alipay.sofa.jraft.rhea.client.failover.impl.MapFailoverFuture) KVMetricNames(com.alipay.sofa.jraft.rhea.metrics.KVMetricNames) KVIterator(com.alipay.sofa.jraft.rhea.storage.KVIterator) NodeExecutor(com.alipay.sofa.jraft.rhea.storage.NodeExecutor) Dispatcher(com.alipay.sofa.jraft.rhea.util.concurrent.disruptor.Dispatcher) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StoreEngine(com.alipay.sofa.jraft.rhea.StoreEngine) MultiGetRequest(com.alipay.sofa.jraft.rhea.cmd.store.MultiGetRequest) EventHandler(com.lmax.disruptor.EventHandler) PutIfAbsentRequest(com.alipay.sofa.jraft.rhea.cmd.store.PutIfAbsentRequest) Logger(org.slf4j.Logger) RetryRunner(com.alipay.sofa.jraft.rhea.client.failover.RetryRunner) GetSequenceRequest(com.alipay.sofa.jraft.rhea.cmd.store.GetSequenceRequest) RingBuffer(com.lmax.disruptor.RingBuffer) AffinityNamedThreadFactory(com.alipay.sofa.jraft.rhea.util.concurrent.AffinityNamedThreadFactory) ListRetryCallable(com.alipay.sofa.jraft.rhea.client.failover.ListRetryCallable) Status(com.alipay.sofa.jraft.Status) ByteArray(com.alipay.sofa.jraft.rhea.util.ByteArray) NodeExecuteRequest(com.alipay.sofa.jraft.rhea.cmd.store.NodeExecuteRequest) TimeUnit(java.util.concurrent.TimeUnit) StoreEngineOptions(com.alipay.sofa.jraft.rhea.options.StoreEngineOptions) Sequence(com.alipay.sofa.jraft.rhea.storage.Sequence) RpcOptions(com.alipay.sofa.jraft.rhea.options.RpcOptions) KVEntry(com.alipay.sofa.jraft.rhea.storage.KVEntry) Collections(java.util.Collections) LeaderStateListener(com.alipay.sofa.jraft.rhea.LeaderStateListener) EventFactory(com.lmax.disruptor.EventFactory) Disruptor(com.lmax.disruptor.dsl.Disruptor) BytesUtil(com.alipay.sofa.jraft.util.BytesUtil) FailoverClosureImpl(com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl) RawKVStore(com.alipay.sofa.jraft.rhea.storage.RawKVStore) BatchPutRequest(com.alipay.sofa.jraft.rhea.cmd.store.BatchPutRequest) RegionEngine(com.alipay.sofa.jraft.rhea.RegionEngine) RetryRunner(com.alipay.sofa.jraft.rhea.client.failover.RetryRunner)

Example 7 with RetryRunner

use of com.alipay.sofa.jraft.rhea.client.failover.RetryRunner 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);
    }
}
Also used : NamedThreadFactory(com.alipay.sofa.jraft.rhea.util.concurrent.NamedThreadFactory) PlacementDriverClient(com.alipay.sofa.jraft.rhea.client.pd.PlacementDriverClient) BatchingOptions(com.alipay.sofa.jraft.rhea.options.BatchingOptions) LoggerFactory(org.slf4j.LoggerFactory) FailoverClosure(com.alipay.sofa.jraft.rhea.client.failover.FailoverClosure) ExtSerializerSupports(com.alipay.sofa.jraft.rhea.rpc.ExtSerializerSupports) Region(com.alipay.sofa.jraft.rhea.metadata.Region) Lists(com.alipay.sofa.jraft.rhea.util.Lists) ListFailoverFuture(com.alipay.sofa.jraft.rhea.client.failover.impl.ListFailoverFuture) DescriberManager(com.alipay.sofa.jraft.rhea.DescriberManager) Map(java.util.Map) Constants(com.alipay.sofa.jraft.rhea.util.Constants) ApiExceptionHelper(com.alipay.sofa.jraft.rhea.errors.ApiExceptionHelper) ScanRequest(com.alipay.sofa.jraft.rhea.cmd.store.ScanRequest) Endpoint(com.alipay.sofa.jraft.util.Endpoint) MergeRequest(com.alipay.sofa.jraft.rhea.cmd.store.MergeRequest) ThreadFactory(java.util.concurrent.ThreadFactory) DeleteRequest(com.alipay.sofa.jraft.rhea.cmd.store.DeleteRequest) WaitStrategyType(com.alipay.sofa.jraft.rhea.util.concurrent.disruptor.WaitStrategyType) CASEntry(com.alipay.sofa.jraft.rhea.storage.CASEntry) DistributedLock(com.alipay.sofa.jraft.rhea.util.concurrent.DistributedLock) LogExceptionHandler(com.alipay.sofa.jraft.util.LogExceptionHandler) CASAllRequest(com.alipay.sofa.jraft.rhea.cmd.store.CASAllRequest) TaskDispatcher(com.alipay.sofa.jraft.rhea.util.concurrent.disruptor.TaskDispatcher) PeerId(com.alipay.sofa.jraft.entity.PeerId) RouteTable(com.alipay.sofa.jraft.RouteTable) PlacementDriverOptions(com.alipay.sofa.jraft.rhea.options.PlacementDriverOptions) KVStoreClosure(com.alipay.sofa.jraft.rhea.storage.KVStoreClosure) KVMetrics(com.alipay.sofa.jraft.rhea.metrics.KVMetrics) CompareAndPutRequest(com.alipay.sofa.jraft.rhea.cmd.store.CompareAndPutRequest) PutRequest(com.alipay.sofa.jraft.rhea.cmd.store.PutRequest) FakePlacementDriverClient(com.alipay.sofa.jraft.rhea.client.pd.FakePlacementDriverClient) ContainsKeyRequest(com.alipay.sofa.jraft.rhea.cmd.store.ContainsKeyRequest) RawKVStore(com.alipay.sofa.jraft.rhea.storage.RawKVStore) DeleteRangeRequest(com.alipay.sofa.jraft.rhea.cmd.store.DeleteRangeRequest) Strings(com.alipay.sofa.jraft.rhea.util.Strings) List(java.util.List) ResetSequenceRequest(com.alipay.sofa.jraft.rhea.cmd.store.ResetSequenceRequest) RegionEngine(com.alipay.sofa.jraft.rhea.RegionEngine) BoolFailoverFuture(com.alipay.sofa.jraft.rhea.client.failover.impl.BoolFailoverFuture) JRaftHelper(com.alipay.sofa.jraft.rhea.JRaftHelper) ZipStrategyManager(com.alipay.sofa.jraft.rhea.storage.zip.ZipStrategyManager) RemotePlacementDriverClient(com.alipay.sofa.jraft.rhea.client.pd.RemotePlacementDriverClient) FailoverClosureImpl(com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl) RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) Requires(com.alipay.sofa.jraft.util.Requires) Histogram(com.codahale.metrics.Histogram) RheaRuntimeException(com.alipay.sofa.jraft.rhea.errors.RheaRuntimeException) BatchPutRequest(com.alipay.sofa.jraft.rhea.cmd.store.BatchPutRequest) StackTraceUtil(com.alipay.sofa.jraft.rhea.util.StackTraceUtil) CompletableFuture(java.util.concurrent.CompletableFuture) FollowerStateListener(com.alipay.sofa.jraft.rhea.FollowerStateListener) Utils(com.alipay.sofa.jraft.util.Utils) ErrorsHelper(com.alipay.sofa.jraft.rhea.errors.ErrorsHelper) BatchDeleteRequest(com.alipay.sofa.jraft.rhea.cmd.store.BatchDeleteRequest) StateListenerContainer(com.alipay.sofa.jraft.rhea.StateListenerContainer) RetryCallable(com.alipay.sofa.jraft.rhea.client.failover.RetryCallable) GetRequest(com.alipay.sofa.jraft.rhea.cmd.store.GetRequest) Errors(com.alipay.sofa.jraft.rhea.errors.Errors) StateListener(com.alipay.sofa.jraft.rhea.StateListener) GetAndPutRequest(com.alipay.sofa.jraft.rhea.cmd.store.GetAndPutRequest) KeyLockRequest(com.alipay.sofa.jraft.rhea.cmd.store.KeyLockRequest) KeyUnlockRequest(com.alipay.sofa.jraft.rhea.cmd.store.KeyUnlockRequest) MapFailoverFuture(com.alipay.sofa.jraft.rhea.client.failover.impl.MapFailoverFuture) KVMetricNames(com.alipay.sofa.jraft.rhea.metrics.KVMetricNames) KVIterator(com.alipay.sofa.jraft.rhea.storage.KVIterator) NodeExecutor(com.alipay.sofa.jraft.rhea.storage.NodeExecutor) Dispatcher(com.alipay.sofa.jraft.rhea.util.concurrent.disruptor.Dispatcher) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StoreEngine(com.alipay.sofa.jraft.rhea.StoreEngine) MultiGetRequest(com.alipay.sofa.jraft.rhea.cmd.store.MultiGetRequest) EventHandler(com.lmax.disruptor.EventHandler) PutIfAbsentRequest(com.alipay.sofa.jraft.rhea.cmd.store.PutIfAbsentRequest) Logger(org.slf4j.Logger) RetryRunner(com.alipay.sofa.jraft.rhea.client.failover.RetryRunner) GetSequenceRequest(com.alipay.sofa.jraft.rhea.cmd.store.GetSequenceRequest) RingBuffer(com.lmax.disruptor.RingBuffer) AffinityNamedThreadFactory(com.alipay.sofa.jraft.rhea.util.concurrent.AffinityNamedThreadFactory) ListRetryCallable(com.alipay.sofa.jraft.rhea.client.failover.ListRetryCallable) Status(com.alipay.sofa.jraft.Status) ByteArray(com.alipay.sofa.jraft.rhea.util.ByteArray) NodeExecuteRequest(com.alipay.sofa.jraft.rhea.cmd.store.NodeExecuteRequest) TimeUnit(java.util.concurrent.TimeUnit) StoreEngineOptions(com.alipay.sofa.jraft.rhea.options.StoreEngineOptions) Sequence(com.alipay.sofa.jraft.rhea.storage.Sequence) RpcOptions(com.alipay.sofa.jraft.rhea.options.RpcOptions) KVEntry(com.alipay.sofa.jraft.rhea.storage.KVEntry) Collections(java.util.Collections) LeaderStateListener(com.alipay.sofa.jraft.rhea.LeaderStateListener) EventFactory(com.lmax.disruptor.EventFactory) Disruptor(com.lmax.disruptor.dsl.Disruptor) BytesUtil(com.alipay.sofa.jraft.util.BytesUtil) FailoverClosureImpl(com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl) Region(com.alipay.sofa.jraft.rhea.metadata.Region) RegionEngine(com.alipay.sofa.jraft.rhea.RegionEngine) RetryRunner(com.alipay.sofa.jraft.rhea.client.failover.RetryRunner) ContainsKeyRequest(com.alipay.sofa.jraft.rhea.cmd.store.ContainsKeyRequest)

Example 8 with RetryRunner

use of com.alipay.sofa.jraft.rhea.client.failover.RetryRunner 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);
}
Also used : Store(com.alipay.sofa.jraft.rhea.metadata.Store) RetryRunner(com.alipay.sofa.jraft.rhea.client.failover.RetryRunner) FailoverClosure(com.alipay.sofa.jraft.rhea.client.failover.FailoverClosure) CreateRegionIdRequest(com.alipay.sofa.jraft.rhea.cmd.pd.CreateRegionIdRequest) CompletableFuture(java.util.concurrent.CompletableFuture) GetStoreInfoRequest(com.alipay.sofa.jraft.rhea.cmd.pd.GetStoreInfoRequest) Errors(com.alipay.sofa.jraft.rhea.errors.Errors) Cluster(com.alipay.sofa.jraft.rhea.metadata.Cluster) GetStoreIdRequest(com.alipay.sofa.jraft.rhea.cmd.pd.GetStoreIdRequest) SetStoreInfoRequest(com.alipay.sofa.jraft.rhea.cmd.pd.SetStoreInfoRequest) GetClusterInfoRequest(com.alipay.sofa.jraft.rhea.cmd.pd.GetClusterInfoRequest) Endpoint(com.alipay.sofa.jraft.util.Endpoint) FutureHelper(com.alipay.sofa.jraft.rhea.client.FutureHelper) FailoverClosureImpl(com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl) GetClusterInfoRequest(com.alipay.sofa.jraft.rhea.cmd.pd.GetClusterInfoRequest) FailoverClosureImpl(com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl) Cluster(com.alipay.sofa.jraft.rhea.metadata.Cluster) RetryRunner(com.alipay.sofa.jraft.rhea.client.failover.RetryRunner)

Example 9 with RetryRunner

use of com.alipay.sofa.jraft.rhea.client.failover.RetryRunner 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);
}
Also used : Store(com.alipay.sofa.jraft.rhea.metadata.Store) RetryRunner(com.alipay.sofa.jraft.rhea.client.failover.RetryRunner) FailoverClosure(com.alipay.sofa.jraft.rhea.client.failover.FailoverClosure) CreateRegionIdRequest(com.alipay.sofa.jraft.rhea.cmd.pd.CreateRegionIdRequest) CompletableFuture(java.util.concurrent.CompletableFuture) GetStoreInfoRequest(com.alipay.sofa.jraft.rhea.cmd.pd.GetStoreInfoRequest) Errors(com.alipay.sofa.jraft.rhea.errors.Errors) Cluster(com.alipay.sofa.jraft.rhea.metadata.Cluster) GetStoreIdRequest(com.alipay.sofa.jraft.rhea.cmd.pd.GetStoreIdRequest) SetStoreInfoRequest(com.alipay.sofa.jraft.rhea.cmd.pd.SetStoreInfoRequest) GetClusterInfoRequest(com.alipay.sofa.jraft.rhea.cmd.pd.GetClusterInfoRequest) Endpoint(com.alipay.sofa.jraft.util.Endpoint) FutureHelper(com.alipay.sofa.jraft.rhea.client.FutureHelper) FailoverClosureImpl(com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl) FailoverClosureImpl(com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl) CreateRegionIdRequest(com.alipay.sofa.jraft.rhea.cmd.pd.CreateRegionIdRequest) RetryRunner(com.alipay.sofa.jraft.rhea.client.failover.RetryRunner)

Example 10 with RetryRunner

use of com.alipay.sofa.jraft.rhea.client.failover.RetryRunner 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);
    }
}
Also used : RetryRunner(com.alipay.sofa.jraft.rhea.client.failover.RetryRunner) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FailoverClosure(com.alipay.sofa.jraft.rhea.client.failover.FailoverClosure) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test) ListRetryCallable(com.alipay.sofa.jraft.rhea.client.failover.ListRetryCallable) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Errors(com.alipay.sofa.jraft.rhea.errors.Errors) ExecutionException(java.util.concurrent.ExecutionException) Lists(com.alipay.sofa.jraft.rhea.util.Lists) List(java.util.List) ListFailoverFuture(com.alipay.sofa.jraft.rhea.client.failover.impl.ListFailoverFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assert(org.junit.Assert) FailoverClosureImpl(com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FailoverClosureImpl(com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RetryRunner(com.alipay.sofa.jraft.rhea.client.failover.RetryRunner)

Aggregations

FailoverClosure (com.alipay.sofa.jraft.rhea.client.failover.FailoverClosure)27 RetryRunner (com.alipay.sofa.jraft.rhea.client.failover.RetryRunner)27 FailoverClosureImpl (com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl)27 Errors (com.alipay.sofa.jraft.rhea.errors.Errors)27 CompletableFuture (java.util.concurrent.CompletableFuture)27 Endpoint (com.alipay.sofa.jraft.util.Endpoint)25 Lists (com.alipay.sofa.jraft.rhea.util.Lists)22 List (java.util.List)22 ListRetryCallable (com.alipay.sofa.jraft.rhea.client.failover.ListRetryCallable)21 RetryCallable (com.alipay.sofa.jraft.rhea.client.failover.RetryCallable)21 ListFailoverFuture (com.alipay.sofa.jraft.rhea.client.failover.impl.ListFailoverFuture)21 MapFailoverFuture (com.alipay.sofa.jraft.rhea.client.failover.impl.MapFailoverFuture)21 RouteTable (com.alipay.sofa.jraft.RouteTable)20 Status (com.alipay.sofa.jraft.Status)20 PeerId (com.alipay.sofa.jraft.entity.PeerId)20 DescriberManager (com.alipay.sofa.jraft.rhea.DescriberManager)20 FollowerStateListener (com.alipay.sofa.jraft.rhea.FollowerStateListener)20 JRaftHelper (com.alipay.sofa.jraft.rhea.JRaftHelper)20 LeaderStateListener (com.alipay.sofa.jraft.rhea.LeaderStateListener)20 RegionEngine (com.alipay.sofa.jraft.rhea.RegionEngine)20