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);
}
Aggregations