Search in sources :

Example 26 with ZKException

use of org.apache.distributedlog.exceptions.ZKException in project bookkeeper by apache.

the class TestDistributedLogTool method testToolCreateZkAclId.

@Test(timeout = 60000)
public void testToolCreateZkAclId() throws Exception {
    createStream(defaultUri, "0", "CreateAclStream", defaultPrivilegedZkAclId);
    try {
        DistributedLogManager dlm = DLMTestUtil.createNewDLM("0CreateAclStream", conf, defaultUri);
        DLMTestUtil.generateCompletedLogSegments(dlm, conf, 3, 1000);
        dlm.close();
    } catch (ZKException ex) {
        assertEquals(KeeperException.Code.NOAUTH, ex.getKeeperExceptionCode());
    }
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) Test(org.junit.Test)

Example 27 with ZKException

use of org.apache.distributedlog.exceptions.ZKException in project bookkeeper by apache.

the class ZKLogMetadataStore method getLogs.

@Override
public CompletableFuture<Iterator<String>> getLogs(String logNamePrefix) {
    final CompletableFuture<Iterator<String>> promise = new CompletableFuture<Iterator<String>>();
    final String nsRootPath;
    if (StringUtils.isEmpty(logNamePrefix)) {
        nsRootPath = namespace.getPath();
    } else {
        nsRootPath = namespace.getPath() + "/" + logNamePrefix;
    }
    try {
        final ZooKeeper zk = zkc.get();
        zk.sync(nsRootPath, new AsyncCallback.VoidCallback() {

            @Override
            public void processResult(int syncRc, String syncPath, Object ctx) {
                if (KeeperException.Code.OK.intValue() == syncRc) {
                    zk.getChildren(nsRootPath, false, new AsyncCallback.Children2Callback() {

                        @Override
                        public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
                            if (KeeperException.Code.OK.intValue() == rc) {
                                List<String> results = Lists.newArrayListWithExpectedSize(children.size());
                                for (String child : children) {
                                    if (!isReservedStreamName(child)) {
                                        results.add(child);
                                    }
                                }
                                promise.complete(results.iterator());
                            } else if (KeeperException.Code.NONODE.intValue() == rc) {
                                List<String> streams = Lists.newLinkedList();
                                promise.complete(streams.iterator());
                            } else {
                                promise.completeExceptionally(new ZKException("Error reading namespace " + nsRootPath, KeeperException.Code.get(rc)));
                            }
                        }
                    }, null);
                } else if (KeeperException.Code.NONODE.intValue() == syncRc) {
                    List<String> streams = Lists.newLinkedList();
                    promise.complete(streams.iterator());
                } else {
                    promise.completeExceptionally(new ZKException("Error reading namespace " + nsRootPath, KeeperException.Code.get(syncRc)));
                }
            }
        }, null);
        zkc.get();
    } catch (ZooKeeperClient.ZooKeeperConnectionException e) {
        promise.completeExceptionally(e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        promise.completeExceptionally(e);
    }
    return promise;
}
Also used : AsyncCallback(org.apache.zookeeper.AsyncCallback) CompletableFuture(java.util.concurrent.CompletableFuture) ZKException(org.apache.distributedlog.exceptions.ZKException) ZooKeeper(org.apache.zookeeper.ZooKeeper) Stat(org.apache.zookeeper.data.Stat) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) Iterator(java.util.Iterator) List(java.util.List)

Example 28 with ZKException

use of org.apache.distributedlog.exceptions.ZKException in project bookkeeper by apache.

the class ZKLogSegmentMetadataStore method deleteLogSegment.

