Search in sources :

Example 1 with LockException

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

the class RegionStoreClient method handleCopResponse.

// handleCopResponse checks coprocessor Response for region split and lock,
// returns more tasks when that happens, or handles the response if no error.
// if we're handling streaming coprocessor response, lastRange is the range of last
// successful response, otherwise it's nil.
private List<RangeSplitter.RegionTask> handleCopResponse(BackOffer backOffer, Coprocessor.Response response, List<Coprocessor.KeyRange> ranges, Queue<SelectResponse> responseQueue, long startTs) {
    boolean forWrite = false;
    if (response == null) {
        // Send request failed, reasons may:
        // 1. TiKV down
        // 2. Network partition
        backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoRegionMiss, new GrpcException("TiKV down or Network partition"));
        logger.warn("Re-splitting region task due to region error: TiKV down or Network partition");
        // Split ranges
        return RangeSplitter.newSplitter(this.regionManager).splitRangeByRegion(ranges, storeType);
    }
    if (response.hasRegionError()) {
        Errorpb.Error regionError = response.getRegionError();
        backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoRegionMiss, new GrpcException(regionError.toString()));
        logger.warn("Re-splitting region task due to region error:" + regionError.getMessage());
        // Split ranges
        return RangeSplitter.newSplitter(this.regionManager).splitRangeByRegion(ranges, storeType);
    }
    if (response.hasLocked()) {
        Lock lock = new Lock(response.getLocked());
        logger.debug(String.format("coprocessor encounters locks: %s", lock));
        ResolveLockResult resolveLockResult = lockResolverClient.resolveLocks(backOffer, startTs, Collections.singletonList(lock), forWrite);
        addResolvedLocks(startTs, resolveLockResult.getResolvedLocks());
        long msBeforeExpired = resolveLockResult.getMsBeforeTxnExpired();
        if (msBeforeExpired > 0) {
            backOffer.doBackOffWithMaxSleep(BoTxnLockFast, msBeforeExpired, new LockException(lock));
        }
        // Split ranges
        return RangeSplitter.newSplitter(this.regionManager).splitRangeByRegion(ranges, storeType);
    }
    String otherError = response.getOtherError();
    if (!otherError.isEmpty()) {
        logger.warn(String.format("Other error occurred, message: %s", otherError));
        throw new GrpcException(otherError);
    }
    responseQueue.offer(doCoprocessor(response));
    return null;
}
Also used : LockException(com.pingcap.tikv.exception.LockException) GrpcException(com.pingcap.tikv.exception.GrpcException) Errorpb(org.tikv.kvproto.Errorpb) ResolveLockResult(com.pingcap.tikv.txn.ResolveLockResult) ByteString(com.google.protobuf.ByteString) Lock(com.pingcap.tikv.txn.Lock) BoTxnLock(com.pingcap.tikv.util.BackOffFunction.BackOffFuncType.BoTxnLock)

Aggregations

ByteString (com.google.protobuf.ByteString)1 GrpcException (com.pingcap.tikv.exception.GrpcException)1 LockException (com.pingcap.tikv.exception.LockException)1 Lock (com.pingcap.tikv.txn.Lock)1 ResolveLockResult (com.pingcap.tikv.txn.ResolveLockResult)1 BoTxnLock (com.pingcap.tikv.util.BackOffFunction.BackOffFuncType.BoTxnLock)1 Errorpb (org.tikv.kvproto.Errorpb)1