Search in sources :

Example 1 with ZooKeeperConnectionException

use of org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException in project bookkeeper by apache.

the class ZKLogStreamMetadataStore method getLogSegments.

@VisibleForTesting
static CompletableFuture<List<LogSegmentMetadata>> getLogSegments(ZooKeeperClient zk, String logSegmentsPath) {
    CompletableFuture<List<LogSegmentMetadata>> future = FutureUtils.createFuture();
    try {
        zk.get().getChildren(logSegmentsPath, false, (rc, path, ctx, children, stat) -> {
            if (Code.OK.intValue() != rc) {
                if (Code.NONODE.intValue() == rc) {
                    future.completeExceptionally(new LogNotFoundException("Log " + path + " not found"));
                } else {
                    future.completeExceptionally(new ZKException("Failed to get log segments from " + path, Code.get(rc)));
                }
                return;
            }
            // get all the segments
            List<CompletableFuture<LogSegmentMetadata>> futures = Lists.newArrayListWithExpectedSize(children.size());
            for (String child : children) {
                futures.add(LogSegmentMetadata.read(zk, logSegmentsPath + "/" + child));
            }
            FutureUtils.proxyTo(FutureUtils.collect(futures), future);
        }, null);
    } catch (ZooKeeperConnectionException e) {
        future.completeExceptionally(e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        future.completeExceptionally(e);
    }
    return future;
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) CompletableFuture(java.util.concurrent.CompletableFuture) List(java.util.List) LinkedList(java.util.LinkedList) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException) ZooKeeperConnectionException(org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ZooKeeperConnectionException

use of org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException in project bookkeeper by apache.

the class ZKLogStreamMetadataStore method getMissingPaths.

@VisibleForTesting
static CompletableFuture<List<String>> getMissingPaths(ZooKeeperClient zkc, URI uri, String logName) {
    ZooKeeper zk;
    try {
        zk = zkc.get();
    } catch (ZooKeeperConnectionException | InterruptedException e) {
        return FutureUtils.exception(e);
    }
    String basePath = uri.getPath();
    String logStreamPath = LogMetadata.getLogStreamPath(uri, logName);
    return getMissingPaths(zk, basePath, logStreamPath);
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ZooKeeperConnectionException(org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with ZooKeeperConnectionException

use of org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException 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)3 DLInterruptedException (org.apache.distributedlog.exceptions.DLInterruptedException)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ZKException (org.apache.distributedlog.exceptions.ZKException)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 LockingException (org.apache.distributedlog.exceptions.LockingException)1 LogExistsException (org.apache.distributedlog.exceptions.LogExistsException)1 LogNotFoundException (org.apache.distributedlog.exceptions.LogNotFoundException)1 Op (org.apache.zookeeper.Op)1 Create (org.apache.zookeeper.Op.Create)1 Delete (org.apache.zookeeper.Op.Delete)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1