Search in sources :

Example 1 with ConcurrentConstConfiguration

use of org.apache.distributedlog.common.config.ConcurrentConstConfiguration 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)

Example 2 with ConcurrentConstConfiguration

use of org.apache.distributedlog.common.config.ConcurrentConstConfiguration in project bookkeeper by apache.

the class TestDynamicConfigurationFactory method getConfigFactory.

private DynamicConfigurationFactory getConfigFactory(File configFile) {
    String streamConfigPath = configFile.getParent();
    ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1);
    ConcurrentBaseConfiguration defaultConf = new ConcurrentConstConfiguration(new DistributedLogConfiguration());
    return new DynamicConfigurationFactory(executorService, 100, TimeUnit.MILLISECONDS);
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ConcurrentConstConfiguration(org.apache.distributedlog.common.config.ConcurrentConstConfiguration) ConcurrentBaseConfiguration(org.apache.distributedlog.common.config.ConcurrentBaseConfiguration)

Example 3 with ConcurrentConstConfiguration

use of org.apache.distributedlog.common.config.ConcurrentConstConfiguration in project bookkeeper by apache.

the class TestDynamicDistributedLogConfiguration method testDefaults.

@Test(timeout = 20000)
public void testDefaults() throws Exception {
    // Default config defines retention period plus two other params, but eaves ack quorum unspecified
    DistributedLogConfiguration underlyingConfig = new DistributedLogConfiguration();
    underlyingConfig.setRetentionPeriodHours(99);
    underlyingConfig.setProperty("rpsHardWriteLimit", 99);
    ConcurrentConstConfiguration defaultConfig = new ConcurrentConstConfiguration(underlyingConfig);
    DynamicDistributedLogConfiguration config = new DynamicDistributedLogConfiguration(defaultConfig);
    assertEquals(99, config.getRetentionPeriodHours());
    assertEquals(99, config.getRpsHardWriteLimit());
    config.setProperty(DistributedLogConfiguration.BKDL_RETENTION_PERIOD_IN_HOURS, 5);
    // Config checks primary then secondary then const defaults
    assertEquals(5, config.getRetentionPeriodHours());
    assertEquals(99, config.getRpsHardWriteLimit());
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) ConcurrentConstConfiguration(org.apache.distributedlog.common.config.ConcurrentConstConfiguration) Test(org.junit.Test)

Aggregations

ConcurrentConstConfiguration (org.apache.distributedlog.common.config.ConcurrentConstConfiguration)3 DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)2 ConcurrentBaseConfiguration (org.apache.distributedlog.common.config.ConcurrentBaseConfiguration)2 Test (org.junit.Test)2 URI (java.net.URI)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)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 DynamicDistributedLogConfiguration (org.apache.distributedlog.config.DynamicDistributedLogConfiguration)1 BKNamespaceDriver (org.apache.distributedlog.impl.BKNamespaceDriver)1