Search in sources :

Example 1 with LogNotFoundException

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;
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) CompletableFuture(java.util.concurrent.CompletableFuture) List(java.util.List) LinkedList(java.util.LinkedList) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException) ZooKeeperConnectionException(org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with LogNotFoundException

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;
}
Also used : LockCancelledException(org.apache.distributedlog.exceptions.LockCancelledException) AsyncCallback(org.apache.zookeeper.AsyncCallback) ZooKeeperConnectionException(org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException) CompletableFuture(java.util.concurrent.CompletableFuture) CancellationException(java.util.concurrent.CancellationException) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException)

Example 3 with LogNotFoundException

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;
}
Also used : AsyncCallback(org.apache.zookeeper.AsyncCallback) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) ZooKeeperConnectionException(org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException) CompletableFuture(java.util.concurrent.CompletableFuture) ZKException(org.apache.distributedlog.exceptions.ZKException) ZooKeeper(org.apache.zookeeper.ZooKeeper) Stat(org.apache.zookeeper.data.Stat) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException)

Example 4 with LogNotFoundException

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
    }
}
Also used : DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LogReader(org.apache.distributedlog.api.LogReader) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException) Test(org.junit.Test)

Example 5 with LogNotFoundException

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;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException)

Aggregations

LogNotFoundException (org.apache.distributedlog.exceptions.LogNotFoundException)17 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)8 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 LogReader (org.apache.distributedlog.api.LogReader)4 DLInterruptedException (org.apache.distributedlog.exceptions.DLInterruptedException)4 LogEmptyException (org.apache.distributedlog.exceptions.LogEmptyException)4 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ZooKeeperConnectionException (org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException)3 ZKException (org.apache.distributedlog.exceptions.ZKException)3 BufferedOutputStream (java.io.BufferedOutputStream)2 URI (java.net.URI)2 LinkedList (java.util.LinkedList)2 DLSN (org.apache.distributedlog.DLSN)2 ZooKeeperClient (org.apache.distributedlog.ZooKeeperClient)2 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)2 DLIllegalStateException (org.apache.distributedlog.exceptions.DLIllegalStateException)2 BufferedFSInputStream (org.apache.hadoop.fs.BufferedFSInputStream)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2