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