Search in sources :

Example 31 with ZKException

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

the class DLAuditor method collectLedgersFromAllocator.

private void collectLedgersFromAllocator(final URI uri, final Namespace namespace, final List<String> allocationPaths, final Set<Long> ledgers) throws IOException {
    final LinkedBlockingQueue<String> poolQueue = new LinkedBlockingQueue<String>();
    for (String allocationPath : allocationPaths) {
        String rootPath = uri.getPath() + "/" + allocationPath;
        try {
            List<String> pools = getZooKeeperClient(namespace).get().getChildren(rootPath, false);
            for (String pool : pools) {
                poolQueue.add(rootPath + "/" + pool);
            }
        } catch (KeeperException e) {
            throw new ZKException("Failed to get list of pools from " + rootPath, e);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new DLInterruptedException("Interrupted on getting list of pools from " + rootPath, e);
        }
    }
    logger.info("Collecting ledgers from allocators for {} : {}", uri, poolQueue);
    executeAction(poolQueue, 10, new Action<String>() {

        @Override
        public void execute(String poolPath) throws IOException {
            try {
                collectLedgersFromPool(poolPath);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new DLInterruptedException("Interrupted on collecting" + " ledgers from allocation pool " + poolPath, e);
            } catch (KeeperException e) {
                throw new ZKException("Failed to collect ledgers from allocation pool " + poolPath, e.code());
            }
        }

        private void collectLedgersFromPool(String poolPath) throws InterruptedException, ZooKeeperClient.ZooKeeperConnectionException, KeeperException {
            List<String> allocators = getZooKeeperClient(namespace).get().getChildren(poolPath, false);
            for (String allocator : allocators) {
                String allocatorPath = poolPath + "/" + allocator;
                byte[] data = getZooKeeperClient(namespace).get().getData(allocatorPath, false, new Stat());
                if (null != data && data.length > 0) {
                    try {
                        long ledgerId = DLUtils.bytes2LogSegmentId(data);
                        synchronized (ledgers) {
                            ledgers.add(ledgerId);
                        }
                    } catch (NumberFormatException nfe) {
                        logger.warn("Invalid ledger found in allocator path {} : ", allocatorPath, nfe);
                    }
                }
            }
        }
    });
    logger.info("Collected ledgers from allocators for {}.", uri);
}
Also used : IOException(java.io.IOException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) ZKException(org.apache.distributedlog.exceptions.ZKException) Stat(org.apache.zookeeper.data.Stat) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) List(java.util.List) ArrayList(java.util.ArrayList) KeeperException(org.apache.zookeeper.KeeperException)

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