Search in sources :

Example 11 with BaseKVStoreClosure

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

the class InstructionProcessor method processSplit.

private boolean processSplit(final Instruction instruction) {
    try {
        final Instruction.RangeSplit rangeSplit = instruction.getRangeSplit();
        if (rangeSplit == null) {
            return false;
        }
        final String newRegionId = rangeSplit.getNewRegionId();
        if (newRegionId == null) {
            LOG.error("RangeSplit#newRegionId must not be null, {}.", instruction);
            return false;
        }
        final Region region = instruction.getRegion();
        final String regionId = region.getId();
        final RegionEngine engine = this.storeEngine.getRegionEngine(regionId);
        if (engine == null) {
            LOG.error("Could not found regionEngine, {}.", instruction);
            return false;
        }
        if (!region.equals(engine.getRegion())) {
            LOG.warn("Instruction [{}] is out of date.", instruction);
            return false;
        }
        final CompletableFuture<Status> future = new CompletableFuture<>();
        this.storeEngine.applySplit(regionId, newRegionId, new BaseKVStoreClosure() {

            @Override
            public void run(Status status) {
                future.complete(status);
            }
        });
        final Status status = future.get(20, TimeUnit.SECONDS);
        final boolean ret = status.isOk();
        if (ret) {
            LOG.info("Range-split succeeded, instruction: {}.", instruction);
        } else {
            LOG.warn("Range-split failed: {}, instruction: {}.", status, instruction);
        }
        return ret;
    } catch (final Throwable t) {
        LOG.error("Caught an exception on #processSplit: {}.", StackTraceUtil.stackTrace(t));
        return false;
    }
}
Also used : Status(io.dingodb.raft.Status) CompletableFuture(java.util.concurrent.CompletableFuture) BaseKVStoreClosure(io.dingodb.store.row.storage.BaseKVStoreClosure) Region(io.dingodb.store.row.metadata.Region) RegionEngine(io.dingodb.store.row.RegionEngine) Instruction(io.dingodb.store.row.metadata.Instruction)

Example 12 with BaseKVStoreClosure

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

the class DefaultRegionKVService method handleGetAndPutRequest.

