Search in sources :

Example 1 with LockCancelledException

use of com.twitter.distributedlog.exceptions.LockCancelledException in project distributedlog by twitter.

the class BKLogReadHandler method ensureReadLockPathExist.

private Future<Void> ensureReadLockPathExist() {
    final Promise<Void> promise = new Promise<Void>();
    promise.setInterruptHandler(new com.twitter.util.Function<Throwable, BoxedUnit>() {

        @Override
        public BoxedUnit apply(Throwable t) {
            FutureUtils.setException(promise, new LockCancelledException(readLockPath, "Could not ensure read lock path", t));
            return null;
        }
    });
    Optional<String> parentPathShouldNotCreate = Optional.of(logMetadata.getLogRootPath());
    Utils.zkAsyncCreateFullPathOptimisticRecursive(zooKeeperClient, readLockPath, parentPathShouldNotCreate, new byte[0], zooKeeperClient.getDefaultACL(), CreateMode.PERSISTENT, new org.apache.zookeeper.AsyncCallback.StringCallback() {

        @Override
        public void processResult(final int rc, final String path, Object ctx, String name) {
            scheduler.submit(new Runnable() {

                @Override
                public void run() {
                    if (KeeperException.Code.NONODE.intValue() == rc) {
                        FutureUtils.setException(promise, new LogNotFoundException(String.format("Log %s does not exist or has been deleted", getFullyQualifiedName())));
                    } else if (KeeperException.Code.OK.intValue() == rc) {
                        FutureUtils.setValue(promise, null);
                        LOG.trace("Created path {}.", path);
                    } else if (KeeperException.Code.NODEEXISTS.intValue() == rc) {
                        FutureUtils.setValue(promise, null);
                        LOG.trace("Path {} is already existed.", path);
                    } else if (DistributedLogConstants.ZK_CONNECTION_EXCEPTION_RESULT_CODE == rc) {
                        FutureUtils.setException(promise, new ZooKeeperClient.ZooKeeperConnectionException(path));
                    } else if (DistributedLogConstants.DL_INTERRUPTED_EXCEPTION_RESULT_CODE == rc) {
                        FutureUtils.setException(promise, new DLInterruptedException(path));
                    } else {
                        FutureUtils.setException(promise, KeeperException.create(KeeperException.Code.get(rc)));
                    }
                }
            });
        }
    }, null);
    return promise;
}
Also used : LockCancelledException(com.twitter.distributedlog.exceptions.LockCancelledException) Promise(com.twitter.util.Promise) SafeRunnable(org.apache.bookkeeper.util.SafeRunnable) DLInterruptedException(com.twitter.distributedlog.exceptions.DLInterruptedException) BoxedUnit(scala.runtime.BoxedUnit) LogNotFoundException(com.twitter.distributedlog.exceptions.LogNotFoundException)

Aggregations

DLInterruptedException (com.twitter.distributedlog.exceptions.DLInterruptedException)1 LockCancelledException (com.twitter.distributedlog.exceptions.LockCancelledException)1 LogNotFoundException (com.twitter.distributedlog.exceptions.LogNotFoundException)1 Promise (com.twitter.util.Promise)1 SafeRunnable (org.apache.bookkeeper.util.SafeRunnable)1 BoxedUnit (scala.runtime.BoxedUnit)1