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;
}
Aggregations