Search in sources :

Example 1 with LockCancelledException

use of org.apache.distributedlog.exceptions.LockCancelledException in project bookkeeper by apache.

the class TestAsyncReaderLock method testReaderLockFutureCancelledWhileWaiting.

@Test(timeout = 60000)
public void testReaderLockFutureCancelledWhileWaiting() throws Exception {
    String name = runtime.getMethodName();
    DistributedLogManager dlm0 = createNewDLM(conf, name);
    BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm0.startAsyncLogSegmentNonPartitioned());
    writer.write(DLMTestUtil.getLogRecordInstance(1L));
    writer.write(DLMTestUtil.getLogRecordInstance(2L));
    writer.closeAndComplete();
    DistributedLogManager dlm1 = createNewDLM(conf, name);
    CompletableFuture<AsyncLogReader> futureReader1 = dlm1.getAsyncLogReaderWithLock(DLSN.InitialDLSN);
    AsyncLogReader reader1 = Utils.ioResult(futureReader1);
    DistributedLogManager dlm2 = createNewDLM(conf, name);
    CompletableFuture<AsyncLogReader> futureReader2 = dlm2.getAsyncLogReaderWithLock(DLSN.InitialDLSN);
    try {
        futureReader2.cancel(true);
        Utils.ioResult(futureReader2);
        fail("Should fail getting log reader as it is cancelled");
    } catch (CancellationException ce) {
    } catch (LockClosedException ex) {
    } catch (LockCancelledException ex) {
    } catch (OwnershipAcquireFailedException oafe) {
    }
    futureReader2 = dlm2.getAsyncLogReaderWithLock(DLSN.InitialDLSN);
    Utils.close(reader1);
    Utils.ioResult(futureReader2);
    dlm0.close();
    dlm1.close();
    dlm2.close();
}
Also used : OwnershipAcquireFailedException(org.apache.distributedlog.exceptions.OwnershipAcquireFailedException) LockCancelledException(org.apache.distributedlog.exceptions.LockCancelledException) AsyncLogReader(org.apache.distributedlog.api.AsyncLogReader) CancellationException(java.util.concurrent.CancellationException) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LockClosedException(org.apache.distributedlog.lock.LockClosedException) Test(org.junit.Test)

Example 2 with LockCancelledException

use of org.apache.distributedlog.exceptions.LockCancelledException 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 LockCancelledException

use of org.apache.distributedlog.exceptions.LockCancelledException in project bookkeeper by apache.

the class TestAsyncReaderLock method testReaderLockDlmClosed.

@Test(timeout = 60000)
public void testReaderLockDlmClosed() throws Exception {
    String name = runtime.getMethodName();
    DistributedLogManager dlm0 = createNewDLM(conf, name);
    BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm0.startAsyncLogSegmentNonPartitioned());
    writer.write(DLMTestUtil.getLogRecordInstance(1L));
    writer.write(DLMTestUtil.getLogRecordInstance(2L));
    writer.closeAndComplete();
    DistributedLogManager dlm1 = createNewDLM(conf, name);
    CompletableFuture<AsyncLogReader> futureReader1 = dlm1.getAsyncLogReaderWithLock(DLSN.InitialDLSN);
    AsyncLogReader reader1 = Utils.ioResult(futureReader1);
    BKDistributedLogManager dlm2 = (BKDistributedLogManager) createNewDLM(conf, name);
    CompletableFuture<AsyncLogReader> futureReader2 = dlm2.getAsyncLogReaderWithLock(DLSN.InitialDLSN);
    dlm2.close();
    try {
        Utils.ioResult(futureReader2);
        fail("should have thrown exception!");
    } catch (CancellationException ce) {
    } catch (LockClosedException ex) {
    } catch (LockCancelledException ex) {
    }
    Utils.close(reader1);
    dlm0.close();
    dlm1.close();
}
Also used : LockCancelledException(org.apache.distributedlog.exceptions.LockCancelledException) AsyncLogReader(org.apache.distributedlog.api.AsyncLogReader) CancellationException(java.util.concurrent.CancellationException) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LockClosedException(org.apache.distributedlog.lock.LockClosedException) Test(org.junit.Test)

Aggregations

CancellationException (java.util.concurrent.CancellationException)3 LockCancelledException (org.apache.distributedlog.exceptions.LockCancelledException)3 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)2 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)2 LockClosedException (org.apache.distributedlog.lock.LockClosedException)2 Test (org.junit.Test)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 ZooKeeperClient (org.apache.distributedlog.ZooKeeperClient)1 ZooKeeperConnectionException (org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException)1 DLInterruptedException (org.apache.distributedlog.exceptions.DLInterruptedException)1 LogNotFoundException (org.apache.distributedlog.exceptions.LogNotFoundException)1 OwnershipAcquireFailedException (org.apache.distributedlog.exceptions.OwnershipAcquireFailedException)1 AsyncCallback (org.apache.zookeeper.AsyncCallback)1