Search in sources :

Example 1 with DLMetadata

use of org.apache.distributedlog.metadata.DLMetadata in project bookkeeper by apache.

the class TestZkMetadataResolver method testResolve.

@Test(timeout = 60000)
public void testResolve() throws Exception {
    DLMetadata dlMetadata = DLMetadata.create(bkdlConfig);
    dlMetadata.create(createURI("/messaging/distributedlog-testresolve"));
    DLMetadata dlMetadata2 = DLMetadata.create(bkdlConfig2);
    dlMetadata2.create(createURI("/messaging/distributedlog-testresolve/child"));
    assertEquals(dlMetadata, resolver.resolve(createURI("/messaging/distributedlog-testresolve")));
    assertEquals(dlMetadata2, resolver.resolve(createURI("/messaging/distributedlog-testresolve/child")));
    assertEquals(dlMetadata2, resolver.resolve(createURI("/messaging/distributedlog-testresolve/child/unknown")));
    Utils.zkCreateFullPathOptimistic(zkc, "/messaging/distributedlog-testresolve/child/child2", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    assertEquals(dlMetadata2, resolver.resolve(createURI("/messaging/distributedlog-testresolve/child/child2")));
}
Also used : DLMetadata(org.apache.distributedlog.metadata.DLMetadata) Test(org.junit.Test)

Example 2 with DLMetadata

use of org.apache.distributedlog.metadata.DLMetadata in project bookkeeper by apache.

the class TestZkMetadataResolver method testFirstLogSegmentSequenceNumber.

@Test(timeout = 60000)
public void testFirstLogSegmentSequenceNumber() throws Exception {
    DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
    URI uri = createURI("/messaging/distributedlog-testfirstledgerseqno/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);
    assertEquals(DistributedLogConstants.FIRST_LOGSEGMENT_SEQNO, dlConf.getFirstLogSegmentSequenceNumber());
    BKDLConfig.clearCachedDLConfigs();
    DLMetadata meta2 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers").setFirstLogSegmentSeqNo(9999L));
    meta2.update(uri);
    BKDLConfig read2 = BKDLConfig.resolveDLConfig(zkc, uri);
    BKDLConfig.propagateConfiguration(read2, dlConf);
    assertEquals(9999L, dlConf.getFirstLogSegmentSequenceNumber());
    BKDLConfig.clearCachedDLConfigs();
    DLMetadata meta3 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers").setFirstLogSegmentSeqNo(99L));
    meta3.update(uri);
    BKDLConfig read3 = BKDLConfig.resolveDLConfig(zkc, uri);
    BKDLConfig.propagateConfiguration(read3, dlConf);
    assertEquals(99L, dlConf.getFirstLogSegmentSequenceNumber());
    BKDLConfig.clearCachedDLConfigs();
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) URI(java.net.URI) DLMetadata(org.apache.distributedlog.metadata.DLMetadata) Test(org.junit.Test)

Example 3 with DLMetadata

use of org.apache.distributedlog.metadata.DLMetadata in project incubator-pulsar by apache.

the class Utils method initializeDlogNamespace.

public static URI initializeDlogNamespace(String zkServers, String ledgersRootPath) throws IOException {
    BKDLConfig dlConfig = new BKDLConfig(zkServers, ledgersRootPath);
    DLMetadata dlMetadata = DLMetadata.create(dlConfig);
    URI dlogUri = URI.create(String.format("distributedlog://%s/pulsar/functions", zkServers));
    try {
        dlMetadata.create(dlogUri);
    } catch (ZKException e) {
        if (e.getKeeperExceptionCode() == Code.NODEEXISTS) {
            return dlogUri;
        }
        throw e;
    }
    return dlogUri;
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) BKDLConfig(org.apache.distributedlog.impl.metadata.BKDLConfig) DLMetadata(org.apache.distributedlog.metadata.DLMetadata) URI(java.net.URI)

Example 4 with DLMetadata

use of org.apache.distributedlog.metadata.DLMetadata in project bookkeeper by apache.

the class DLNamespaceProviderService method initializeNamespace.

private static URI initializeNamespace(ServerConfiguration bkServerConf, URI dlogUri) throws IOException {
    BKDLConfig dlConfig = new BKDLConfig(bkServerConf.getZkServers(), bkServerConf.getZkLedgersRootPath());
    DLMetadata dlMetadata = DLMetadata.create(dlConfig);
    try {
        log.info("Initializing dlog namespace at {}", dlogUri);
        dlMetadata.create(dlogUri);
        log.info("Initialized dlog namespace at {}", dlogUri);
    } catch (ZKException e) {
        if (e.getKeeperExceptionCode() == Code.NODEEXISTS) {
            if (log.isDebugEnabled()) {
                log.debug("Dlog uri is already bound at {}", dlogUri);
            }
            return dlogUri;
        }
        log.error("Failed to initialize dlog namespace at {}", dlogUri, e);
        throw e;
    }
    return dlogUri;
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) BKDLConfig(org.apache.distributedlog.impl.metadata.BKDLConfig) DLMetadata(org.apache.distributedlog.metadata.DLMetadata)

Example 5 with DLMetadata

use of org.apache.distributedlog.metadata.DLMetadata in project bookkeeper by apache.

the class TestZkMetadataResolver method testEncodeRegionID.

@Test(timeout = 60000)
public void testEncodeRegionID() throws Exception {
    DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
    URI uri = createURI("/messaging/distributedlog-testencoderegionid/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);
    assertFalse(dlConf.getEncodeRegionIDInLogSegmentMetadata());
    BKDLConfig.clearCachedDLConfigs();
    DLMetadata meta2 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers").setEncodeRegionID(true));
    meta2.update(uri);
    BKDLConfig read2 = BKDLConfig.resolveDLConfig(zkc, uri);
    BKDLConfig.propagateConfiguration(read2, dlConf);
    assertTrue(dlConf.getEncodeRegionIDInLogSegmentMetadata());
    BKDLConfig.clearCachedDLConfigs();
    DLMetadata meta3 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers").setEncodeRegionID(false));
    meta3.update(uri);
    BKDLConfig read3 = BKDLConfig.resolveDLConfig(zkc, uri);
    BKDLConfig.propagateConfiguration(read3, dlConf);
    assertFalse(dlConf.getEncodeRegionIDInLogSegmentMetadata());
    BKDLConfig.clearCachedDLConfigs();
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) URI(java.net.URI) DLMetadata(org.apache.distributedlog.metadata.DLMetadata) Test(org.junit.Test)

Aggregations

DLMetadata (org.apache.distributedlog.metadata.DLMetadata)6 URI (java.net.URI)4 Test (org.junit.Test)4 DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)3 ZKException (org.apache.distributedlog.exceptions.ZKException)2 BKDLConfig (org.apache.distributedlog.impl.metadata.BKDLConfig)2