use of org.apache.distributedlog.namespace.NamespaceDriver in project bookkeeper by apache.
the class NamespaceBuilder method build.
/**
* Build the namespace.
*
* @return the namespace instance.
* @throws IllegalArgumentException when there is illegal argument provided in the builder
* @throws NullPointerException when there is null argument provided in the builder
* @throws IOException when fail to build the backend
*/
public Namespace build() throws IllegalArgumentException, NullPointerException, IOException {
// Check arguments
checkNotNull(_conf, "No DistributedLog Configuration.");
checkNotNull(_uri, "No DistributedLog URI");
// validate the configuration
_conf.validate();
if (null == _dynConf) {
_dynConf = ConfUtils.getConstDynConf(_conf);
}
// retrieve the namespace driver
NamespaceDriver driver = NamespaceDriverManager.getDriver(_uri);
URI normalizedUri = DLUtils.normalizeURI(_uri);
// build the feature provider
FeatureProvider featureProvider;
if (null == _featureProvider) {
featureProvider = new SettableFeatureProvider("", 0);
logger.info("No feature provider is set. All features are disabled now.");
} else {
featureProvider = _featureProvider;
}
// build the failure injector
AsyncFailureInjector failureInjector = AsyncRandomFailureInjector.newBuilder().injectDelays(_conf.getEIInjectReadAheadDelay(), _conf.getEIInjectReadAheadDelayPercent(), _conf.getEIInjectMaxReadAheadDelayMs()).injectErrors(false, 10).injectStops(_conf.getEIInjectReadAheadStall(), 10).injectCorruption(_conf.getEIInjectReadAheadBrokenEntries()).build();
// normalize the per log stats logger
StatsLogger perLogStatsLogger = normalizePerLogStatsLogger(_statsLogger, _perLogStatsLogger, _conf);
// build the scheduler
OrderedScheduler scheduler = OrderedScheduler.newSchedulerBuilder().name("DLM-" + normalizedUri.getPath()).numThreads(_conf.getNumWorkerThreads()).build();
// initialize the namespace driver
driver.initialize(_conf, _dynConf, normalizedUri, scheduler, featureProvider, failureInjector, _statsLogger, perLogStatsLogger, DLUtils.normalizeClientId(_clientId), _regionId);
// initialize the write limiter
PermitLimiter writeLimiter;
if (_conf.getGlobalOutstandingWriteLimit() < 0) {
writeLimiter = PermitLimiter.NULL_PERMIT_LIMITER;
} else {
Feature disableWriteLimitFeature = featureProvider.getFeature(CoreFeatureKeys.DISABLE_WRITE_LIMIT.name().toLowerCase());
writeLimiter = new SimplePermitLimiter(_conf.getOutstandingWriteLimitDarkmode(), _conf.getGlobalOutstandingWriteLimit(), _statsLogger.scope("writeLimiter"), true, /* singleton */
disableWriteLimitFeature);
}
return new BKDistributedLogNamespace(_conf, normalizedUri, driver, scheduler, featureProvider, writeLimiter, failureInjector, _statsLogger, perLogStatsLogger, DLUtils.normalizeClientId(_clientId), _regionId);
}
use of org.apache.distributedlog.namespace.NamespaceDriver in project bookkeeper by apache.
the class TestDistributedLogBase method getBookKeeperClient.
@SuppressWarnings("deprecation")
protected BookKeeperClient getBookKeeperClient(Namespace namespace) throws Exception {
NamespaceDriver driver = namespace.getNamespaceDriver();
assertTrue(driver instanceof BKNamespaceDriver);
return ((BKNamespaceDriver) driver).getReaderBKC();
}
use of org.apache.distributedlog.namespace.NamespaceDriver in project bookkeeper by apache.
the class TestDistributedLogBase method getZooKeeperClient.
protected ZooKeeperClient getZooKeeperClient(Namespace namespace) throws Exception {
NamespaceDriver driver = namespace.getNamespaceDriver();
assertTrue(driver instanceof BKNamespaceDriver);
return ((BKNamespaceDriver) driver).getWriterZKC();
}
use of org.apache.distributedlog.namespace.NamespaceDriver in project bookkeeper by apache.
the class TestAsyncReaderLock method testReaderLockIfLockPathDoesntExist.
@Test(timeout = 60000)
public void testReaderLockIfLockPathDoesntExist() throws Exception {
final String name = runtime.getMethodName();
DistributedLogManager dlm = createNewDLM(conf, name);
BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm.startAsyncLogSegmentNonPartitioned());
writer.write(DLMTestUtil.getLogRecordInstance(1L));
writer.closeAndComplete();
CompletableFuture<AsyncLogReader> futureReader1 = dlm.getAsyncLogReaderWithLock(DLSN.InitialDLSN);
BKAsyncLogReader reader1 = (BKAsyncLogReader) Utils.ioResult(futureReader1);
LogRecordWithDLSN record = Utils.ioResult(reader1.readNext());
assertEquals(1L, record.getTransactionId());
assertEquals(0L, record.getSequenceId());
DLMTestUtil.verifyLogRecord(record);
String readLockPath = reader1.readHandler.getReadLockPath();
Utils.close(reader1);
// simulate a old stream created without readlock path
NamespaceDriver driver = dlm.getNamespaceDriver();
((BKNamespaceDriver) driver).getWriterZKC().get().delete(readLockPath, -1);
CompletableFuture<AsyncLogReader> futureReader2 = dlm.getAsyncLogReaderWithLock(DLSN.InitialDLSN);
AsyncLogReader reader2 = Utils.ioResult(futureReader2);
record = Utils.ioResult(reader2.readNext());
assertEquals(1L, record.getTransactionId());
assertEquals(0L, record.getSequenceId());
DLMTestUtil.verifyLogRecord(record);
}
Aggregations