Search in sources :

Example 1 with DynamicDistributedLogConfiguration

use of org.apache.distributedlog.config.DynamicDistributedLogConfiguration in project bookkeeper by apache.

the class BKDistributedLogNamespace method openLogInternal.

/**
 * Open the log in location <i>uri</i>.
 *
 * @param uri
 *          location to store the log
 * @param nameOfLogStream
 *          name of the log
 * @param logConfiguration
 *          optional stream configuration
 * @param dynamicLogConfiguration
 *          dynamic stream configuration overrides.
 * @return distributedlog manager instance.
 * @throws InvalidStreamNameException if the stream name is invalid
 * @throws IOException
 */
protected DistributedLogManager openLogInternal(URI uri, String nameOfLogStream, Optional<DistributedLogConfiguration> logConfiguration, Optional<DynamicDistributedLogConfiguration> dynamicLogConfiguration) throws InvalidStreamNameException, IOException {
    // Make sure the name is well formed
    checkState();
    nameOfLogStream = validateAndNormalizeName(nameOfLogStream);
    DistributedLogConfiguration mergedConfiguration = new DistributedLogConfiguration();
    mergedConfiguration.addConfiguration(conf);
    mergedConfiguration.loadStreamConf(logConfiguration);
    // If dynamic config was not provided, default to a static view of the global configuration.
    DynamicDistributedLogConfiguration dynConf = null;
    if (dynamicLogConfiguration.isPresent()) {
        dynConf = dynamicLogConfiguration.get();
    } else {
        dynConf = ConfUtils.getConstDynConf(mergedConfiguration);
    }
    return new BKDistributedLogManager(nameOfLogStream, /* Log Name */
    mergedConfiguration, /* Configuration */
    dynConf, /* Dynamic Configuration */
    uri, /* Namespace URI */
    driver, /* Namespace Driver */
    logSegmentMetadataCache, /* Log Segment Metadata Cache */
    scheduler, /* DL scheduler */
    clientId, /* Client Id */
    regionId, /* Region Id */
    writeLimiter, /* Write Limiter */
    featureProvider.scope("dl"), /* Feature Provider */
    failureInjector, /* Failure Injector */
    statsLogger, /* Stats Logger */
    perLogStatsLogger, /* Per Log Stats Logger */
    com.google.common.base.Optional.absent());
}
Also used : DynamicDistributedLogConfiguration(org.apache.distributedlog.config.DynamicDistributedLogConfiguration) DynamicDistributedLogConfiguration(org.apache.distributedlog.config.DynamicDistributedLogConfiguration)

Example 2 with DynamicDistributedLogConfiguration

use of org.apache.distributedlog.config.DynamicDistributedLogConfiguration in project bookkeeper by apache.

the class TestAsyncReaderWriter method testCreateLogStreamWithDifferentReplicationFactor.

@Test(timeout = 60000)
public void testCreateLogStreamWithDifferentReplicationFactor() throws Exception {
    String name = runtime.getMethodName();
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(testConf);
    confLocal.setOutputBufferSize(0);
    confLocal.setImmediateFlushEnabled(false);
    confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
    ConcurrentBaseConfiguration baseConf = new ConcurrentConstConfiguration(confLocal);
    DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(baseConf);
    dynConf.setProperty(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE, DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT - 1);
    URI uri = createDLMURI("/" + name);
    ensureURICreated(uri);
    Namespace namespace = NamespaceBuilder.newBuilder().conf(confLocal).uri(uri).build();
    // use the pool
    DistributedLogManager dlm = namespace.openLog(name + "-pool");
    AsyncLogWriter writer = dlm.startAsyncLogSegmentNonPartitioned();
    Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
    List<LogSegmentMetadata> segments = dlm.getLogSegments();
    assertEquals(1, segments.size());
    long ledgerId = segments.get(0).getLogSegmentId();
    LedgerHandle lh = ((BKNamespaceDriver) namespace.getNamespaceDriver()).getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
    LedgerMetadata metadata = BookKeeperAccessor.getLedgerMetadata(lh);
    assertEquals(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT, metadata.getEnsembleSize());
    lh.close();
    Utils.close(writer);
    dlm.close();
    // use customized configuration
    dlm = namespace.openLog(name + "-custom", java.util.Optional.empty(), java.util.Optional.of(dynConf), java.util.Optional.empty());
    writer = dlm.startAsyncLogSegmentNonPartitioned();
    Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
    segments = dlm.getLogSegments();
    assertEquals(1, segments.size());
    ledgerId = segments.get(0).getLogSegmentId();
    lh = ((BKNamespaceDriver) namespace.getNamespaceDriver()).getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
    metadata = BookKeeperAccessor.getLedgerMetadata(lh);
    assertEquals(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT - 1, metadata.getEnsembleSize());
    lh.close();
    Utils.close(writer);
    dlm.close();
    namespace.close();
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) AsyncLogWriter(org.apache.distributedlog.api.AsyncLogWriter) ConcurrentConstConfiguration(org.apache.distributedlog.common.config.ConcurrentConstConfiguration) DynamicDistributedLogConfiguration(org.apache.distributedlog.config.DynamicDistributedLogConfiguration) URI(java.net.URI) Namespace(org.apache.distributedlog.api.namespace.Namespace) ConcurrentBaseConfiguration(org.apache.distributedlog.common.config.ConcurrentBaseConfiguration) DynamicDistributedLogConfiguration(org.apache.distributedlog.config.DynamicDistributedLogConfiguration) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) Test(org.junit.Test)

Aggregations

DynamicDistributedLogConfiguration (org.apache.distributedlog.config.DynamicDistributedLogConfiguration)2 URI (java.net.URI)1 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)1 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)1 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)1 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)1 Namespace (org.apache.distributedlog.api.namespace.Namespace)1 ConcurrentBaseConfiguration (org.apache.distributedlog.common.config.ConcurrentBaseConfiguration)1 ConcurrentConstConfiguration (org.apache.distributedlog.common.config.ConcurrentConstConfiguration)1 BKNamespaceDriver (org.apache.distributedlog.impl.BKNamespaceDriver)1 Test (org.junit.Test)1