use of org.tikv.common.operation.KVErrorHandler in project client-java by tikv.
the class RegionStoreClient method scan.
public List<KvPair> scan(BackOffer backOffer, ByteString startKey, long version, boolean keyOnly) {
boolean forWrite = false;
while (true) {
// we should refresh region
region = regionManager.getRegionByKey(startKey, backOffer);
Supplier<ScanRequest> request = () -> ScanRequest.newBuilder().setContext(makeContext(getResolvedLocks(version), this.storeType, backOffer.getSlowLog())).setStartKey(startKey).setVersion(version).setKeyOnly(keyOnly).setLimit(getConf().getScanBatchSize()).build();
KVErrorHandler<ScanResponse> handler = new KVErrorHandler<>(regionManager, this, lockResolverClient, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> null, resolveLockResult -> addResolvedLocks(version, resolveLockResult.getResolvedLocks()), version, forWrite);
ScanResponse resp = callWithRetry(backOffer, TikvGrpc.getKvScanMethod(), request, handler);
if (isScanSuccess(backOffer, resp)) {
return doScan(resp);
}
}
}
use of org.tikv.common.operation.KVErrorHandler in project client-java by tikv.
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(makeContext(getResolvedLocks(version), this.storeType, backOffer.getSlowLog())).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 org.tikv.common.operation.KVErrorHandler in project client-java by tikv.
the class RegionStoreClient method txnHeartBeat.
/**
* TXN Heart Beat: update primary key ttl
*/
public void txnHeartBeat(BackOffer bo, ByteString primaryLock, long startTs, long ttl) {
boolean forWrite = false;
while (true) {
Supplier<TxnHeartBeatRequest> factory = () -> TxnHeartBeatRequest.newBuilder().setContext(makeContext(storeType, bo.getSlowLog())).setStartVersion(startTs).setPrimaryLock(primaryLock).setAdviseLockTtl(ttl).build();
KVErrorHandler<TxnHeartBeatResponse> handler = new KVErrorHandler<>(regionManager, this, lockResolverClient, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> resp.hasError() ? resp.getError() : null, resolveLockResult -> null, startTs, forWrite);
TxnHeartBeatResponse resp = callWithRetry(bo, TikvGrpc.getKvTxnHeartBeatMethod(), factory, handler);
if (isTxnHeartBeatSuccess(resp)) {
return;
}
}
}
use of org.tikv.common.operation.KVErrorHandler in project client-java by tikv.
the class RegionStoreClient method batchGet.
public List<KvPair> batchGet(BackOffer backOffer, Iterable<ByteString> keys, long version) {
boolean forWrite = false;
Supplier<BatchGetRequest> request = () -> BatchGetRequest.newBuilder().setContext(makeContext(getResolvedLocks(version), this.storeType, backOffer.getSlowLog())).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);
return handleBatchGetResponse(backOffer, resp, version);
}
use of org.tikv.common.operation.KVErrorHandler in project client-java by tikv.
the class RegionStoreClient method splitRegion.
/**
* Send SplitRegion request to tikv split a region at splitKey. splitKey must between current
* region's start key and end key.
*
* @param splitKeys is the split points for a specific region.
* @return a split region info.
*/
public List<Metapb.Region> splitRegion(Iterable<ByteString> splitKeys) {
Supplier<SplitRegionRequest> request = () -> SplitRegionRequest.newBuilder().setContext(makeContext(storeType, SlowLogEmptyImpl.INSTANCE)).addAllSplitKeys(splitKeys).setIsRawKv(conf.isRawKVMode()).build();
KVErrorHandler<SplitRegionResponse> handler = new KVErrorHandler<>(regionManager, this, null, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> null, resolveLockResult -> null, 0L, false);
SplitRegionResponse resp = callWithRetry(ConcreteBackOffer.newGetBackOff(pdClient.getClusterId()), TikvGrpc.getSplitRegionMethod(), request, handler);
if (resp == null) {
this.regionManager.onRequestFail(region);
throw new TiClientInternalException("SplitRegion Response failed without a cause");
}
if (resp.hasRegionError()) {
throw new TiClientInternalException(String.format("failed to split region %d because %s", region.getId(), resp.getRegionError().toString()));
}
return resp.getRegionsList();
}
Aggregations