use of org.apache.zookeeper.Op.Create in project bookkeeper by apache.
the class ZKLogStreamMetadataStore method executeRenameTxn.
private CompletableFuture<Void> executeRenameTxn(String oldLogPath, String newLogPath, LinkedList<Op> createOps, LinkedList<Op> deleteOps) {
CompletableFuture<Void> future = FutureUtils.createFuture();
List<Op> zkOps = Lists.newArrayListWithExpectedSize(createOps.size() + deleteOps.size());
zkOps.addAll(createOps);
zkOps.addAll(deleteOps);
if (LOG.isDebugEnabled()) {
for (Op op : zkOps) {
if (op instanceof Create) {
Create create = (Create) op;
LOG.debug("op : create {}", create.getPath());
} else if (op instanceof Delete) {
Delete delete = (Delete) op;
LOG.debug("op : delete {}, record = {}", delete.getPath(), op.toRequestRecord());
} else {
LOG.debug("op : {}", op);
}
}
}
try {
zooKeeperClient.get().multi(zkOps, (rc, path, ctx, opResults) -> {
if (Code.OK.intValue() == rc) {
future.complete(null);
} else if (Code.NODEEXISTS.intValue() == rc) {
future.completeExceptionally(new LogExistsException("Someone just created new log " + newLogPath));
} else if (Code.NOTEMPTY.intValue() == rc) {
future.completeExceptionally(new LockingException(oldLogPath + LOCK_PATH, "Someone is holding a lock on log " + oldLogPath));
} else {
future.completeExceptionally(new ZKException("Failed to rename log " + oldLogPath + " to " + newLogPath + " at path " + path, Code.get(rc)));
}
}, null);
} catch (ZooKeeperConnectionException e) {
future.completeExceptionally(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
future.completeExceptionally(e);
}
return future;
}
Aggregations