use of com.pingcap.tikv.region.TiRegion in project tispark by pingcap.
the class CatalogTest method setUp.
@Before
@Override
public void setUp() throws IOException {
super.setUp();
kvServer = new KVMockServer();
kvServer.start(new TiRegion(MetaMockHelper.region, MetaMockHelper.region.getPeers(0), IsolationLevel.RC, CommandPri.Low));
}
use of com.pingcap.tikv.region.TiRegion in project tispark by pingcap.
the class KVClient method doSendBatchGetInBatchesWithRetry.
private Pair<List<Batch>, List<KvPair>> doSendBatchGetInBatchesWithRetry(BackOffer backOffer, Batch batch, long version) {
TiRegion oldRegion = batch.getRegion();
TiRegion currentRegion = clientBuilder.getRegionManager().getRegionByKey(batch.getRegion().getStartKey());
if (oldRegion.equals(currentRegion)) {
RegionStoreClient client = clientBuilder.build(batch.getRegion());
try {
List<KvPair> partialResult = client.batchGet(backOffer, batch.getKeys(), version);
return Pair.create(new ArrayList<>(), partialResult);
} catch (final TiKVException e) {
backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoRegionMiss, e);
clientBuilder.getRegionManager().invalidateRegion(batch.getRegion());
logger.debug("ReSplitting ranges for BatchGetRequest", e);
return doRetryBatchGet(backOffer, batch);
}
} else {
return doRetryBatchGet(backOffer, batch);
}
}
use of com.pingcap.tikv.region.TiRegion in project tispark by pingcap.
the class PDClient method getRegionByID.
@Override
public TiRegion getRegionByID(BackOffer backOffer, long id) {
Supplier<GetRegionByIDRequest> request = () -> GetRegionByIDRequest.newBuilder().setHeader(header).setRegionId(id).build();
PDErrorHandler<GetRegionResponse> handler = new PDErrorHandler<>(getRegionResponseErrorExtractor, this);
GetRegionResponse resp = callWithRetry(backOffer, PDGrpc.getGetRegionByIDMethod(), request, handler);
// Instead of using default leader instance, explicitly set no leader to null
return new TiRegion(resp.getRegion(), resp.getLeader(), conf.getIsolationLevel(), conf.getCommandPriority());
}
use of com.pingcap.tikv.region.TiRegion in project tispark by pingcap.
the class PDClient method getRegionByIDAsync.
@Override
public Future<TiRegion> getRegionByIDAsync(BackOffer backOffer, long id) {
FutureObserver<TiRegion, GetRegionResponse> responseObserver = new FutureObserver<>(resp -> new TiRegion(resp.getRegion(), resp.getLeader(), conf.getIsolationLevel(), conf.getCommandPriority()));
Supplier<GetRegionByIDRequest> request = () -> GetRegionByIDRequest.newBuilder().setHeader(header).setRegionId(id).build();
PDErrorHandler<GetRegionResponse> handler = new PDErrorHandler<>(getRegionResponseErrorExtractor, this);
callAsyncWithRetry(backOffer, PDGrpc.getGetRegionByIDMethod(), request, responseObserver, handler);
return responseObserver.getFuture();
}
use of com.pingcap.tikv.region.TiRegion in project tispark by pingcap.
the class TTLManager method sendTxnHeartBeat.
private void sendTxnHeartBeat(BackOffer bo, long ttl) {
Pair<TiRegion, Metapb.Store> pair = regionManager.getRegionStorePairByKey(primaryLock);
TiRegion tiRegion = pair.first;
Metapb.Store store = pair.second;
ClientRPCResult result = kvClient.txnHeartBeat(bo, primaryLock, startTS, ttl, tiRegion, store);
if (!result.isSuccess() && !result.isRetry()) {
throw new TiBatchWriteException("sendTxnHeartBeat error", result.getException());
}
if (result.isRetry()) {
try {
bo.doBackOff(BackOffFunction.BackOffFuncType.BoRegionMiss, new GrpcException(String.format("sendTxnHeartBeat failed, regionId=%s", tiRegion.getId()), result.getException()));
this.regionManager.invalidateStore(store.getId());
this.regionManager.invalidateRegion(tiRegion);
// re-split keys and commit again.
sendTxnHeartBeat(bo, ttl);
} catch (GrpcException e) {
String errorMsg = String.format("sendTxnHeartBeat error, regionId=%s, detail=%s", tiRegion.getId(), e.getMessage());
throw new TiBatchWriteException(errorMsg, e);
}
}
LOG.debug("sendTxnHeartBeat success key={} ttl={} success", LogDesensitization.hide(KeyUtils.formatBytes(primaryLock)), ttl);
}
Aggregations