Search in sources :

Example 1 with DistributedLogConfiguration

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

the class DistributedLogInputFormat method setConf.

/**
 * {@inheritDoc}
 */
@Override
public void setConf(Configuration configuration) {
    this.conf = configuration;
    dlConf = new DistributedLogConfiguration();
    dlUri = URI.create(configuration.get(DL_URI, ""));
    streamName = configuration.get(DL_STREAM, "");
    try {
        namespace = BKDistributedLogNamespace.newBuilder().conf(dlConf).uri(dlUri).build();
        dlm = namespace.openLog(streamName);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) IOException(java.io.IOException)

Example 2 with DistributedLogConfiguration

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

the class DistributedLogServer method runServer.

public void runServer() throws ConfigurationException, IllegalArgumentException, IOException {
    if (!uri.isPresent()) {
        throw new IllegalArgumentException("No distributedlog uri provided.");
    }
    URI dlUri = URI.create(uri.get());
    DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
    if (conf.isPresent()) {
        String configFile = conf.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 + ".");
        }
    }
    this.configExecutorService = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setNameFormat("DistributedLogService-Dyncfg-%d").setDaemon(true).build());
    // server configuration and dynamic configuration
    ServerConfiguration serverConf = new ServerConfiguration();
    serverConf.loadConf(dlConf);
    // overwrite the shard id if it is provided in the args
    if (shardId.isPresent()) {
        serverConf.setServerShardId(shardId.get());
    }
    serverConf.validate();
    DynamicDistributedLogConfiguration dynDlConf = getServiceDynConf(dlConf);
    logger.info("Starting stats provider : {}", statsProvider.getClass());
    statsProvider.start(dlConf);
    if (announceServerSet.isPresent() && announceServerSet.get()) {
        announcer = new ServerSetAnnouncer(dlUri, port.or(0), statsPort.or(0), shardId.or(0));
    } else {
        announcer = new NOPAnnouncer();
    }
    // Build the stream partition converter
    StreamPartitionConverter converter;
    try {
        converter = ReflectionUtils.newInstance(serverConf.getStreamPartitionConverterClass());
    } catch (ConfigurationException e) {
        logger.warn("Failed to load configured stream-to-partition converter. Fallback to use {}", IdentityStreamPartitionConverter.class.getName());
        converter = new IdentityStreamPartitionConverter();
    }
    StreamConfigProvider streamConfProvider = getStreamConfigProvider(dlConf, converter);
    // pre-run
    preRun(dlConf, serverConf);
    Pair<DistributedLogServiceImpl, Server> serverPair = runServer(serverConf, dlConf, dynDlConf, dlUri, converter, statsProvider, port.or(0), keepAliveLatch, statsReceiver, thriftmux.isPresent(), streamConfProvider);
    this.dlService = serverPair.getLeft();
    this.server = serverPair.getRight();
    // announce the service
    announcer.announce();
}
Also used : MalformedURLException(java.net.MalformedURLException) Server(com.twitter.finagle.builder.Server) ServerConfiguration(com.twitter.distributedlog.service.config.ServerConfiguration) URI(java.net.URI) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) IdentityStreamPartitionConverter(com.twitter.distributedlog.service.streamset.IdentityStreamPartitionConverter) StreamPartitionConverter(com.twitter.distributedlog.service.streamset.StreamPartitionConverter) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) ServerSetAnnouncer(com.twitter.distributedlog.service.announcer.ServerSetAnnouncer) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IdentityStreamPartitionConverter(com.twitter.distributedlog.service.streamset.IdentityStreamPartitionConverter) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) NOPAnnouncer(com.twitter.distributedlog.service.announcer.NOPAnnouncer) DefaultStreamConfigProvider(com.twitter.distributedlog.service.config.DefaultStreamConfigProvider) ServiceStreamConfigProvider(com.twitter.distributedlog.service.config.ServiceStreamConfigProvider) NullStreamConfigProvider(com.twitter.distributedlog.service.config.NullStreamConfigProvider) StreamConfigProvider(com.twitter.distributedlog.service.config.StreamConfigProvider) File(java.io.File)

Example 3 with DistributedLogConfiguration

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

the class TestDistributedLogAdmin method testChangeSequenceNumber.

/**
 * {@link https://issues.apache.org/jira/browse/DL-44}
 */
