Search in sources :

Example 1 with ZkPeekLockException

use of org.apache.kylin.job.lock.zookeeper.exception.ZkPeekLockException in project kylin by apache.

the class ZookeeperDistributedLock method unlock.

@Override
public void unlock(String lockPath) {
    logger.debug("{} trying to unlock {}", client, lockPath);
    // peek owner first
    String owner;
    ZkPeekLockInterruptException peekLockInterruptException = null;
    try {
        owner = peekLock(lockPath);
    } catch (ZkPeekLockInterruptException zie) {
        // re-peek owner of lock when interrupted
        owner = peekLock(lockPath);
        peekLockInterruptException = zie;
    } catch (ZkPeekLockException ze) {
        // this exception should be thrown to diagnose even it may cause unlock failed
        logger.error("{} failed to peekLock when unlock at {}", client, lockPath, ze);
        throw ze;
    }
    // then unlock
    ZkReleaseLockInterruptException unlockInterruptException = null;
    try {
        unlockInternal(owner, lockPath);
    } catch (ZkReleaseLockInterruptException zlie) {
        // re-unlock once when interrupted
        unlockInternal(owner, lockPath);
        unlockInterruptException = zlie;
    } catch (Exception ex) {
        throw new ZkReleaseLockException("Error while " + client + " trying to unlock " + lockPath, ex);
    }
    // need re-throw interrupt exception to avoid swallowing it
    if (peekLockInterruptException != null) {
        throw peekLockInterruptException;
    }
    if (unlockInterruptException != null) {
        throw unlockInterruptException;
    }
}
Also used : ZkPeekLockInterruptException(org.apache.kylin.job.lock.zookeeper.exception.ZkPeekLockInterruptException) ZkReleaseLockInterruptException(org.apache.kylin.job.lock.zookeeper.exception.ZkReleaseLockInterruptException) ZkReleaseLockException(org.apache.kylin.job.lock.zookeeper.exception.ZkReleaseLockException) ZkReleaseLockInterruptException(org.apache.kylin.job.lock.zookeeper.exception.ZkReleaseLockInterruptException) ZkReleaseLockException(org.apache.kylin.job.lock.zookeeper.exception.ZkReleaseLockException) KeeperException(org.apache.zookeeper.KeeperException) ZkPeekLockException(org.apache.kylin.job.lock.zookeeper.exception.ZkPeekLockException) ZkAcquireLockException(org.apache.kylin.job.lock.zookeeper.exception.ZkAcquireLockException) ZkPeekLockInterruptException(org.apache.kylin.job.lock.zookeeper.exception.ZkPeekLockInterruptException) ZkPeekLockException(org.apache.kylin.job.lock.zookeeper.exception.ZkPeekLockException)

Aggregations

ZkAcquireLockException (org.apache.kylin.job.lock.zookeeper.exception.ZkAcquireLockException)1 ZkPeekLockException (org.apache.kylin.job.lock.zookeeper.exception.ZkPeekLockException)1 ZkPeekLockInterruptException (org.apache.kylin.job.lock.zookeeper.exception.ZkPeekLockInterruptException)1 ZkReleaseLockException (org.apache.kylin.job.lock.zookeeper.exception.ZkReleaseLockException)1 ZkReleaseLockInterruptException (org.apache.kylin.job.lock.zookeeper.exception.ZkReleaseLockInterruptException)1 KeeperException (org.apache.zookeeper.KeeperException)1