Search in sources :

Example 1 with BaseResponse

use of io.dingodb.store.row.cmd.store.BaseResponse in project dingo by dingodb.

the class DefaultDingoRowStoreRpcService method internalCallAsyncWithRpc.

private <V> void internalCallAsyncWithRpc(final Endpoint endpoint, final BaseRequest request, final FailoverClosure<V> closure) {
    final InvokeContext invokeCtx = new InvokeContext();
    invokeCtx.put(BoltRpcClient.BOLT_CTX, ExtSerializerSupports.getInvokeContext());
    final InvokeCallback invokeCallback = new InvokeCallback() {

        @Override
        public void complete(final Object result, final Throwable err) {
            if (err == null) {
                final BaseResponse<?> response = (BaseResponse<?>) result;
                if (response.isSuccess()) {
                    closure.setData(response.getValue());
                    closure.run(Status.OK());
                } else {
                    closure.setError(response.getError());
                    closure.run(new Status(-1, "RPC failed with address: %s, response: %s", endpoint, response));
                }
            } else {
                closure.failure(err);
            }
        }

        @Override
        public Executor executor() {
            return rpcCallbackExecutor;
        }
    };
    try {
        this.rpcClient.invokeAsync(endpoint, request, invokeCtx, invokeCallback, this.rpcTimeoutMillis);
    } catch (final Throwable t) {
        closure.failure(t);
    }
}
Also used : Status(io.dingodb.raft.Status) BaseResponse(io.dingodb.store.row.cmd.store.BaseResponse) InvokeContext(io.dingodb.raft.rpc.InvokeContext) InvokeCallback(io.dingodb.raft.rpc.InvokeCallback)

Example 2 with BaseResponse

use of io.dingodb.store.row.cmd.store.BaseResponse in project dingo by dingodb.

the class KVCommandProcessor method handleRequest.

@Override
public void handleRequest(final RpcContext rpcCtx, final T request) {
    Requires.requireNonNull(request, "request");
    final RequestProcessClosure<BaseRequest, BaseResponse<?>> closure = new RequestProcessClosure<>(request, rpcCtx);
    final RegionKVService regionKVService = this.storeEngine.getRegionKVService(request.getRegionId());
    if (regionKVService == null) {
        final NoRegionFoundResponse noRegion = new NoRegionFoundResponse();
        noRegion.setRegionId(request.getRegionId());
        noRegion.setError(Errors.NO_REGION_FOUND);
        noRegion.setValue(false);
        closure.sendResponse(noRegion);
        return;
    }
    switch(request.magic()) {
        case BaseRequest.PUT:
            regionKVService.handlePutRequest((PutRequest) request, closure);
            break;
        case BaseRequest.BATCH_PUT:
            regionKVService.handleBatchPutRequest((BatchPutRequest) request, closure);
            break;
        case BaseRequest.PUT_IF_ABSENT:
            regionKVService.handlePutIfAbsentRequest((PutIfAbsentRequest) request, closure);
            break;
        case BaseRequest.GET_PUT:
            regionKVService.handleGetAndPutRequest((GetAndPutRequest) request, closure);
            break;
        case BaseRequest.COMPARE_PUT:
            regionKVService.handleCompareAndPutRequest((CompareAndPutRequest) request, closure);
            break;
        case BaseRequest.DELETE:
            regionKVService.handleDeleteRequest((DeleteRequest) request, closure);
            break;
        case BaseRequest.DELETE_RANGE:
            regionKVService.handleDeleteRangeRequest((DeleteRangeRequest) request, closure);
            break;
        case BaseRequest.BATCH_DELETE:
            regionKVService.handleBatchDeleteRequest((BatchDeleteRequest) request, closure);
            break;
        case BaseRequest.MERGE:
            regionKVService.handleMergeRequest((MergeRequest) request, closure);
            break;
        case BaseRequest.GET:
            regionKVService.handleGetRequest((GetRequest) request, closure);
            break;
        case BaseRequest.MULTI_GET:
            regionKVService.handleMultiGetRequest((MultiGetRequest) request, closure);
            break;
        case BaseRequest.CONTAINS_KEY:
            regionKVService.handleContainsKeyRequest((ContainsKeyRequest) request, closure);
            break;
        case BaseRequest.SCAN:
            regionKVService.handleScanRequest((ScanRequest) request, closure);
            break;
        case BaseRequest.GET_SEQUENCE:
            regionKVService.handleGetSequence((GetSequenceRequest) request, closure);
            break;
        case BaseRequest.RESET_SEQUENCE:
            regionKVService.handleResetSequence((ResetSequenceRequest) request, closure);
            break;
        case BaseRequest.KEY_LOCK:
            regionKVService.handleKeyLockRequest((KeyLockRequest) request, closure);
            break;
        case BaseRequest.KEY_UNLOCK:
            regionKVService.handleKeyUnlockRequest((KeyUnlockRequest) request, closure);
            break;
        case BaseRequest.NODE_EXECUTE:
            regionKVService.handleNodeExecuteRequest((NodeExecuteRequest) request, closure);
            break;
        case BaseRequest.RANGE_SPLIT:
            regionKVService.handleRangeSplitRequest((RangeSplitRequest) request, closure);
            break;
        case BaseRequest.COMPARE_PUT_ALL:
            regionKVService.handleCompareAndPutAll((CASAllRequest) request, closure);
            break;
        default:
            throw new DingoRowStoreRuntimeException("Unsupported request type: " + request.getClass().getName());
    }
}
Also used : BaseResponse(io.dingodb.store.row.cmd.store.BaseResponse) NoRegionFoundResponse(io.dingodb.store.row.cmd.store.NoRegionFoundResponse) BaseRequest(io.dingodb.store.row.cmd.store.BaseRequest) DingoRowStoreRuntimeException(io.dingodb.store.row.errors.DingoRowStoreRuntimeException)

