Search in sources :

Example 16 with TiRegion

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));
}
Also used : KVMockServer(com.pingcap.tikv.KVMockServer) TiRegion(com.pingcap.tikv.region.TiRegion) Before(org.junit.Before)

Example 17 with TiRegion

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);
    }
}
Also used : KvPair(org.tikv.kvproto.Kvrpcpb.KvPair) TiKVException(com.pingcap.tikv.exception.TiKVException) TiRegion(com.pingcap.tikv.region.TiRegion) RegionStoreClient(com.pingcap.tikv.region.RegionStoreClient)

Example 18 with TiRegion

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());
}
Also used : GetRegionResponse(org.tikv.kvproto.Pdpb.GetRegionResponse) GetRegionByIDRequest(org.tikv.kvproto.Pdpb.GetRegionByIDRequest) PDErrorHandler(com.pingcap.tikv.operation.PDErrorHandler) TiRegion(com.pingcap.tikv.region.TiRegion)

Example 19 with TiRegion

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();
}
Also used : GetRegionResponse(org.tikv.kvproto.Pdpb.GetRegionResponse) GetRegionByIDRequest(org.tikv.kvproto.Pdpb.GetRegionByIDRequest) PDErrorHandler(com.pingcap.tikv.operation.PDErrorHandler) TiRegion(com.pingcap.tikv.region.TiRegion) FutureObserver(com.pingcap.tikv.util.FutureObserver)

Example 20 with TiRegion

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);
}
Also used : TiRegion(com.pingcap.tikv.region.TiRegion) GrpcException(com.pingcap.tikv.exception.GrpcException) ByteString(com.google.protobuf.ByteString) ClientRPCResult(com.pingcap.tikv.txn.type.ClientRPCResult) Metapb(org.tikv.kvproto.Metapb) TiBatchWriteException(com.pingcap.tikv.exception.TiBatchWriteException)

Aggregations

TiRegion (com.pingcap.tikv.region.TiRegion)43 ByteString (com.google.protobuf.ByteString)19 RegionStoreClient (com.pingcap.tikv.region.RegionStoreClient)17 ArrayList (java.util.ArrayList)16 BackOffer (com.pingcap.tikv.util.BackOffer)10 ConcreteBackOffer (com.pingcap.tikv.util.ConcreteBackOffer)10 List (java.util.List)10 Test (org.junit.Test)9 TiKVException (com.pingcap.tikv.exception.TiKVException)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Kvrpcpb (org.tikv.kvproto.Kvrpcpb)8 Metapb (org.tikv.kvproto.Metapb)8 GrpcException (com.pingcap.tikv.exception.GrpcException)7 KeyException (com.pingcap.tikv.exception.KeyException)7 TiClientInternalException (com.pingcap.tikv.exception.TiClientInternalException)6 RegionException (com.pingcap.tikv.exception.RegionException)4 TiBatchWriteException (com.pingcap.tikv.exception.TiBatchWriteException)4 Key (com.pingcap.tikv.key.Key)4 TiTimestamp (com.pingcap.tikv.meta.TiTimestamp)4