Search in sources :

Example 1 with ListRetryCallable

use of io.dingodb.store.row.client.failover.ListRetryCallable in project dingo by dingodb.

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

Example 2 with ListRetryCallable

use of io.dingodb.store.row.client.failover.ListRetryCallable in project dingo by dingodb.

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

Aggregations

Histogram (com.codahale.metrics.Histogram)2 EventFactory (com.lmax.disruptor.EventFactory)2 EventHandler (com.lmax.disruptor.EventHandler)2 RingBuffer (com.lmax.disruptor.RingBuffer)2 Disruptor (com.lmax.disruptor.dsl.Disruptor)2 RouteTable (io.dingodb.raft.RouteTable)2 Status (io.dingodb.raft.Status)2 PeerId (io.dingodb.raft.entity.PeerId)2 BytesUtil (io.dingodb.raft.util.BytesUtil)2 Endpoint (io.dingodb.raft.util.Endpoint)2 LogExceptionHandler (io.dingodb.raft.util.LogExceptionHandler)2 NamedThreadFactory (io.dingodb.raft.util.NamedThreadFactory)2 Requires (io.dingodb.raft.util.Requires)2 Utils (io.dingodb.raft.util.Utils)2 DescriberManager (io.dingodb.store.row.DescriberManager)2 FollowerStateListener (io.dingodb.store.row.FollowerStateListener)2 JRaftHelper (io.dingodb.store.row.JRaftHelper)2 LeaderStateListener (io.dingodb.store.row.LeaderStateListener)2 RegionEngine (io.dingodb.store.row.RegionEngine)2 StateListener (io.dingodb.store.row.StateListener)2