use of com.pingcap.tikv.operation.KVErrorHandler in project tispark by pingcap.
the class RegionStoreClient method rawBatchPut.
public void rawBatchPut(BackOffer backOffer, List<KvPair> kvPairs, long ttl, boolean atomic) {
if (kvPairs.isEmpty()) {
return;
}
Supplier<RawBatchPutRequest> factory = () -> RawBatchPutRequest.newBuilder().setContext(region.getContext()).addAllPairs(kvPairs).setTtl(ttl).setForCas(atomic).build();
KVErrorHandler<RawBatchPutResponse> handler = new KVErrorHandler<>(regionManager, this, resp -> resp.hasRegionError() ? resp.getRegionError() : null);
RawBatchPutResponse resp = callWithRetry(backOffer, TikvGrpc.getRawBatchPutMethod(), factory, handler);
handleRawBatchPut(resp);
}
use of com.pingcap.tikv.operation.KVErrorHandler in project tispark by pingcap.
the class RegionStoreClient method get.
/**
* Fetch a value according to a key
*
* @param backOffer backOffer
* @param key key to fetch
* @param version key version
* @return value
* @throws TiClientInternalException TiSpark Client exception, unexpected
* @throws KeyException Key may be locked
*/
public ByteString get(BackOffer backOffer, ByteString key, long version) throws TiClientInternalException, KeyException {
boolean forWrite = false;
Supplier<GetRequest> factory = () -> GetRequest.newBuilder().setContext(region.getContext(getResolvedLocks(version))).setKey(key).setVersion(version).build();
KVErrorHandler<GetResponse> handler = new KVErrorHandler<>(regionManager, this, lockResolverClient, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> resp.hasError() ? resp.getError() : null, resolveLockResult -> addResolvedLocks(version, resolveLockResult.getResolvedLocks()), version, forWrite);
GetResponse resp = callWithRetry(backOffer, TikvGrpc.getKvGetMethod(), factory, handler);
handleGetResponse(resp);
return resp.getValue();
}
use of com.pingcap.tikv.operation.KVErrorHandler in project tispark by pingcap.
the class RegionStoreClient method rawBatchGet.
public List<KvPair> rawBatchGet(BackOffer backoffer, List<ByteString> keys) {
if (keys.isEmpty()) {
return new ArrayList<>();
}
Supplier<RawBatchGetRequest> factory = () -> RawBatchGetRequest.newBuilder().setContext(region.getContext()).addAllKeys(keys).build();
KVErrorHandler<RawBatchGetResponse> handler = new KVErrorHandler<>(regionManager, this, resp -> resp.hasRegionError() ? resp.getRegionError() : null);
RawBatchGetResponse resp = callWithRetry(backoffer, TikvGrpc.getRawBatchGetMethod(), factory, handler);
return handleRawBatchGet(resp);
}
use of com.pingcap.tikv.operation.KVErrorHandler in project tispark by pingcap.
the class RegionStoreClient method batchGet.
public List<KvPair> batchGet(BackOffer backOffer, List<ByteString> keys, long version) {
boolean forWrite = false;
Supplier<BatchGetRequest> request = () -> BatchGetRequest.newBuilder().setContext(region.getContext(getResolvedLocks(version))).addAllKeys(keys).setVersion(version).build();
KVErrorHandler<BatchGetResponse> handler = new KVErrorHandler<>(regionManager, this, lockResolverClient, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> null, resolveLockResult -> addResolvedLocks(version, resolveLockResult.getResolvedLocks()), version, forWrite);
BatchGetResponse resp = callWithRetry(backOffer, TikvGrpc.getKvBatchGetMethod(), request, handler);
try {
return handleBatchGetResponse(backOffer, resp, version);
} catch (TiKVException e) {
if ("locks not resolved, retry".equals(e.getMessage())) {
backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoTxnLock, e);
return batchGet(backOffer, keys, version);
} else {
throw e;
}
}
}
use of com.pingcap.tikv.operation.KVErrorHandler in project tispark by pingcap.
the class RegionStoreClient method rawGetKeyTTL.
public Long rawGetKeyTTL(BackOffer backOffer, ByteString key) {
Supplier<RawGetKeyTTLRequest> factory = () -> RawGetKeyTTLRequest.newBuilder().setContext(region.getContext()).setKey(key).build();
KVErrorHandler<RawGetKeyTTLResponse> handler = new KVErrorHandler<>(regionManager, this, resp -> resp.hasRegionError() ? resp.getRegionError() : null);
RawGetKeyTTLResponse resp = callWithRetry(backOffer, TikvGrpc.getRawGetKeyTTLMethod(), factory, handler);
return rawGetKeyTTLHelper(resp);
}
Aggregations