Search in sources :

Example 1 with ScatterRegionRequest

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

Example 2 with ScatterRegionRequest

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

the class PDClient method scatterRegion.

/**
 * Sends request to pd to scatter region.
 *
 * @param region represents a region info
 */
void scatterRegion(Metapb.Region 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(org.tikv.common.exception.TiClientInternalException) ScatterRegionResponse(org.tikv.kvproto.Pdpb.ScatterRegionResponse) PDErrorHandler(org.tikv.common.operation.PDErrorHandler)

Aggregations

ScatterRegionRequest (org.tikv.kvproto.Pdpb.ScatterRegionRequest)2 ScatterRegionResponse (org.tikv.kvproto.Pdpb.ScatterRegionResponse)2 TiClientInternalException (com.pingcap.tikv.exception.TiClientInternalException)1 PDErrorHandler (com.pingcap.tikv.operation.PDErrorHandler)1 TiClientInternalException (org.tikv.common.exception.TiClientInternalException)1 PDErrorHandler (org.tikv.common.operation.PDErrorHandler)1