Search in sources :

Example 16 with ZKException

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

the class DLNamespaceProviderService method initializeNamespace.

private static URI initializeNamespace(ServerConfiguration bkServerConf, URI dlogUri) throws IOException {
    BKDLConfig dlConfig = new BKDLConfig(bkServerConf.getZkServers(), bkServerConf.getZkLedgersRootPath());
    DLMetadata dlMetadata = DLMetadata.create(dlConfig);
    try {
        log.info("Initializing dlog namespace at {}", dlogUri);
        dlMetadata.create(dlogUri);
        log.info("Initialized dlog namespace at {}", dlogUri);
    } catch (ZKException e) {
        if (e.getKeeperExceptionCode() == Code.NODEEXISTS) {
            if (log.isDebugEnabled()) {
                log.debug("Dlog uri is already bound at {}", dlogUri);
            }
            return dlogUri;
        }
        log.error("Failed to initialize dlog namespace at {}", dlogUri, e);
        throw e;
    }
    return dlogUri;
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) BKDLConfig(org.apache.distributedlog.impl.metadata.BKDLConfig) DLMetadata(org.apache.distributedlog.metadata.DLMetadata)

Example 17 with ZKException

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

the class BKAbstractLogWriter method closeOldLogSegmentAndStartNewOneWithPermit.

private CompletableFuture<BKLogSegmentWriter> closeOldLogSegmentAndStartNewOneWithPermit(final BKLogSegmentWriter oldSegmentWriter, final BKLogWriteHandler writeHandler, final long startTxId, final boolean bestEffort, final boolean allowMaxTxID) {
    final PermitManager.Permit switchPermit = bkDistributedLogManager.getLogSegmentRollingPermitManager().acquirePermit();
    if (switchPermit.isAllowed()) {
        return FutureUtils.ensure(FutureUtils.rescue(closeOldLogSegmentAndStartNewOne(oldSegmentWriter, writeHandler, startTxId, bestEffort, allowMaxTxID), // rescue function
        cause -> {
            if (cause instanceof LockingException) {
                LOG.warn("We lost lock during completeAndClose log segment for {}." + "Disable ledger rolling until it is recovered : ", writeHandler.getFullyQualifiedName(), cause);
                bkDistributedLogManager.getLogSegmentRollingPermitManager().disallowObtainPermits(switchPermit);
                return FutureUtils.value(oldSegmentWriter);
            } else if (cause instanceof ZKException) {
                ZKException zke = (ZKException) cause;
                if (ZKException.isRetryableZKException(zke)) {
                    LOG.warn("Encountered zookeeper connection issues during completeAndClose " + "log segment for {}. " + "Disable ledger rolling until it is recovered : {}", writeHandler.getFullyQualifiedName(), zke.getKeeperExceptionCode());
                    bkDistributedLogManager.getLogSegmentRollingPermitManager().disallowObtainPermits(switchPermit);
                    return FutureUtils.value(oldSegmentWriter);
                }
            }
            return FutureUtils.exception(cause);
        }), // ensure function
        () -> bkDistributedLogManager.getLogSegmentRollingPermitManager().releasePermit(switchPermit));
    } else {
        bkDistributedLogManager.getLogSegmentRollingPermitManager().releasePermit(switchPermit);
        return FutureUtils.value(oldSegmentWriter);
    }
}
Also used : AlreadyClosedException(org.apache.distributedlog.exceptions.AlreadyClosedException) ZKException(org.apache.distributedlog.exceptions.ZKException) AsyncAbortable(org.apache.distributedlog.io.AsyncAbortable) Logger(org.slf4j.Logger) FutureEventListener(org.apache.bookkeeper.common.concurrent.FutureEventListener) LockingException(org.apache.distributedlog.exceptions.LockingException) LoggerFactory(org.slf4j.LoggerFactory) PermitManager(org.apache.distributedlog.common.util.PermitManager) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) FutureUtils(org.apache.bookkeeper.common.concurrent.FutureUtils) Function(java.util.function.Function) Abortable(org.apache.distributedlog.io.Abortable) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) UnexpectedException(org.apache.distributedlog.exceptions.UnexpectedException) AsyncCloseable(org.apache.distributedlog.io.AsyncCloseable) Closeable(java.io.Closeable) DynamicDistributedLogConfiguration(org.apache.distributedlog.config.DynamicDistributedLogConfiguration) Utils(org.apache.distributedlog.util.Utils) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Abortables(org.apache.distributedlog.io.Abortables) LockingException(org.apache.distributedlog.exceptions.LockingException) PermitManager(org.apache.distributedlog.common.util.PermitManager) ZKException(org.apache.distributedlog.exceptions.ZKException)

Example 18 with ZKException

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

the class TestBKLogSegmentWriter method createLock.