@Override
public void handleGetAndPutRequest(final GetAndPutRequest request, final RequestProcessClosure<BaseRequest, BaseResponse<?>> closure) {
    final GetAndPutResponse response = new GetAndPutResponse();
    response.setRegionId(getRegionId());
    response.setRegionEpoch(getRegionEpoch());
    try {
        KVParameterRequires.requireSameEpoch(request, getRegionEpoch());
        final byte[] key = KVParameterRequires.requireNonNull(request.getKey(), "getAndPut.key");
        final byte[] value = KVParameterRequires.requireNonNull(request.getValue(), "getAndPut.value");
        this.rawKVStore.getAndPut(key, value, new BaseKVStoreClosure() {

            @Override
            public void run(final Status status) {
                if (status.isOk()) {
                    response.setValue((byte[]) 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) GetAndPutResponse(io.dingodb.store.row.cmd.store.GetAndPutResponse)

Example 13 with BaseKVStoreClosure

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

the class DefaultRegionKVService method handleScanRequest.

@Override
public void handleScanRequest(final ScanRequest request, final RequestProcessClosure<BaseRequest, BaseResponse<?>> closure) {
    final ScanResponse response = new ScanResponse();
    response.setRegionId(getRegionId());
    response.setRegionEpoch(getRegionEpoch());
    try {
        KVParameterRequires.requireSameEpoch(request, getRegionEpoch());
        final BaseKVStoreClosure kvStoreClosure = new BaseKVStoreClosure() {

            @SuppressWarnings("unchecked")
            @Override
            public void run(final Status status) {
                if (status.isOk()) {
                    response.setValue((List<KVEntry>) getData());
                } else {
                    setFailure(request, response, status, getError());
                }
                closure.sendResponse(response);
            }
        };
        if (request.isReverse()) {
            this.rawKVStore.reverseScan(request.getStartKey(), request.getEndKey(), request.getLimit(), request.isReadOnlySafe(), request.isReturnValue(), kvStoreClosure);
        } else {
            this.rawKVStore.scan(request.getStartKey(), request.getEndKey(), request.getLimit(), request.isReadOnlySafe(), request.isReturnValue(), kvStoreClosure);
        }
    } 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) KVEntry(io.dingodb.store.row.storage.KVEntry) BaseKVStoreClosure(io.dingodb.store.row.storage.BaseKVStoreClosure) ScanResponse(io.dingodb.store.row.cmd.store.ScanResponse)

Example 14 with BaseKVStoreClosure

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

the class DefaultRegionKVService method handleBatchPutRequest.

@Override
public void handleBatchPutRequest(final BatchPutRequest request, final RequestProcessClosure<BaseRequest, BaseResponse<?>> closure) {
    final BatchPutResponse response = new BatchPutResponse();
    response.setRegionId(getRegionId());
    response.setRegionEpoch(getRegionEpoch());
    try {
        KVParameterRequires.requireSameEpoch(request, getRegionEpoch());
        final List<KVEntry> kvEntries = KVParameterRequires.requireNonEmpty(request.getKvEntries(), "put.kvEntries");
        this.rawKVStore.put(kvEntries, 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) KVEntry(io.dingodb.store.row.storage.KVEntry) BatchPutResponse(io.dingodb.store.row.cmd.store.BatchPutResponse) BaseKVStoreClosure(io.dingodb.store.row.storage.BaseKVStoreClosure)

Example 15 with BaseKVStoreClosure

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

the class DefaultRegionKVService method handleDeleteRequest.

@Override
public void handleDeleteRequest(final DeleteRequest request, final RequestProcessClosure<BaseRequest, BaseResponse<?>> closure) {
    final DeleteResponse response = new DeleteResponse();
    response.setRegionId(getRegionId());
    response.setRegionEpoch(getRegionEpoch());
    try {
        KVParameterRequires.requireSameEpoch(request, getRegionEpoch());
        final byte[] key = KVParameterRequires.requireNonNull(request.getKey(), "delete.key");
        this.rawKVStore.delete(key, 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) BatchDeleteResponse(io.dingodb.store.row.cmd.store.BatchDeleteResponse) DeleteResponse(io.dingodb.store.row.cmd.store.DeleteResponse) BaseKVStoreClosure(io.dingodb.store.row.storage.BaseKVStoreClosure)

Aggregations

Status (io.dingodb.raft.Status)21 BaseKVStoreClosure (io.dingodb.store.row.storage.BaseKVStoreClosure)21 BatchDeleteResponse (io.dingodb.store.row.cmd.store.BatchDeleteResponse)2 BatchPutResponse (io.dingodb.store.row.cmd.store.BatchPutResponse)2 CompareAndPutResponse (io.dingodb.store.row.cmd.store.CompareAndPutResponse)2 GetAndPutResponse (io.dingodb.store.row.cmd.store.GetAndPutResponse)2 MultiGetResponse (io.dingodb.store.row.cmd.store.MultiGetResponse)2 KVEntry (io.dingodb.store.row.storage.KVEntry)2 DistributedLock (io.dingodb.store.row.util.concurrent.DistributedLock)2 RegionEngine (io.dingodb.store.row.RegionEngine)1 CASAllResponse (io.dingodb.store.row.cmd.store.CASAllResponse)1 ContainsKeyResponse (io.dingodb.store.row.cmd.store.ContainsKeyResponse)1 DeleteRangeResponse (io.dingodb.store.row.cmd.store.DeleteRangeResponse)1 DeleteResponse (io.dingodb.store.row.cmd.store.DeleteResponse)1 GetResponse (io.dingodb.store.row.cmd.store.GetResponse)1 GetSequenceResponse (io.dingodb.store.row.cmd.store.GetSequenceResponse)1 KeyLockResponse (io.dingodb.store.row.cmd.store.KeyLockResponse)1 KeyUnlockResponse (io.dingodb.store.row.cmd.store.KeyUnlockResponse)1 MergeResponse (io.dingodb.store.row.cmd.store.MergeResponse)1 NodeExecuteResponse (io.dingodb.store.row.cmd.store.NodeExecuteResponse)1