Example 3 with BaseResponse

use of io.dingodb.store.row.cmd.store.BaseResponse in project dingo by dingodb.

the class DefaultDingoRowStoreCliService method rangeSplit.

@Override
public Status rangeSplit(final String regionId, final String newRegionId, final String groupId, final Configuration conf) {
    final PeerId leaderId = new PeerId();
    final Status st = this.cliService.getLeader(groupId, conf, leaderId);
    if (!st.isOk()) {
        throw new IllegalStateException(st.getErrorMsg());
    }
    final RangeSplitRequest request = new RangeSplitRequest();
    request.setRegionId(regionId);
    request.setNewRegionId(newRegionId);
    try {
        final BaseResponse<?> response = (BaseResponse<?>) this.rpcClient.invokeSync(leaderId.getEndpoint(), request, this.opts.getTimeoutMs());
        if (response.isSuccess()) {
            return Status.OK();
        }
        return new Status(-1, "Fail to range split on region %d, error: %s", regionId, response);
    } catch (final Exception e) {
        LOG.error("Fail to range split on exception: {}.", StackTraceUtil.stackTrace(e));
        return new Status(-1, "fail to range split on region %d", regionId);
    }
}
Also used : Status(io.dingodb.raft.Status) BaseResponse(io.dingodb.store.row.cmd.store.BaseResponse) RangeSplitRequest(io.dingodb.store.row.cmd.store.RangeSplitRequest) PeerId(io.dingodb.raft.entity.PeerId)

Aggregations

BaseResponse (io.dingodb.store.row.cmd.store.BaseResponse)3 Status (io.dingodb.raft.Status)2 PeerId (io.dingodb.raft.entity.PeerId)1 InvokeCallback (io.dingodb.raft.rpc.InvokeCallback)1 InvokeContext (io.dingodb.raft.rpc.InvokeContext)1 BaseRequest (io.dingodb.store.row.cmd.store.BaseRequest)1 NoRegionFoundResponse (io.dingodb.store.row.cmd.store.NoRegionFoundResponse)1 RangeSplitRequest (io.dingodb.store.row.cmd.store.RangeSplitRequest)1 DingoRowStoreRuntimeException (io.dingodb.store.row.errors.DingoRowStoreRuntimeException)1