Search in sources :

Example 1 with BKDistributedLogNamespace

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);
}
Also used : AsyncFailureInjector(org.apache.distributedlog.injector.AsyncFailureInjector) NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) BKDistributedLogNamespace(org.apache.distributedlog.BKDistributedLogNamespace) NamespaceDriver(org.apache.distributedlog.namespace.NamespaceDriver) FeatureProvider(org.apache.bookkeeper.feature.FeatureProvider) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider) SimplePermitLimiter(org.apache.distributedlog.util.SimplePermitLimiter) PermitLimiter(org.apache.distributedlog.common.util.PermitLimiter) SimplePermitLimiter(org.apache.distributedlog.util.SimplePermitLimiter) URI(java.net.URI) Feature(org.apache.bookkeeper.feature.Feature) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler)

Aggregations

URI (java.net.URI)1 OrderedScheduler (org.apache.bookkeeper.common.util.OrderedScheduler)1 Feature (org.apache.bookkeeper.feature.Feature)1 FeatureProvider (org.apache.bookkeeper.feature.FeatureProvider)1 SettableFeatureProvider (org.apache.bookkeeper.feature.SettableFeatureProvider)1 NullStatsLogger (org.apache.bookkeeper.stats.NullStatsLogger)1 StatsLogger (org.apache.bookkeeper.stats.StatsLogger)1 BKDistributedLogNamespace (org.apache.distributedlog.BKDistributedLogNamespace)1 PermitLimiter (org.apache.distributedlog.common.util.PermitLimiter)1 AsyncFailureInjector (org.apache.distributedlog.injector.AsyncFailureInjector)1 NamespaceDriver (org.apache.distributedlog.namespace.NamespaceDriver)1 SimplePermitLimiter (org.apache.distributedlog.util.SimplePermitLimiter)1