use of com.pingcap.tikv.exception.TiClientInternalException 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()));
}
}
use of com.pingcap.tikv.exception.TiClientInternalException in project tispark by pingcap.
the class CatalogTransaction method parseFromJson.
public static <T> T parseFromJson(ByteString json, Class<T> cls) {
Objects.requireNonNull(json, "json is null");
Objects.requireNonNull(cls, "cls is null");
logger.debug(String.format("Parse Json %s : %s", cls.getSimpleName(), json.toStringUtf8()));
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.readValue(json.toStringUtf8(), cls);
} catch (JsonParseException | JsonMappingException e) {
String errMsg = String.format("Invalid JSON value for Type %s: %s\n", cls.getSimpleName(), json.toStringUtf8());
throw new TiClientInternalException(errMsg, e);
} catch (Exception e1) {
throw new TiClientInternalException("Error parsing Json", e1);
}
}
use of com.pingcap.tikv.exception.TiClientInternalException in project tispark by pingcap.
the class RegionStoreClient method handleBatchGetResponse.
private List<KvPair> handleBatchGetResponse(BackOffer backOffer, BatchGetResponse resp, long version) {
boolean forWrite = false;
if (resp == null) {
this.regionManager.onRequestFail(region);
throw new TiClientInternalException("BatchGetResponse failed without a cause");
}
if (resp.hasRegionError()) {
throw new RegionException(resp.getRegionError());
}
List<Lock> locks = new ArrayList<>();
for (KvPair pair : resp.getPairsList()) {
if (pair.hasError()) {
if (pair.getError().hasLocked()) {
Lock lock = new Lock(pair.getError().getLocked());
locks.add(lock);
} else {
throw new KeyException(pair.getError());
}
}
}
if (!locks.isEmpty()) {
ResolveLockResult resolveLockResult = lockResolverClient.resolveLocks(backOffer, version, locks, forWrite);
addResolvedLocks(version, resolveLockResult.getResolvedLocks());
// resolveLocks already retried, just throw error to upper logic.
throw new TiKVException("locks not resolved, retry");
} else {
return resp.getPairsList();
}
}
use of com.pingcap.tikv.exception.TiClientInternalException in project tispark by pingcap.
the class RegionStoreClient method splitRegion.
/**
* Send SplitRegion request to tikv split a region at splitKey. splitKey must between current
* region's start key and end key.
*
* @param splitKeys is the split points for a specific region.
* @return a split region info.
*/
public List<TiRegion> splitRegion(Iterable<ByteString> splitKeys) {
Supplier<SplitRegionRequest> request = () -> SplitRegionRequest.newBuilder().setContext(region.getContext()).addAllSplitKeys(splitKeys).build();
KVErrorHandler<SplitRegionResponse> handler = new KVErrorHandler<>(regionManager, this, null, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> null, resolveLockResult -> null, 0L, false);
SplitRegionResponse resp = callWithRetry(ConcreteBackOffer.newGetBackOff(), TikvGrpc.getSplitRegionMethod(), request, handler);
if (resp == null) {
this.regionManager.onRequestFail(region);
throw new TiClientInternalException("SplitRegion Response failed without a cause");
}
if (resp.hasRegionError()) {
throw new TiClientInternalException(String.format("failed to split region %d because %s", region.getId(), resp.getRegionError().toString()));
}
return resp.getRegionsList().stream().map(region -> new TiRegion(region, null, conf.getIsolationLevel(), conf.getCommandPriority())).collect(Collectors.toList());
}
use of com.pingcap.tikv.exception.TiClientInternalException in project tispark by pingcap.
the class DAGIterator method processByStreaming.
private Iterator<SelectResponse> processByStreaming(RangeSplitter.RegionTask regionTask) {
List<Coprocessor.KeyRange> ranges = regionTask.getRanges();
TiRegion region = regionTask.getRegion();
Metapb.Store store = regionTask.getStore();
RegionStoreClient client;
try {
client = session.getRegionStoreClientBuilder().build(region, store, storeType);
Iterator<SelectResponse> responseIterator = client.coprocessStreaming(dagRequest, ranges, startTs);
if (responseIterator == null) {
eof = true;
return null;
}
return responseIterator;
} catch (Exception e) {
// see:https://github.com/pingcap/tikv-client-lib-java/pull/149
throw new TiClientInternalException("Error Closing Store client.", e);
}
}
Aggregations