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;
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations