Search in sources :

Example 21 with ZKException

use of com.twitter.distributedlog.exceptions.ZKException in project distributedlog by twitter.

the class BKLogHandler method asyncGetLedgerListWithRetries.

protected Future<List<LogSegmentMetadata>> asyncGetLedgerListWithRetries(Comparator<LogSegmentMetadata> comparator, LogSegmentFilter segmentFilter, Watcher watcher) {
    final Promise<List<LogSegmentMetadata>> promise = new Promise<List<LogSegmentMetadata>>();
    asyncGetLedgerListWithRetries(comparator, segmentFilter, watcher, new GenericCallback<List<LogSegmentMetadata>>() {

        @Override
        public void operationComplete(int rc, List<LogSegmentMetadata> segments) {
            if (KeeperException.Code.OK.intValue() == rc) {
                promise.setValue(segments);
            } else if (KeeperException.Code.NONODE.intValue() == rc) {
                promise.setException(new LogNotFoundException("Log " + getFullyQualifiedName() + " not found"));
            } else {
                String errMsg = "ZK Exception " + rc + " reading ledger list for " + getFullyQualifiedName();
                promise.setException(new ZKException(errMsg, KeeperException.Code.get(rc)));
            }
        }
    });
    return promise;
}
Also used : Promise(com.twitter.util.Promise) ZKException(com.twitter.distributedlog.exceptions.ZKException) List(java.util.List) ArrayList(java.util.ArrayList) LogNotFoundException(com.twitter.distributedlog.exceptions.LogNotFoundException)

Example 22 with ZKException

use of com.twitter.distributedlog.exceptions.ZKException in project distributedlog by twitter.

the class DLAuditor method collectLedgersFromAllocator.

private void collectLedgersFromAllocator(final URI uri, final com.twitter.distributedlog.DistributedLogManagerFactory factory, 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(factory).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) {
                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(factory).get().getChildren(poolPath, false);
            for (String allocator : allocators) {
                String allocatorPath = poolPath + "/" + allocator;
                byte[] data = getZooKeeperClient(factory).get().getData(allocatorPath, false, new Stat());
                if (null != data && data.length > 0) {
                    try {
                        long ledgerId = DLUtils.bytes2LedgerId(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(com.twitter.distributedlog.exceptions.DLInterruptedException) ZKException(com.twitter.distributedlog.exceptions.ZKException) Stat(org.apache.zookeeper.data.Stat) DLInterruptedException(com.twitter.distributedlog.exceptions.DLInterruptedException) List(java.util.List) ArrayList(java.util.ArrayList) KeeperException(org.apache.zookeeper.KeeperException)

Example 23 with ZKException

use of com.twitter.distributedlog.exceptions.ZKException in project distributedlog by twitter.

the class MaxLogSegmentSequenceNo method store.

synchronized void store(ZooKeeperClient zkc, String path, long logSegmentSeqNo) throws IOException {
    try {
        Stat stat = zkc.get().setData(path, DLUtils.serializeLogSegmentSequenceNumber(logSegmentSeqNo), getZkVersion());
        update(stat.getVersion(), logSegmentSeqNo);
    } catch (KeeperException ke) {
        throw new ZKException("Error writing max ledger sequence number " + logSegmentSeqNo + " to " + path + " : ", ke);
    } catch (ZooKeeperClient.ZooKeeperConnectionException zce) {
        throw new IOException("Error writing max ledger sequence number " + logSegmentSeqNo + " to " + path + " : ", zce);
    } catch (InterruptedException e) {
        throw new DLInterruptedException("Error writing max ledger sequence number " + logSegmentSeqNo + " to " + path + " : ", e);
    }
}
Also used : ZKException(com.twitter.distributedlog.exceptions.ZKException) Stat(org.apache.zookeeper.data.Stat) DLInterruptedException(com.twitter.distributedlog.exceptions.DLInterruptedException) IOException(java.io.IOException) DLInterruptedException(com.twitter.distributedlog.exceptions.DLInterruptedException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

ZKException (com.twitter.distributedlog.exceptions.ZKException)23 Test (org.junit.Test)13 KeeperException (org.apache.zookeeper.KeeperException)9 Stat (org.apache.zookeeper.data.Stat)9 Promise (com.twitter.util.Promise)7 ZkVersion (org.apache.bookkeeper.meta.ZkVersion)7 Versioned (org.apache.bookkeeper.versioning.Versioned)7 DLInterruptedException (com.twitter.distributedlog.exceptions.DLInterruptedException)6 List (java.util.List)6 AsyncCallback (org.apache.zookeeper.AsyncCallback)5 LogSegmentMetadata (com.twitter.distributedlog.LogSegmentMetadata)4 Transaction (com.twitter.distributedlog.util.Transaction)4 ZKTransaction (com.twitter.distributedlog.zk.ZKTransaction)4 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)4 Version (org.apache.bookkeeper.versioning.Version)4 LogNotFoundException (com.twitter.distributedlog.exceptions.LogNotFoundException)3 ArrayList (java.util.ArrayList)3 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 LogExistsException (com.twitter.distributedlog.exceptions.LogExistsException)2 IOException (java.io.IOException)2