Search in sources :

Example 1 with CASEntry

use of io.dingodb.store.row.storage.CASEntry in project dingo by dingodb.

the class DefaultDingoRowStore method internalRegionCompareAndPutAll.

private void internalRegionCompareAndPutAll(final Region region, final List<CASEntry> subEntries, final CompletableFuture<Boolean> future, final int retriesLeft, final Errors lastCause) {
    final RegionEngine regionEngine = getRegionEngine(region.getId(), true);
    final RetryRunner retryRunner = retryCause -> internalRegionCompareAndPutAll(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.compareAndPutAll(subEntries, closure);
            } else {
                this.kvDispatcher.execute(() -> rawKVStore.compareAndPutAll(subEntries, closure));
            }
        }
    } else {
        final CASAllRequest request = new CASAllRequest();
        request.setCasEntries(subEntries);
        request.setRegionId(region.getId());
        request.setRegionEpoch(region.getRegionEpoch());
        this.dingoRowStoreRpcService.callAsyncWithRpc(request, closure, lastCause);
    }
}
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) FailoverClosureImpl(io.dingodb.store.row.client.failover.impl.FailoverClosureImpl) RawKVStore(io.dingodb.store.row.storage.RawKVStore) CASAllRequest(io.dingodb.store.row.cmd.store.CASAllRequest) RegionEngine(io.dingodb.store.row.RegionEngine) RetryRunner(io.dingodb.store.row.client.failover.RetryRunner)

Example 2 with CASEntry

use of io.dingodb.store.row.storage.CASEntry in project dingo by dingodb.

the class DefaultDingoRowStore method internalCompareAndPutAll.

private FutureGroup<Boolean> internalCompareAndPutAll(final List<CASEntry> entries, final int retriesLeft, final Throwable lastCause) {
    final Map<Region, List<CASEntry>> regionMap = this.pdClient.findRegionsByCASEntries(entries, ApiExceptionHelper.isInvalidEpoch(lastCause));
    final List<CompletableFuture<Boolean>> futures = Lists.newArrayListWithCapacity(regionMap.size());
    final Errors lastError = lastCause == null ? null : Errors.forException(lastCause);
    for (final Map.Entry<Region, List<CASEntry>> entry : regionMap.entrySet()) {
        final Region region = entry.getKey();
        final List<CASEntry> subEntries = entry.getValue();
        final RetryCallable<Boolean> retryCallable = retryCause -> internalCompareAndPutAll(subEntries, retriesLeft - 1, retryCause);
        final BoolFailoverFuture future = new BoolFailoverFuture(retriesLeft, retryCallable);
        internalRegionCompareAndPutAll(region, subEntries, future, retriesLeft, lastError);
        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) BoolFailoverFuture(io.dingodb.store.row.client.failover.impl.BoolFailoverFuture) Errors(io.dingodb.store.row.errors.Errors) CompletableFuture(java.util.concurrent.CompletableFuture) Region(io.dingodb.store.row.metadata.Region) List(java.util.List) CASEntry(io.dingodb.store.row.storage.CASEntry) Map(java.util.Map)

Example 3 with CASEntry

use of io.dingodb.store.row.storage.CASEntry in project dingo by dingodb.

the class DefaultRegionKVService method handleCompareAndPutAll.

@Override
public void handleCompareAndPutAll(final CASAllRequest request, final RequestProcessClosure<BaseRequest, BaseResponse<?>> closure) {
    final CASAllResponse response = new CASAllResponse();
    response.setRegionId(getRegionId());
    response.setRegionEpoch(getRegionEpoch());
    try {
        KVParameterRequires.requireSameEpoch(request, getRegionEpoch());
        final List<CASEntry> casEntries = KVParameterRequires.requireNonEmpty(request.getCasEntries(), "casAll.casEntries");
        this.rawKVStore.compareAndPutAll(casEntries, new BaseKVStoreClosure() {

            @Override
            public void run(final Status status) {
                if (status.isOk()) {
                    response.setValue((Boolean) getData());
                } else {
                    setFailure(request, response, status, getError());
                }
                closure.sendResponse(response);
            }
        });
    } catch (final Throwable t) {
        LOG.error("Failed to handle: {}, {}.", request, StackTraceUtil.stackTrace(t));
        response.setError(Errors.forException(t));
        closure.sendResponse(response);
    }
}
Also used : Status(io.dingodb.raft.Status) BaseKVStoreClosure(io.dingodb.store.row.storage.BaseKVStoreClosure) CASAllResponse(io.dingodb.store.row.cmd.store.CASAllResponse) CASEntry(io.dingodb.store.row.storage.CASEntry)

Example 4 with CASEntry

use of io.dingodb.store.row.storage.CASEntry in project dingo by dingodb.

the class RegionRouteTable method findRegionsByCASEntries.

/**
 * Returns the list of regions to which the keys belongs.
 */
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
public Map<Region, List<CASEntry>> findRegionsByCASEntries(final List<CASEntry> casEntries) {
    Requires.requireNonNull(casEntries, "casEntries");
    final Map<Region, List<CASEntry>> regionMap = Maps.newHashMap();
    final StampedLock stampedLock = this.stampedLock;
    final long stamp = stampedLock.readLock();
    try {
        for (final CASEntry casEntry : casEntries) {
            final Region region = findRegionByKeyWithoutLock(casEntry.getKey());
            regionMap.computeIfAbsent(region, k -> Lists.newArrayList()).add(casEntry);
        }
        return regionMap;
    } finally {
        stampedLock.unlockRead(stamp);
    }
}
Also used : Requires(io.dingodb.raft.util.Requires) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Region(io.dingodb.store.row.metadata.Region) Lists(io.dingodb.store.row.util.Lists) Maps(io.dingodb.store.row.util.Maps) NavigableMap(java.util.NavigableMap) List(java.util.List) TreeMap(java.util.TreeMap) RouteTableException(io.dingodb.store.row.errors.RouteTableException) Map(java.util.Map) BytesUtil(io.dingodb.raft.util.BytesUtil) KVEntry(io.dingodb.store.row.storage.KVEntry) Comparator(java.util.Comparator) RegionEpoch(io.dingodb.store.row.metadata.RegionEpoch) CASEntry(io.dingodb.store.row.storage.CASEntry) StampedLock(java.util.concurrent.locks.StampedLock) Region(io.dingodb.store.row.metadata.Region) StampedLock(java.util.concurrent.locks.StampedLock) List(java.util.List) CASEntry(io.dingodb.store.row.storage.CASEntry)

Aggregations

CASEntry (io.dingodb.store.row.storage.CASEntry)4 Status (io.dingodb.raft.Status)3 BytesUtil (io.dingodb.raft.util.BytesUtil)3 Requires (io.dingodb.raft.util.Requires)3 Region (io.dingodb.store.row.metadata.Region)3 KVEntry (io.dingodb.store.row.storage.KVEntry)3 Lists (io.dingodb.store.row.util.Lists)3 List (java.util.List)3 Map (java.util.Map)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 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 PeerId (io.dingodb.raft.entity.PeerId)2 Endpoint (io.dingodb.raft.util.Endpoint)2 LogExceptionHandler (io.dingodb.raft.util.LogExceptionHandler)2