@DistributedLogAnnotations.FlakyTest
@Ignore
@Test(timeout = 60000)
@SuppressWarnings("deprecation")
public void testChangeSequenceNumber() throws Exception {
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(conf);
    confLocal.setLogSegmentSequenceNumberValidationEnabled(false);
    URI uri = createDLMURI("/change-sequence-number");
    zooKeeperClient.get().create(uri.getPath(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    com.twitter.distributedlog.DistributedLogManagerFactory factory = new com.twitter.distributedlog.DistributedLogManagerFactory(confLocal, uri);
    String streamName = "change-sequence-number";
    // create completed log segments
    DistributedLogManager dlm = factory.createDistributedLogManagerWithSharedClients(streamName);
    DLMTestUtil.generateCompletedLogSegments(dlm, confLocal, 4, 10);
    DLMTestUtil.injectLogSegmentWithGivenLogSegmentSeqNo(dlm, confLocal, 5, 41, false, 10, true);
    dlm.close();
    // create a reader
    DistributedLogManager readDLM = factory.createDistributedLogManagerWithSharedClients(streamName);
    AsyncLogReader reader = readDLM.getAsyncLogReader(DLSN.InitialDLSN);
    // read the records
    long expectedTxId = 1L;
    for (int i = 0; i < 4 * 10; i++) {
        LogRecord record = Await.result(reader.readNext());
        assertNotNull(record);
        DLMTestUtil.verifyLogRecord(record);
        assertEquals(expectedTxId, record.getTransactionId());
        expectedTxId++;
    }
    dlm = factory.createDistributedLogManagerWithSharedClients(streamName);
    DLMTestUtil.injectLogSegmentWithGivenLogSegmentSeqNo(dlm, confLocal, 3L, 5 * 10 + 1, true, 10, false);
    // Wait for reader to be aware of new log segments
    TimeUnit.SECONDS.sleep(2);
    DLSN dlsn = readDLM.getLastDLSN();
    assertTrue(dlsn.compareTo(new DLSN(5, Long.MIN_VALUE, Long.MIN_VALUE)) < 0);
    assertTrue(dlsn.compareTo(new DLSN(4, -1, Long.MIN_VALUE)) > 0);
    // there isn't records should be read
    Future<LogRecordWithDLSN> readFuture = reader.readNext();
    try {
        Await.result(readFuture, Duration.fromMilliseconds(1000));
        fail("Should fail reading next when there is a corrupted log segment");
    } catch (TimeoutException te) {
    // expected
    }
    // Dryrun
    DistributedLogAdmin.fixInprogressSegmentWithLowerSequenceNumber(factory, new DryrunLogSegmentMetadataStoreUpdater(confLocal, getLogSegmentMetadataStore(factory)), streamName, false, false);
    // Wait for reader to be aware of new log segments
    TimeUnit.SECONDS.sleep(2);
    dlsn = readDLM.getLastDLSN();
    assertTrue(dlsn.compareTo(new DLSN(5, Long.MIN_VALUE, Long.MIN_VALUE)) < 0);
    assertTrue(dlsn.compareTo(new DLSN(4, -1, Long.MIN_VALUE)) > 0);
    // there isn't records should be read
    try {
        Await.result(readFuture, Duration.fromMilliseconds(1000));
        fail("Should fail reading next when there is a corrupted log segment");
    } catch (TimeoutException te) {
    // expected
    }
    // Actual run
    DistributedLogAdmin.fixInprogressSegmentWithLowerSequenceNumber(factory, LogSegmentMetadataStoreUpdater.createMetadataUpdater(confLocal, getLogSegmentMetadataStore(factory)), streamName, false, false);
    // Wait for reader to be aware of new log segments
    TimeUnit.SECONDS.sleep(2);
    expectedTxId = 51L;
    LogRecord record = Await.result(readFuture);
    assertNotNull(record);
    DLMTestUtil.verifyLogRecord(record);
    assertEquals(expectedTxId, record.getTransactionId());
    expectedTxId++;
    for (int i = 1; i < 10; i++) {
        record = Await.result(reader.readNext());
        assertNotNull(record);
        DLMTestUtil.verifyLogRecord(record);
        assertEquals(expectedTxId, record.getTransactionId());
        expectedTxId++;
    }
    dlsn = readDLM.getLastDLSN();
    LOG.info("LastDLSN after fix inprogress segment : {}", dlsn);
    assertTrue(dlsn.compareTo(new DLSN(7, Long.MIN_VALUE, Long.MIN_VALUE)) < 0);
    assertTrue(dlsn.compareTo(new DLSN(6, -1, Long.MIN_VALUE)) > 0);
    Utils.close(reader);
    readDLM.close();
    dlm.close();
    factory.close();
}
Also used : LogRecordWithDLSN(com.twitter.distributedlog.LogRecordWithDLSN) DLSN(com.twitter.distributedlog.DLSN) LogRecordWithDLSN(com.twitter.distributedlog.LogRecordWithDLSN) AsyncLogReader(com.twitter.distributedlog.AsyncLogReader) URI(java.net.URI) DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) LogRecord(com.twitter.distributedlog.LogRecord) DistributedLogManager(com.twitter.distributedlog.DistributedLogManager) DryrunLogSegmentMetadataStoreUpdater(com.twitter.distributedlog.metadata.DryrunLogSegmentMetadataStoreUpdater) TimeoutException(com.twitter.util.TimeoutException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with DistributedLogConfiguration

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

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(com.twitter.distributedlog.DistributedLogConfiguration) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)

Example 5 with DistributedLogConfiguration

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

the class TestDynamicConfigurationFeatureProvider method testLoadFeaturesFromBase.

@Test(timeout = 60000)
public void testLoadFeaturesFromBase() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty("feature_1", "10000");
    writer.setProperty("feature_2", "5000");
    writer.save();
    DistributedLogConfiguration conf = new DistributedLogConfiguration().setDynamicConfigReloadIntervalSec(Integer.MAX_VALUE).setFileFeatureProviderBaseConfigPath(writer.getFile().toURI().toURL().getPath());
    DynamicConfigurationFeatureProvider provider = new DynamicConfigurationFeatureProvider("", conf, NullStatsLogger.INSTANCE);
    provider.start();
    ensureConfigReloaded();
    Feature feature1 = provider.getFeature("feature_1");
    assertTrue(feature1.isAvailable());
    assertEquals(10000, feature1.availability());
    Feature feature2 = provider.getFeature("feature_2");
    assertTrue(feature2.isAvailable());
    assertEquals(5000, feature2.availability());
    Feature feature3 = provider.getFeature("feature_3");
    assertFalse(feature3.isAvailable());
    assertEquals(0, feature3.availability());
    Feature feature4 = provider.getFeature("unknown_feature");
    assertFalse(feature4.isAvailable());
    assertEquals(0, feature4.availability());
    provider.stop();
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) PropertiesWriter(com.twitter.distributedlog.config.PropertiesWriter) Feature(org.apache.bookkeeper.feature.Feature) Test(org.junit.Test)

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