Search in sources :

Example 26 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.

the class TestZkMetadataResolver method testFederatedNamespace.

@Test(timeout = 60000)
public void testFederatedNamespace() throws Exception {
    DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
    URI uri = createURI("/messaging/distributedlog-testfederatednamespace/dl1");
    DLMetadata meta1 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers"));
    meta1.create(uri);
    BKDLConfig read1 = BKDLConfig.resolveDLConfig(zkc, uri);
    BKDLConfig.propagateConfiguration(read1, dlConf);
    assertTrue(dlConf.getCreateStreamIfNotExists());
    BKDLConfig.clearCachedDLConfigs();
    DLMetadata meta2 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers").setFederatedNamespace(true));
    meta2.update(uri);
    BKDLConfig read2 = BKDLConfig.resolveDLConfig(zkc, uri);
    BKDLConfig.propagateConfiguration(read2, dlConf);
    assertFalse(dlConf.getCreateStreamIfNotExists());
    BKDLConfig.clearCachedDLConfigs();
    DLMetadata meta3 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers").setFederatedNamespace(false));
    meta3.update(uri);
    BKDLConfig read3 = BKDLConfig.resolveDLConfig(zkc, uri);
    BKDLConfig.propagateConfiguration(read3, dlConf);
    // if it is non-federated namespace, it won't change the create stream behavior.
    assertFalse(dlConf.getCreateStreamIfNotExists());
    BKDLConfig.clearCachedDLConfigs();
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) URI(java.net.URI) DLMetadata(org.apache.distributedlog.metadata.DLMetadata) Test(org.junit.Test)

Example 27 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.

the class TestFederatedZKLogMetadataStore method testZooKeeperSessionExpired.

@Test(timeout = 60000)
public void testZooKeeperSessionExpired() throws Exception {
    Set<String> allLogs = createLogs(2 * maxLogsPerSubnamespace, "test-zookeeper-session-expired-");
    TestNamespaceListenerWithExpectedSize listener = new TestNamespaceListenerWithExpectedSize(2 * maxLogsPerSubnamespace + 1);
    metadataStore.registerNamespaceListener(listener);
    ZooKeeperClientUtils.expireSession(zkc, BKNamespaceDriver.getZKServersFromDLUri(uri), zkSessionTimeoutMs);
    String testLogName = "test-log-name";
    allLogs.add(testLogName);
    DistributedLogConfiguration anotherConf = new DistributedLogConfiguration();
    anotherConf.addConfiguration(baseConf);
    ZooKeeperClient anotherZkc = TestZooKeeperClientBuilder.newBuilder().uri(uri).sessionTimeoutMs(zkSessionTimeoutMs).build();
    FederatedZKLogMetadataStore anotherMetadataStore = new FederatedZKLogMetadataStore(anotherConf, uri, anotherZkc, scheduler);
    Utils.ioResult(anotherMetadataStore.createLog(testLogName));
    listener.waitForDone();
    Set<String> receivedLogs = listener.getResult();
    assertEquals(2 * maxLogsPerSubnamespace + 1, receivedLogs.size());
    assertEquals(allLogs, receivedLogs);
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) Test(org.junit.Test)

Example 28 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.

the class TestFederatedZKLogMetadataStore method setup.

@Before
public void setup() throws Exception {
    zkc = TestZooKeeperClientBuilder.newBuilder().uri(createDLMURI("/")).sessionTimeoutMs(zkSessionTimeoutMs).build();
    scheduler = OrderedScheduler.newSchedulerBuilder().name("test-zk-logmetadata-store").numThreads(2).build();
    DistributedLogConfiguration conf = new DistributedLogConfiguration();
    conf.addConfiguration(baseConf);
    this.uri = createDLMURI("/" + runtime.getMethodName());
    FederatedZKLogMetadataStore.createFederatedNamespace(uri, zkc);
    metadataStore = new FederatedZKLogMetadataStore(conf, uri, zkc, scheduler);
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) Before(org.junit.Before)

Example 29 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.

the class TestLedgerAllocator method testAllocatorWithoutEnoughBookies.

@Test(timeout = 60000)
public void testAllocatorWithoutEnoughBookies() throws Exception {
    String allocationPath = "/allocator-without-enough-bookies";
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(conf);
    confLocal.setEnsembleSize(numBookies * 2);
    confLocal.setWriteQuorumSize(numBookies * 2);
    SimpleLedgerAllocator allocator1 = createAllocator(allocationPath, confLocal);
    allocator1.allocate();
    ZKTransaction txn1 = newTxn();
    try {
        Utils.ioResult(allocator1.tryObtain(txn1, NULL_LISTENER));
        fail("Should fail allocating ledger if there aren't enough bookies");
    } catch (AllocationException ioe) {
        // expected
        assertEquals(Phase.ERROR, ioe.getPhase());
    }
    byte[] data = zkc.get().getData(allocationPath, false, null);
    assertEquals(0, data.length);
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) ZKTransaction(org.apache.distributedlog.zk.ZKTransaction) AllocationException(org.apache.distributedlog.bk.SimpleLedgerAllocator.AllocationException) Test(org.junit.Test)

Example 30 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration 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

DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)39 Test (org.junit.Test)25 URI (java.net.URI)10 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)10 DLSN (org.apache.distributedlog.DLSN)9 LogRecordWithDLSN (org.apache.distributedlog.LogRecordWithDLSN)8 LogSegmentMetadata (org.apache.distributedlog.LogSegmentMetadata)8 Entry (org.apache.distributedlog.Entry)7 IOException (java.io.IOException)6 ZooKeeperClient (org.apache.distributedlog.ZooKeeperClient)5 Before (org.junit.Before)4 List (java.util.List)3 Feature (org.apache.bookkeeper.feature.Feature)3 Namespace (org.apache.distributedlog.api.namespace.Namespace)3 KeeperException (org.apache.zookeeper.KeeperException)3 Set (java.util.Set)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)2