Search in sources :

Example 11 with RegionException

use of com.pingcap.tikv.exception.RegionException in project tispark by pingcap.

the class LockResolverClientV2 method getTxnStatus.

private Long getTxnStatus(BackOffer bo, Long txnID, ByteString primary) {
    Long status = getResolved(txnID);
    if (status != null) {
        return status;
    }
    while (true) {
        // refresh region
        region = regionManager.getRegionByKey(primary);
        Supplier<CleanupRequest> factory = () -> CleanupRequest.newBuilder().setContext(region.getContext()).setKey(primary).setStartVersion(txnID).build();
        KVErrorHandler<CleanupResponse> handler = new KVErrorHandler<>(regionManager, this, this, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> resp.hasError() ? resp.getError() : null, resolveLockResult -> null, 0L, false);
        CleanupResponse resp = callWithRetry(bo, TikvGrpc.getKvCleanupMethod(), factory, handler);
        status = 0L;
        if (resp == null) {
            logger.error("getKvCleanupMethod failed without a cause");
            regionManager.onRequestFail(region);
            bo.doBackOff(BoRegionMiss, new TiClientInternalException("getKvCleanupMethod failed without a cause"));
            continue;
        }
        if (resp.hasRegionError()) {
            bo.doBackOff(BoRegionMiss, new RegionException(resp.getRegionError()));
            continue;
        }
        if (resp.hasError()) {
            logger.error(String.format("unexpected cleanup err: %s, tid: %d", resp.getError(), txnID));
            throw new KeyException(resp.getError());
        }
        if (resp.getCommitVersion() != 0) {
            status = resp.getCommitVersion();
        }
        saveResolved(txnID, status);
        return status;
    }
}
Also used : CleanupResponse(org.tikv.kvproto.Kvrpcpb.CleanupResponse) TiClientInternalException(com.pingcap.tikv.exception.TiClientInternalException) CleanupRequest(org.tikv.kvproto.Kvrpcpb.CleanupRequest) KVErrorHandler(com.pingcap.tikv.operation.KVErrorHandler) RegionException(com.pingcap.tikv.exception.RegionException) KeyException(com.pingcap.tikv.exception.KeyException)

Aggregations

RegionException (com.pingcap.tikv.exception.RegionException)11 KeyException (com.pingcap.tikv.exception.KeyException)9 TiClientInternalException (com.pingcap.tikv.exception.TiClientInternalException)9 KVErrorHandler (com.pingcap.tikv.operation.KVErrorHandler)7 Kvrpcpb (org.tikv.kvproto.Kvrpcpb)5 RegionStoreClient (com.pingcap.tikv.region.RegionStoreClient)4 TiRegion (com.pingcap.tikv.region.TiRegion)4 AbstractRegionStoreClient (com.pingcap.tikv.region.AbstractRegionStoreClient)2 Lock (com.pingcap.tikv.txn.Lock)2 ResolveLockResult (com.pingcap.tikv.txn.ResolveLockResult)2 BoTxnLock (com.pingcap.tikv.util.BackOffFunction.BackOffFuncType.BoTxnLock)2 BackOffer (com.pingcap.tikv.util.BackOffer)2 ConcreteBackOffer (com.pingcap.tikv.util.ConcreteBackOffer)2 ArrayList (java.util.ArrayList)2 CleanupRequest (org.tikv.kvproto.Kvrpcpb.CleanupRequest)2 CleanupResponse (org.tikv.kvproto.Kvrpcpb.CleanupResponse)2 ByteString (com.google.protobuf.ByteString)1 TiKVException (com.pingcap.tikv.exception.TiKVException)1 TxnNotFoundException (com.pingcap.tikv.exception.TxnNotFoundException)1 KeyError (org.tikv.kvproto.Kvrpcpb.KeyError)1