Search in sources :

Example 1 with GetRegionRequest

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

Example 2 with GetRegionRequest

use of org.tikv.kvproto.Pdpb.GetRegionRequest in project tispark by pingcap.

the class PDClient method getRegionByKey.

@Override
public TiRegion getRegionByKey(BackOffer backOffer, ByteString key) {
    CodecDataOutput cdo = new CodecDataOutput();
    BytesCodec.writeBytes(cdo, key.toByteArray());
    ByteString encodedKey = cdo.toByteString();
    Supplier<GetRegionRequest> request = () -> GetRegionRequest.newBuilder().setHeader(header).setRegionKey(encodedKey).build();
    PDErrorHandler<GetRegionResponse> handler = new PDErrorHandler<>(getRegionResponseErrorExtractor, this);
    GetRegionResponse resp = callWithRetry(backOffer, PDGrpc.getGetRegionMethod(), request, handler);
    return new TiRegion(resp.getRegion(), resp.getLeader(), conf.getIsolationLevel(), conf.getCommandPriority());
}
Also used : GetRegionResponse(org.tikv.kvproto.Pdpb.GetRegionResponse) ByteString(com.google.protobuf.ByteString) PDErrorHandler(com.pingcap.tikv.operation.PDErrorHandler) TiRegion(com.pingcap.tikv.region.TiRegion) CodecDataOutput(com.pingcap.tikv.codec.CodecDataOutput) GetRegionRequest(org.tikv.kvproto.Pdpb.GetRegionRequest)

Example 3 with GetRegionRequest

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

the class PDClient method getRegionByKey.

@Override
public Pair<Metapb.Region, Metapb.Peer> getRegionByKey(BackOffer backOffer, ByteString key) {
    Histogram.Timer requestTimer = PD_GET_REGION_BY_KEY_REQUEST_LATENCY.labels(getClusterId().toString()).startTimer();
    try {
        if (conf.isTxnKVMode()) {
            CodecDataOutput cdo = new CodecDataOutput();
            BytesCodec.writeBytes(cdo, key.toByteArray());
            key = cdo.toByteString();
        }
        ByteString queryKey = key;
        Supplier<GetRegionRequest> request = () -> GetRegionRequest.newBuilder().setHeader(header).setRegionKey(queryKey).build();
        PDErrorHandler<GetRegionResponse> handler = new PDErrorHandler<>(getRegionResponseErrorExtractor, this);
        GetRegionResponse resp = callWithRetry(backOffer, PDGrpc.getGetRegionMethod(), request, handler);
        return new Pair<Metapb.Region, Metapb.Peer>(decodeRegion(resp.getRegion()), resp.getLeader());
    } finally {
        requestTimer.observeDuration();
    }
}
Also used : Histogram(io.prometheus.client.Histogram) GetRegionResponse(org.tikv.kvproto.Pdpb.GetRegionResponse) ByteString(com.google.protobuf.ByteString) PDErrorHandler(org.tikv.common.operation.PDErrorHandler) CodecDataOutput(org.tikv.common.codec.CodecDataOutput) Metapb(org.tikv.kvproto.Metapb) GetRegionRequest(org.tikv.kvproto.Pdpb.GetRegionRequest) Pair(org.tikv.common.util.Pair)

Aggregations

GetRegionRequest (org.tikv.kvproto.Pdpb.GetRegionRequest)3 GetRegionResponse (org.tikv.kvproto.Pdpb.GetRegionResponse)3 ByteString (com.google.protobuf.ByteString)2 PDErrorHandler (com.pingcap.tikv.operation.PDErrorHandler)2 TiRegion (com.pingcap.tikv.region.TiRegion)2 CodecDataOutput (com.pingcap.tikv.codec.CodecDataOutput)1 FutureObserver (com.pingcap.tikv.util.FutureObserver)1 Histogram (io.prometheus.client.Histogram)1 CodecDataOutput (org.tikv.common.codec.CodecDataOutput)1 PDErrorHandler (org.tikv.common.operation.PDErrorHandler)1 Pair (org.tikv.common.util.Pair)1 Metapb (org.tikv.kvproto.Metapb)1