Search in sources :

Example 31 with DistributedLogConfiguration

use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.

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(com.twitter.distributedlog.DistributedLogConfiguration) URI(java.net.URI) Test(org.junit.Test)

Example 32 with DistributedLogConfiguration

use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.

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(com.twitter.distributedlog.DistributedLogConfiguration) URI(java.net.URI) Test(org.junit.Test)

Example 33 with DistributedLogConfiguration

use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.

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(com.twitter.distributedlog.DistributedLogConfiguration) URI(java.net.URI) Test(org.junit.Test)

Example 34 with DistributedLogConfiguration

use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.

the class DistributedLogServerApp method runCmd.

private void runCmd(CommandLine cmdline) throws IllegalArgumentException, IOException, ConfigurationException {
    final StatsReceiver statsReceiver = NullStatsReceiver.get();
    Optional<String> confOptional = getOptionalStringArg(cmdline, "c");
    DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
    if (confOptional.isPresent()) {
        String configFile = confOptional.get();
        try {
            dlConf.loadConf(new File(configFile).toURI().toURL());
        } catch (ConfigurationException e) {
            throw new IllegalArgumentException("Failed to load distributedlog configuration from " + configFile + ".");
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("Failed to load distributedlog configuration from malformed " + configFile + ".");
        }
    }
    // load the stats provider
    final StatsProvider statsProvider = getOptionalStringArg(cmdline, "pd").transform(new Function<String, StatsProvider>() {

        @Nullable
        @Override
        public StatsProvider apply(@Nullable String name) {
            return ReflectionUtils.newInstance(name, StatsProvider.class);
        }
    }).or(new NullStatsProvider());
    final DistributedLogServer server = DistributedLogServer.runServer(getOptionalStringArg(cmdline, "u"), confOptional, getOptionalStringArg(cmdline, "sc"), getOptionalIntegerArg(cmdline, "p"), getOptionalIntegerArg(cmdline, "sp"), getOptionalIntegerArg(cmdline, "si"), getOptionalBooleanArg(cmdline, "a"), getOptionalBooleanArg(cmdline, "mx"), statsReceiver, statsProvider);
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            logger.info("Closing DistributedLog Server.");
            server.close();
            logger.info("Closed DistributedLog Server.");
            statsProvider.stop();
        }
    });
    try {
        server.join();
    } catch (InterruptedException e) {
        logger.warn("Interrupted when waiting distributedlog server to be finished : ", e);
    }
    logger.info("DistributedLog Service Interrupted.");
    server.close();
    logger.info("Closed DistributedLog Server.");
    statsProvider.stop();
}
Also used : MalformedURLException(java.net.MalformedURLException) StatsReceiver(com.twitter.finagle.stats.StatsReceiver) NullStatsReceiver(com.twitter.finagle.stats.NullStatsReceiver) DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) Function(com.google.common.base.Function) ConfigurationException(org.apache.commons.configuration.ConfigurationException) NullStatsProvider(org.apache.bookkeeper.stats.NullStatsProvider) StatsProvider(org.apache.bookkeeper.stats.StatsProvider) NullStatsProvider(org.apache.bookkeeper.stats.NullStatsProvider) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 35 with DistributedLogConfiguration

use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.

the class StreamBenchmark method parseCommandLine.

protected void parseCommandLine(String[] args) throws Exception {
    BasicParser parser = new BasicParser();
    CommandLine cmdline = parser.parse(options, args);
    if (cmdline.hasOption("h")) {
        printUsage();
        System.exit(0);
    }
    if (cmdline.hasOption("u")) {
        this.uri = URI.create(cmdline.getOptionValue("u"));
    } else {
        printUsage();
        System.exit(0);
    }
    this.conf = new DistributedLogConfiguration();
    if (cmdline.hasOption("c")) {
        String configFile = cmdline.getOptionValue("c");
        this.conf.loadConf(new File(configFile).toURI().toURL());
    }
    if (cmdline.hasOption("p")) {
        statsProvider = ReflectionUtils.newInstance(cmdline.getOptionValue("p"), StatsProvider.class);
    } else {
        statsProvider = new NullStatsProvider();
    }
    if (cmdline.hasOption("s")) {
        this.streamName = cmdline.getOptionValue("s");
    } else {
        printUsage();
        System.exit(0);
    }
    parseCommandLine(cmdline);
}
Also used : BasicParser(org.apache.commons.cli.BasicParser) DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) CommandLine(org.apache.commons.cli.CommandLine) NullStatsProvider(org.apache.bookkeeper.stats.NullStatsProvider) StatsProvider(org.apache.bookkeeper.stats.StatsProvider) NullStatsProvider(org.apache.bookkeeper.stats.NullStatsProvider) File(java.io.File)

Aggregations

DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)50 Test (org.junit.Test)32 URI (java.net.URI)12 IOException (java.io.IOException)7 DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)6 WriteResponse (com.twitter.distributedlog.thrift.service.WriteResponse)6 Before (org.junit.Before)6 ZooKeeperClient (com.twitter.distributedlog.ZooKeeperClient)5 ServerConfiguration (com.twitter.distributedlog.service.config.ServerConfiguration)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 StreamManagerImpl (com.twitter.distributedlog.service.stream.StreamManagerImpl)4 Future (com.twitter.util.Future)4 ArrayList (java.util.ArrayList)4 ConfigurationException (org.apache.commons.configuration.ConfigurationException)4 DistributedLogManager (com.twitter.distributedlog.DistributedLogManager)3 ConcurrentConstConfiguration (com.twitter.distributedlog.config.ConcurrentConstConfiguration)3 PropertiesWriter (com.twitter.distributedlog.config.PropertiesWriter)3 DistributedLogNamespace (com.twitter.distributedlog.namespace.DistributedLogNamespace)3 StreamConfigProvider (com.twitter.distributedlog.service.config.StreamConfigProvider)3 Stream (com.twitter.distributedlog.service.stream.Stream)3