Search in sources :

Example 16 with ZooKeeperClient

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

the class BKNamespaceDriver method enumerateLogsWithMetadataInNamespace.

public Map<String, byte[]> enumerateLogsWithMetadataInNamespace() throws IOException, IllegalArgumentException {
    String namespaceRootPath = namespace.getPath();
    HashMap<String, byte[]> result = new HashMap<String, byte[]>();
    ZooKeeperClient zkc = writerZKC;
    try {
        ZooKeeper zk = Utils.sync(zkc, namespaceRootPath);
        Stat currentStat = zk.exists(namespaceRootPath, false);
        if (currentStat == null) {
            return result;
        }
        List<String> children = zk.getChildren(namespaceRootPath, false);
        for (String child : children) {
            if (isReservedStreamName(child)) {
                continue;
            }
            String zkPath = String.format("%s/%s", namespaceRootPath, child);
            currentStat = zk.exists(zkPath, false);
            if (currentStat == null) {
                result.put(child, new byte[0]);
            } else {
                result.put(child, zk.getData(zkPath, false, currentStat));
            }
        }
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        LOG.error("Interrupted while deleting " + namespaceRootPath, ie);
        throw new IOException("Interrupted while reading " + namespaceRootPath, ie);
    } catch (KeeperException ke) {
        LOG.error("Error reading" + namespaceRootPath + "entry in zookeeper", ke);
        throw new IOException("Error reading" + namespaceRootPath + "entry in zookeeper", ke);
    }
    return result;
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) Stat(org.apache.zookeeper.data.Stat) HashMap(java.util.HashMap) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

ZooKeeperClient (org.apache.distributedlog.ZooKeeperClient)16 DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)6 Test (org.junit.Test)6 KeeperException (org.apache.zookeeper.KeeperException)5 ZooKeeper (org.apache.zookeeper.ZooKeeper)5 IOException (java.io.IOException)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 ZKException (org.apache.distributedlog.exceptions.ZKException)4 URI (java.net.URI)3 DLInterruptedException (org.apache.distributedlog.exceptions.DLInterruptedException)3 AsyncCallback (org.apache.zookeeper.AsyncCallback)3 Stat (org.apache.zookeeper.data.Stat)3 CancellationException (java.util.concurrent.CancellationException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutorService (java.util.concurrent.ExecutorService)2 LongVersion (org.apache.bookkeeper.versioning.LongVersion)2 Versioned (org.apache.bookkeeper.versioning.Versioned)2 BoundExponentialBackoffRetryPolicy (org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy)2 RetryPolicy (org.apache.bookkeeper.zookeeper.RetryPolicy)2 BookKeeperClient (org.apache.distributedlog.BookKeeperClient)2