Search in sources :

Example 1 with PDErrorHandler

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

use of com.pingcap.tikv.operation.PDErrorHandler 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 3 with PDErrorHandler

use of com.pingcap.tikv.operation.PDErrorHandler in project tispark by pingcap.

the class PDClient method getTimestamp.

@Override
public TiTimestamp getTimestamp(BackOffer backOffer) {
    Supplier<TsoRequest> request = () -> tsoReq;
    PDErrorHandler<TsoResponse> handler = new PDErrorHandler<>(r -> r.getHeader().hasError() ? buildFromPdpbError(r.getHeader().getError()) : null, this);
    TsoResponse resp = callWithRetry(backOffer, PDGrpc.getTsoMethod(), request, handler);
    Timestamp timestamp = resp.getTimestamp();
    return new TiTimestamp(timestamp.getPhysical(), timestamp.getLogical());
}
Also used : TiTimestamp(com.pingcap.tikv.meta.TiTimestamp) PDErrorHandler(com.pingcap.tikv.operation.PDErrorHandler) TsoResponse(org.tikv.kvproto.Pdpb.TsoResponse) Timestamp(org.tikv.kvproto.Pdpb.Timestamp) TiTimestamp(com.pingcap.tikv.meta.TiTimestamp) TsoRequest(org.tikv.kvproto.Pdpb.TsoRequest)

Example 4 with PDErrorHandler

use of com.pingcap.tikv.operation.PDErrorHandler 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 5 with PDErrorHandler

use of com.pingcap.tikv.operation.PDErrorHandler in project tispark by pingcap.

the class PDClient method scatterRegion.

/**
 * Sends request to pd to scatter region.
 *
 * @param region represents a region info
 */
void scatterRegion(TiRegion region, BackOffer backOffer) {
    Supplier<ScatterRegionRequest> request = () -> ScatterRegionRequest.newBuilder().setHeader(header).setRegionId(region.getId()).build();
    PDErrorHandler<ScatterRegionResponse> handler = new PDErrorHandler<>(r -> r.getHeader().hasError() ? buildFromPdpbError(r.getHeader().getError()) : null, this);
    ScatterRegionResponse resp = callWithRetry(backOffer, PDGrpc.getScatterRegionMethod(), request, handler);
    // TODO: maybe we should retry here, need dig into pd's codebase.
    if (resp.hasHeader() && resp.getHeader().hasError()) {
        throw new TiClientInternalException(String.format("failed to scatter region because %s", resp.getHeader().getError()));
    }
}
Also used : ScatterRegionRequest(org.tikv.kvproto.Pdpb.ScatterRegionRequest) TiClientInternalException(com.pingcap.tikv.exception.TiClientInternalException) ScatterRegionResponse(org.tikv.kvproto.Pdpb.ScatterRegionResponse) PDErrorHandler(com.pingcap.tikv.operation.PDErrorHandler)

Aggregations

PDErrorHandler (com.pingcap.tikv.operation.PDErrorHandler)6 TiRegion (com.pingcap.tikv.region.TiRegion)4 GetRegionResponse (org.tikv.kvproto.Pdpb.GetRegionResponse)4 FutureObserver (com.pingcap.tikv.util.FutureObserver)2 GetRegionByIDRequest (org.tikv.kvproto.Pdpb.GetRegionByIDRequest)2 GetRegionRequest (org.tikv.kvproto.Pdpb.GetRegionRequest)2 ByteString (com.google.protobuf.ByteString)1 CodecDataOutput (com.pingcap.tikv.codec.CodecDataOutput)1 TiClientInternalException (com.pingcap.tikv.exception.TiClientInternalException)1 TiTimestamp (com.pingcap.tikv.meta.TiTimestamp)1 ScatterRegionRequest (org.tikv.kvproto.Pdpb.ScatterRegionRequest)1 ScatterRegionResponse (org.tikv.kvproto.Pdpb.ScatterRegionResponse)1 Timestamp (org.tikv.kvproto.Pdpb.Timestamp)1 TsoRequest (org.tikv.kvproto.Pdpb.TsoRequest)1 TsoResponse (org.tikv.kvproto.Pdpb.TsoResponse)1