use of io.dingodb.store.row.metadata.Region in project dingo by dingodb.
the class DefaultDingoRowStore method internalResetSequence.
private void internalResetSequence(final byte[] seqKey, final CompletableFuture<Boolean> future, final int retriesLeft, final Errors lastCause) {
final Region region = this.pdClient.findRegionByKey(seqKey, ErrorsHelper.isInvalidEpoch(lastCause));
final RegionEngine regionEngine = getRegionEngine(region.getId(), true);
final RetryRunner retryRunner = retryCause -> internalResetSequence(seqKey, future, retriesLeft - 1, retryCause);
final FailoverClosure<Boolean> closure = new FailoverClosureImpl<>(future, retriesLeft, retryRunner);
if (regionEngine != null) {
if (ensureOnValidEpoch(region, regionEngine, closure)) {
getRawKVStore(regionEngine).resetSequence(seqKey, closure);
}
} else {
final ResetSequenceRequest request = new ResetSequenceRequest();
request.setSeqKey(seqKey);
request.setRegionId(region.getId());
request.setRegionEpoch(region.getRegionEpoch());
this.dingoRowStoreRpcService.callAsyncWithRpc(request, closure, lastCause);
}
}
use of io.dingodb.store.row.metadata.Region in project dingo by dingodb.
the class DefaultDingoRowStore method internalDeleteRange.
private FutureGroup<Boolean> internalDeleteRange(final byte[] startKey, final byte[] endKey, final int retriesLeft, final Throwable lastCause) {
final List<Region> regionList = this.pdClient.findRegionsByKeyRange(startKey, endKey, ApiExceptionHelper.isInvalidEpoch(lastCause));
final List<CompletableFuture<Boolean>> 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 : BytesUtil.min(regionEndKey, endKey);
final RetryCallable<Boolean> retryCallable = retryCause -> internalDeleteRange(subStartKey, subEndKey, retriesLeft - 1, retryCause);
final BoolFailoverFuture future = new BoolFailoverFuture(retriesLeft, retryCallable);
internalRegionDeleteRange(region, subStartKey, subEndKey, future, retriesLeft, lastError);
futures.add(future);
}
return new FutureGroup<>(futures);
}
use of io.dingodb.store.row.metadata.Region 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);
}
}
use of io.dingodb.store.row.metadata.Region in project dingo by dingodb.
the class DefaultDingoRowStore method internalPut.
private void internalPut(final byte[] key, final byte[] value, final CompletableFuture<Boolean> future, final int retriesLeft, final Errors lastCause) {
final Region region = this.pdClient.findRegionByKey(key, ErrorsHelper.isInvalidEpoch(lastCause));
final RegionEngine regionEngine = getRegionEngine(region.getId(), true);
final RetryRunner retryRunner = retryCause -> internalPut(key, value, future, retriesLeft - 1, retryCause);
final FailoverClosure<Boolean> closure = new FailoverClosureImpl<>(future, retriesLeft, retryRunner);
if (regionEngine != null) {
if (ensureOnValidEpoch(region, regionEngine, closure)) {
getRawKVStore(regionEngine).put(key, value, closure);
}
} else {
final PutRequest request = new PutRequest();
request.setKey(key);
request.setValue(value);
request.setRegionId(region.getId());
request.setRegionEpoch(region.getRegionEpoch());
this.dingoRowStoreRpcService.callAsyncWithRpc(request, closure, lastCause);
}
}
use of io.dingodb.store.row.metadata.Region in project dingo by dingodb.
the class DefaultDingoRowStore method internalContainsKey.
private void internalContainsKey(final byte[] key, final CompletableFuture<Boolean> future, final int retriesLeft, final Errors lastCause) {
final Region region = this.pdClient.findRegionByKey(key, ErrorsHelper.isInvalidEpoch(lastCause));
final RegionEngine regionEngine = getRegionEngine(region.getId(), true);
final RetryRunner retryRunner = retryCause -> internalContainsKey(key, future, retriesLeft - 1, retryCause);
final FailoverClosure<Boolean> closure = new FailoverClosureImpl<>(future, retriesLeft, retryRunner);
if (regionEngine != null) {
if (ensureOnValidEpoch(region, regionEngine, closure)) {
getRawKVStore(regionEngine).containsKey(key, closure);
}
} else {
final ContainsKeyRequest request = new ContainsKeyRequest();
request.setKey(key);
request.setRegionId(region.getId());
request.setRegionEpoch(region.getRegionEpoch());
this.dingoRowStoreRpcService.callAsyncWithRpc(request, closure, lastCause);
}
}
Aggregations