Search in sources :

Example 1 with Create

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;
}
Also used : Delete(org.apache.zookeeper.Op.Delete) Op(org.apache.zookeeper.Op) LockingException(org.apache.distributedlog.exceptions.LockingException) ZKException(org.apache.distributedlog.exceptions.ZKException) LogExistsException(org.apache.distributedlog.exceptions.LogExistsException) Create(org.apache.zookeeper.Op.Create) ZooKeeperConnectionException(org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException)

Aggregations

ZooKeeperConnectionException (org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException)1 DLInterruptedException (org.apache.distributedlog.exceptions.DLInterruptedException)1 LockingException (org.apache.distributedlog.exceptions.LockingException)1 LogExistsException (org.apache.distributedlog.exceptions.LogExistsException)1 ZKException (org.apache.distributedlog.exceptions.ZKException)1 Op (org.apache.zookeeper.Op)1 Create (org.apache.zookeeper.Op.Create)1 Delete (org.apache.zookeeper.Op.Delete)1