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;
}
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);
}
}
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;
}
}
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());
}
}
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());
}
}
Aggregations