@Override
public void deleteLogSegment(Transaction<Object> txn, final LogSegmentMetadata segment, final OpListener<Void> listener) {
    Op deleteOp = Op.delete(segment.getZkPath(), -1);
    logger.info("Delete segment : {}", segment);
    txn.addOp(DefaultZKOp.of(deleteOp, new OpListener<Void>() {

        @Override
        public void onCommit(Void r) {
            if (null != listener) {
                listener.onCommit(r);
            }
        }

        @Override
        public void onAbort(Throwable t) {
            logger.info("Aborted transaction on deleting segment {}", segment);
            KeeperException.Code kc;
            if (t instanceof KeeperException) {
                kc = ((KeeperException) t).code();
            } else if (t instanceof ZKException) {
                kc = ((ZKException) t).getKeeperExceptionCode();
            } else {
                abortListener(t);
                return;
            }
            if (KeeperException.Code.NONODE == kc) {
                abortListener(new LogSegmentNotFoundException(segment.getZkPath()));
                return;
            }
            abortListener(t);
        }

        private void abortListener(Throwable t) {
            if (null != listener) {
                listener.onAbort(t);
            }
        }
    }));
}
Also used : ZKOp(org.apache.distributedlog.zk.ZKOp) Op(org.apache.zookeeper.Op) DefaultZKOp(org.apache.distributedlog.zk.DefaultZKOp) ZKVersionedSetOp(org.apache.distributedlog.zk.ZKVersionedSetOp) ZKException(org.apache.distributedlog.exceptions.ZKException) OpListener(org.apache.distributedlog.util.Transaction.OpListener) KeeperException(org.apache.zookeeper.KeeperException) LogSegmentNotFoundException(org.apache.distributedlog.exceptions.LogSegmentNotFoundException)

Example 29 with ZKException

use of org.apache.distributedlog.exceptions.ZKException in project bookkeeper by apache.

the class ZKLogSegmentMetadataStore method processResult.

@Override
@SuppressWarnings("unchecked")
public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
    CompletableFuture<Versioned<List<String>>> result = ((CompletableFuture<Versioned<List<String>>>) ctx);
    if (KeeperException.Code.OK.intValue() == rc) {
        /**
         * cversion: the number of changes to the children of this znode *
         */
        LongVersion zkVersion = new LongVersion(stat.getCversion());
        result.complete(new Versioned(children, zkVersion));
    } else if (KeeperException.Code.NONODE.intValue() == rc) {
        result.completeExceptionally(new LogNotFoundException("Log " + path + " not found"));
    } else {
        result.completeExceptionally(new ZKException("Failed to get log segments from " + path, KeeperException.Code.get(rc)));
    }
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) Versioned(org.apache.bookkeeper.versioning.Versioned) LongVersion(org.apache.bookkeeper.versioning.LongVersion) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException)

Example 30 with ZKException

use of org.apache.distributedlog.exceptions.ZKException in project bookkeeper by apache.

the class ZKLogStreamMetadataStore method existPath.

private static void existPath(ZooKeeper zk, String path, String basePath, LinkedList<String> missingPaths, CompletableFuture<List<String>> future) {
    if (basePath.equals(path)) {
        future.complete(missingPaths);
        return;
    }
    zk.exists(path, false, (rc, path1, ctx, stat) -> {
        if (Code.OK.intValue() != rc && Code.NONODE.intValue() != rc) {
            future.completeExceptionally(new ZKException("Failed to check existence of path " + path1, Code.get(rc)));
            return;
        }
        if (Code.OK.intValue() == rc) {
            future.complete(missingPaths);
            return;
        }
        missingPaths.addLast(path);
        String parentPath = Utils.getParent(path);
        existPath(zk, parentPath, basePath, missingPaths, future);
    }, null);
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException)

Aggregations

ZKException (org.apache.distributedlog.exceptions.ZKException)31 Test (org.junit.Test)15 CompletableFuture (java.util.concurrent.CompletableFuture)8 LongVersion (org.apache.bookkeeper.versioning.LongVersion)8 Versioned (org.apache.bookkeeper.versioning.Versioned)8 Stat (org.apache.zookeeper.data.Stat)7 List (java.util.List)6 ZooKeeperClient (org.apache.distributedlog.ZooKeeperClient)5 DLInterruptedException (org.apache.distributedlog.exceptions.DLInterruptedException)5 ZooKeeper (org.apache.zookeeper.ZooKeeper)5 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)4 Version (org.apache.bookkeeper.versioning.Version)4 LogSegmentMetadata (org.apache.distributedlog.LogSegmentMetadata)4 ZKTransaction (org.apache.distributedlog.zk.ZKTransaction)4 KeeperException (org.apache.zookeeper.KeeperException)4 ZooKeeperConnectionException (org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException)3 LogExistsException (org.apache.distributedlog.exceptions.LogExistsException)3 LogNotFoundException (org.apache.distributedlog.exceptions.LogNotFoundException)3 Transaction (org.apache.distributedlog.util.Transaction)3 AsyncCallback (org.apache.zookeeper.AsyncCallback)3