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());
}
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();
}
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());
}
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();
}
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()));
}
}
Aggregations