Search in sources :

Example 1 with FutureObserver

use of com.pingcap.tikv.util.FutureObserver 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 2 with FutureObserver

use of com.pingcap.tikv.util.FutureObserver in project tispark by pingcap.

the class PDClient method getRegionByKeyAsync.

@Override
public Future<TiRegion> getRegionByKeyAsync(BackOffer backOffer, ByteString key) {
    FutureObserver<TiRegion, GetRegionResponse> responseObserver = new FutureObserver<>(resp -> new TiRegion(resp.getRegion(), resp.getLeader(), conf.getIsolationLevel(), conf.getCommandPriority()));
    Supplier<GetRegionRequest> request = () -> GetRegionRequest.newBuilder().setHeader(header).setRegionKey(key).build();
    PDErrorHandler<GetRegionResponse> handler = new PDErrorHandler<>(getRegionResponseErrorExtractor, this);
    callAsyncWithRetry(backOffer, PDGrpc.getGetRegionMethod(), request, responseObserver, handler);
    return responseObserver.getFuture();
}
Also used : GetRegionResponse(org.tikv.kvproto.Pdpb.GetRegionResponse) PDErrorHandler(com.pingcap.tikv.operation.PDErrorHandler) TiRegion(com.pingcap.tikv.region.TiRegion) FutureObserver(com.pingcap.tikv.util.FutureObserver) GetRegionRequest(org.tikv.kvproto.Pdpb.GetRegionRequest)

Aggregations

PDErrorHandler (com.pingcap.tikv.operation.PDErrorHandler)2 TiRegion (com.pingcap.tikv.region.TiRegion)2 FutureObserver (com.pingcap.tikv.util.FutureObserver)2 GetRegionResponse (org.tikv.kvproto.Pdpb.GetRegionResponse)2 GetRegionByIDRequest (org.tikv.kvproto.Pdpb.GetRegionByIDRequest)1 GetRegionRequest (org.tikv.kvproto.Pdpb.GetRegionRequest)1