use of org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException in project bookkeeper by apache.
the class ZKLogStreamMetadataStore method getLogSegments.
@VisibleForTesting
static CompletableFuture<List<LogSegmentMetadata>> getLogSegments(ZooKeeperClient zk, String logSegmentsPath) {
CompletableFuture<List<LogSegmentMetadata>> future = FutureUtils.createFuture();
try {
zk.get().getChildren(logSegmentsPath, false, (rc, path, ctx, children, stat) -> {
if (Code.OK.intValue() != rc) {
if (Code.NONODE.intValue() == rc) {
future.completeExceptionally(new LogNotFoundException("Log " + path + " not found"));
} else {
future.completeExceptionally(new ZKException("Failed to get log segments from " + path, Code.get(rc)));
}
return;
}
// get all the segments
List<CompletableFuture<LogSegmentMetadata>> futures = Lists.newArrayListWithExpectedSize(children.size());
for (String child : children) {
futures.add(LogSegmentMetadata.read(zk, logSegmentsPath + "/" + child));
}
FutureUtils.proxyTo(FutureUtils.collect(futures), future);
}, null);
} catch (ZooKeeperConnectionException e) {
future.completeExceptionally(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
future.completeExceptionally(e);
}
return future;
}
use of org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException in project bookkeeper by apache.
the class ZKLogStreamMetadataStore method getMissingPaths.
@VisibleForTesting
static CompletableFuture<List<String>> getMissingPaths(ZooKeeperClient zkc, URI uri, String logName) {
ZooKeeper zk;
try {
zk = zkc.get();
} catch (ZooKeeperConnectionException | InterruptedException e) {
return FutureUtils.exception(e);
}
String basePath = uri.getPath();
String logStreamPath = LogMetadata.getLogStreamPath(uri, logName);
return getMissingPaths(zk, basePath, logStreamPath);
}
use of org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException in project bookkeeper by apache.
the class ZKLogStreamMetadataStore method executeRenameTxn.
private CompletableFuture<Void> executeRenameTxn(String oldLogPath, String newLogPath, LinkedList<Op> createOps, LinkedList<Op> deleteOps) {
CompletableFuture<Void> future = FutureUtils.createFuture();
List<Op> zkOps = Lists.newArrayListWithExpectedSize(createOps.size() + deleteOps.size());
zkOps.addAll(createOps);
zkOps.addAll(deleteOps);
if (LOG.isDebugEnabled()) {
for (Op op : zkOps) {
if (op instanceof Create) {
Create create = (Create) op;
LOG.debug("op : create {}", create.getPath());
} else if (op instanceof Delete) {
Delete delete = (Delete) op;
LOG.debug("op : delete {}, record = {}", delete.getPath(), op.toRequestRecord());
} else {
LOG.debug("op : {}", op);
}
}
}
try {
zooKeeperClient.get().multi(zkOps, (rc, path, ctx, opResults) -> {
if (Code.OK.intValue() == rc) {
future.complete(null);
} else if (Code.NODEEXISTS.intValue() == rc) {
future.completeExceptionally(new LogExistsException("Someone just created new log " + newLogPath));
} else if (Code.NOTEMPTY.intValue() == rc) {
future.completeExceptionally(new LockingException(oldLogPath + LOCK_PATH, "Someone is holding a lock on log " + oldLogPath));
} else {
future.completeExceptionally(new ZKException("Failed to rename log " + oldLogPath + " to " + newLogPath + " at path " + path, Code.get(rc)));
}
}, null);
} catch (ZooKeeperConnectionException e) {
future.completeExceptionally(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
future.completeExceptionally(e);
}
return future;
}
Aggregations