Search in sources :

Example 1 with NamespaceDriver

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

Example 2 with NamespaceDriver

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();
}
Also used : BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) NamespaceDriver(org.apache.distributedlog.namespace.NamespaceDriver) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver)

Example 3 with NamespaceDriver

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();
}
Also used : BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) NamespaceDriver(org.apache.distributedlog.namespace.NamespaceDriver) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver)

Example 4 with NamespaceDriver

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);
}
Also used : AsyncLogReader(org.apache.distributedlog.api.AsyncLogReader) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) NamespaceDriver(org.apache.distributedlog.namespace.NamespaceDriver) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) Test(org.junit.Test)

Aggregations

NamespaceDriver (org.apache.distributedlog.namespace.NamespaceDriver)4 BKNamespaceDriver (org.apache.distributedlog.impl.BKNamespaceDriver)3 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 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)1 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)1 PermitLimiter (org.apache.distributedlog.common.util.PermitLimiter)1 AsyncFailureInjector (org.apache.distributedlog.injector.AsyncFailureInjector)1 SimplePermitLimiter (org.apache.distributedlog.util.SimplePermitLimiter)1 Test (org.junit.Test)1