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