use of org.apache.distributedlog.exceptions.LogNotFoundException 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.exceptions.LogNotFoundException in project bookkeeper by apache.
the class ZKLogStreamMetadataStore method ensureReadLockPathExist.
//
// Create Read Lock
//
private CompletableFuture<Void> ensureReadLockPathExist(final LogMetadata logMetadata, final String readLockPath) {
final CompletableFuture<Void> promise = new CompletableFuture<Void>();
promise.whenComplete((value, cause) -> {
if (cause instanceof CancellationException) {
FutureUtils.completeExceptionally(promise, new LockCancelledException(readLockPath, "Could not ensure read lock path", cause));
}
});
Optional<String> parentPathShouldNotCreate = Optional.of(logMetadata.getLogRootPath());
Utils.zkAsyncCreateFullPathOptimisticRecursive(zooKeeperClient, readLockPath, parentPathShouldNotCreate, new byte[0], zooKeeperClient.getDefaultACL(), CreateMode.PERSISTENT, new org.apache.zookeeper.AsyncCallback.StringCallback() {
@Override
public void processResult(final int rc, final String path, Object ctx, String name) {
if (KeeperException.Code.NONODE.intValue() == rc) {
FutureUtils.completeExceptionally(promise, new LogNotFoundException(String.format("Log %s does not exist or has been deleted", logMetadata.getFullyQualifiedName())));
} else if (KeeperException.Code.OK.intValue() == rc) {
FutureUtils.complete(promise, null);
LOG.trace("Created path {}.", path);
} else if (KeeperException.Code.NODEEXISTS.intValue() == rc) {
FutureUtils.complete(promise, null);
LOG.trace("Path {} is already existed.", path);
} else if (DistributedLogConstants.ZK_CONNECTION_EXCEPTION_RESULT_CODE == rc) {
FutureUtils.completeExceptionally(promise, new ZooKeeperClient.ZooKeeperConnectionException(path));
} else if (DistributedLogConstants.DL_INTERRUPTED_EXCEPTION_RESULT_CODE == rc) {
FutureUtils.completeExceptionally(promise, new DLInterruptedException(path));
} else {
FutureUtils.completeExceptionally(promise, KeeperException.create(KeeperException.Code.get(rc)));
}
}
}, null);
return promise;
}
use of org.apache.distributedlog.exceptions.LogNotFoundException in project bookkeeper by apache.
the class ZKLogStreamMetadataStore method logExists.
@Override
public CompletableFuture<Void> logExists(URI uri, final String logName) {
final String logSegmentsPath = LogMetadata.getLogSegmentsPath(uri, logName, conf.getUnpartitionedStreamName());
final CompletableFuture<Void> promise = new CompletableFuture<Void>();
try {
final ZooKeeper zk = zooKeeperClient.get();
zk.sync(logSegmentsPath, new AsyncCallback.VoidCallback() {
@Override
public void processResult(int syncRc, String path, Object syncCtx) {
if (KeeperException.Code.NONODE.intValue() == syncRc) {
promise.completeExceptionally(new LogNotFoundException(String.format("Log %s does not exist or has been deleted", logName)));
return;
} else if (KeeperException.Code.OK.intValue() != syncRc) {
promise.completeExceptionally(new ZKException("Error on checking log existence for " + logName, KeeperException.create(KeeperException.Code.get(syncRc))));
return;
}
zk.exists(logSegmentsPath, false, new AsyncCallback.StatCallback() {
@Override
public void processResult(int rc, String path, Object ctx, Stat stat) {
if (KeeperException.Code.OK.intValue() == rc) {
promise.complete(null);
} else if (KeeperException.Code.NONODE.intValue() == rc) {
promise.completeExceptionally(new LogNotFoundException(String.format("Log %s does not exist or has been deleted", logName)));
} else {
promise.completeExceptionally(new ZKException("Error on checking log existence for " + logName, KeeperException.create(KeeperException.Code.get(rc))));
}
}
}, null);
}
}, null);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
LOG.error("Interrupted while reading {}", logSegmentsPath, ie);
promise.completeExceptionally(new DLInterruptedException("Interrupted while checking " + logSegmentsPath, ie));
} catch (ZooKeeperClient.ZooKeeperConnectionException e) {
promise.completeExceptionally(e);
}
return promise;
}
use of org.apache.distributedlog.exceptions.LogNotFoundException in project bookkeeper by apache.
the class TestBKSyncLogReader method testDeletingLogWhileReading.
@Test(timeout = 60000)
public void testDeletingLogWhileReading() throws Exception {
String name = testName.getMethodName();
DistributedLogManager dlm = createNewDLM(conf, name);
BKSyncLogWriter out = (BKSyncLogWriter) dlm.startLogSegmentNonPartitioned();
for (long i = 1; i < 10; i++) {
LogRecord op = DLMTestUtil.getLogRecordInstance(i);
out.write(op);
}
out.closeAndComplete();
LogReader reader = dlm.getInputStream(1L);
for (int i = 1; i < 10; i++) {
LogRecord record = waitForNextRecord(reader);
assertEquals((long) i, record.getTransactionId());
}
DistributedLogManager deleteDLM = createNewDLM(conf, name);
deleteDLM.delete();
LogRecord record;
try {
record = reader.readNext(false);
while (null == record) {
record = reader.readNext(false);
}
fail("Should fail reading next with LogNotFound");
} catch (LogNotFoundException lnfe) {
// expected
}
}
use of org.apache.distributedlog.exceptions.LogNotFoundException in project bookkeeper by apache.
the class DLFileSystem method delete.
@Override
public boolean delete(Path path, boolean recursive) throws IOException {
try {
String logName = getStreamName(path);
if (recursive) {
Iterator<String> logs = namespace.getLogs(logName);
while (logs.hasNext()) {
String child = logs.next();
Path childPath = new Path(path, child);
delete(childPath, recursive);
}
}
namespace.deleteLog(logName);
return true;
} catch (LogNotFoundException e) {
return true;
}
}
Aggregations