use of org.apache.distributedlog.BKDistributedLogNamespace 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);
}
Aggregations