private ZKDistributedLock createLock(String path, ZooKeeperClient zkClient, boolean acquireLock) throws Exception {
    try {
        Utils.ioResult(Utils.zkAsyncCreateFullPathOptimistic(zkClient, path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));
    } catch (ZKException zke) {
    // node already exists
    }
    SessionLockFactory lockFactory = new ZKSessionLockFactory(zkClient, "test-lock", lockStateExecutor, 0, Long.MAX_VALUE, conf.getZKSessionTimeoutMilliseconds(), NullStatsLogger.INSTANCE);
    ZKDistributedLock lock = new ZKDistributedLock(lockStateExecutor, lockFactory, path, Long.MAX_VALUE, NullStatsLogger.INSTANCE);
    if (acquireLock) {
        return Utils.ioResult(lock.asyncAcquire());
    } else {
        return lock;
    }
}
Also used : ZKSessionLockFactory(org.apache.distributedlog.lock.ZKSessionLockFactory) ZKException(org.apache.distributedlog.exceptions.ZKException) ZKSessionLockFactory(org.apache.distributedlog.lock.ZKSessionLockFactory) SessionLockFactory(org.apache.distributedlog.lock.SessionLockFactory) ZKDistributedLock(org.apache.distributedlog.lock.ZKDistributedLock)

Example 19 with ZKException

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

the class TestZKLogStreamMetadataStore method testGetLogSegmentsZKExceptions.

@Test(timeout = 60000)
public void testGetLogSegmentsZKExceptions() throws Exception {
    String logName = testName.getMethodName();
    String logIdentifier = "<default>";
    ZooKeeper mockZk = mock(ZooKeeper.class);
    ZooKeeperClient mockZkc = mock(ZooKeeperClient.class);
    when(mockZkc.get()).thenReturn(mockZk);
    doAnswer(invocationOnMock -> {
        String path = (String) invocationOnMock.getArguments()[0];
        Children2Callback callback = (Children2Callback) invocationOnMock.getArguments()[2];
        callback.processResult(Code.BADVERSION.intValue(), path, null, null, null);
        return null;
    }).when(mockZk).getChildren(anyString(), anyBoolean(), any(Children2Callback.class), any());
    String logSegmentsPath = LogMetadata.getLogSegmentsPath(uri, logName, logIdentifier);
    try {
        FutureUtils.result(getLogSegments(mockZkc, logSegmentsPath));
        fail("Should fail to get log segments when encountering zk exceptions");
    } catch (ZKException zke) {
        assertEquals(Code.BADVERSION, zke.getKeeperExceptionCode());
    }
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) ZooKeeper(org.apache.zookeeper.ZooKeeper) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) Children2Callback(org.apache.zookeeper.AsyncCallback.Children2Callback) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 20 with ZKException

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

the class TestZKLogStreamMetadataStore method testGetMissingPathsFailure.

@Test(timeout = 60000)
public void testGetMissingPathsFailure() throws Exception {
    ZooKeeper mockZk = mock(ZooKeeper.class);
    ZooKeeperClient mockZkc = mock(ZooKeeperClient.class);
    when(mockZkc.get()).thenReturn(mockZk);
    doAnswer(invocationOnMock -> {
        String path = (String) invocationOnMock.getArguments()[0];
        StatCallback callback = (StatCallback) invocationOnMock.getArguments()[2];
        callback.processResult(Code.BADVERSION.intValue(), path, null, null);
        return null;
    }).when(mockZk).exists(anyString(), anyBoolean(), any(StatCallback.class), any());
    try {
        FutureUtils.result(getMissingPaths(mockZkc, uri, "path_failure/to/log_failure"));
        fail("Should fail on getting missing paths on zookeeper exceptions.");
    } catch (ZKException zke) {
        assertEquals(Code.BADVERSION, zke.getKeeperExceptionCode());
    }
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) ZooKeeper(org.apache.zookeeper.ZooKeeper) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StatCallback(org.apache.zookeeper.AsyncCallback.StatCallback) Test(org.junit.Test)

Aggregations

ZKException (org.apache.distributedlog.exceptions.ZKException)31 Test (org.junit.Test)15 CompletableFuture (java.util.concurrent.CompletableFuture)8 LongVersion (org.apache.bookkeeper.versioning.LongVersion)8 Versioned (org.apache.bookkeeper.versioning.Versioned)8 Stat (org.apache.zookeeper.data.Stat)7 List (java.util.List)6 ZooKeeperClient (org.apache.distributedlog.ZooKeeperClient)5 DLInterruptedException (org.apache.distributedlog.exceptions.DLInterruptedException)5 ZooKeeper (org.apache.zookeeper.ZooKeeper)5 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)4 Version (org.apache.bookkeeper.versioning.Version)4 LogSegmentMetadata (org.apache.distributedlog.LogSegmentMetadata)4 ZKTransaction (org.apache.distributedlog.zk.ZKTransaction)4 KeeperException (org.apache.zookeeper.KeeperException)4 ZooKeeperConnectionException (org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException)3 LogExistsException (org.apache.distributedlog.exceptions.LogExistsException)3 LogNotFoundException (org.apache.distributedlog.exceptions.LogNotFoundException)3 Transaction (org.apache.distributedlog.util.Transaction)3 AsyncCallback (org.apache.zookeeper.AsyncCallback)3