Search in sources :

Example 1 with GetRegionByIDRequest

use of org.tikv.kvproto.Pdpb.GetRegionByIDRequest in project client-java by tikv.

the class PDClient method getRegionByID.

@Override
public Pair<Metapb.Region, Metapb.Peer> 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);
    return new Pair<Metapb.Region, Metapb.Peer>(decodeRegion(resp.getRegion()), resp.getLeader());
}
Also used : GetRegionResponse(org.tikv.kvproto.Pdpb.GetRegionResponse) GetRegionByIDRequest(org.tikv.kvproto.Pdpb.GetRegionByIDRequest) PDErrorHandler(org.tikv.common.operation.PDErrorHandler) Metapb(org.tikv.kvproto.Metapb) Pair(org.tikv.common.util.Pair)

Example 2 with GetRegionByIDRequest

use of org.tikv.kvproto.Pdpb.GetRegionByIDRequest 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 3 with GetRegionByIDRequest

use of org.tikv.kvproto.Pdpb.GetRegionByIDRequest 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)

Aggregations

GetRegionByIDRequest (org.tikv.kvproto.Pdpb.GetRegionByIDRequest)3 GetRegionResponse (org.tikv.kvproto.Pdpb.GetRegionResponse)3 PDErrorHandler (com.pingcap.tikv.operation.PDErrorHandler)2 TiRegion (com.pingcap.tikv.region.TiRegion)2 FutureObserver (com.pingcap.tikv.util.FutureObserver)1 PDErrorHandler (org.tikv.common.operation.PDErrorHandler)1 Pair (org.tikv.common.util.Pair)1 Metapb (org.tikv.kvproto.Metapb)1