org.apache.distributedlog.DistributedLogConfiguration Java Examples

The following examples show how to use org.apache.distributedlog.DistributedLogConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestServiceRequestLimiter.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testDynamicLimiterWithException() throws Exception {
    final AtomicInteger id = new AtomicInteger(0);
    final DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(
            new ConcurrentConstConfiguration(new DistributedLogConfiguration()));
    DynamicRequestLimiter<MockRequest> limiter = new DynamicRequestLimiter<MockRequest>(
            dynConf, NullStatsLogger.INSTANCE, new SettableFeature("", 0)) {
        @Override
        public RequestLimiter<MockRequest> build() {
            if (id.incrementAndGet() >= 2) {
                throw new RuntimeException("exception in dynamic limiter build()");
            }
            return new MockRequestLimiter();
        }
    };
    limiter.initialize();
    assertEquals(1, id.get());
    try {
        dynConf.setProperty("test1", 1);
        fail("should have thrown on config failure");
    } catch (RuntimeException ex) {
    }
    assertEquals(2, id.get());
}
 
Example #2
Source File: TestDynamicConfigurationFactory.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
/**
 * If the file is missing, get-config should not fail, and the file should be picked up if its added.
 * If the file is removed externally same should apply.
 */
@Test(timeout = 60000)
public void testMissingConfig() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    DynamicConfigurationFactory factory = getConfigFactory(writer.getFile());
    Optional<DynamicDistributedLogConfiguration> conf = factory.getDynamicConfiguration(writer.getFile().getPath());
    writer.setProperty(DistributedLogConfiguration.BKDL_RETENTION_PERIOD_IN_HOURS, "1");
    writer.save();
    waitForConfig(conf.get(), 1);
    File configFile = writer.getFile();
    configFile.delete();
    Thread.sleep(1000);
    PropertiesWriter writer2 = new PropertiesWriter(writer.getFile());
    writer2.setProperty(DistributedLogConfiguration.BKDL_RETENTION_PERIOD_IN_HOURS, "2");
    writer2.save();
    waitForConfig(conf.get(), 2);
}
 
Example #3
Source File: DistributedLogServer.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
private StreamConfigProvider getStreamConfigProvider(DistributedLogConfiguration dlConf,
                                                     StreamPartitionConverter partitionConverter)
        throws ConfigurationException {
    StreamConfigProvider streamConfProvider = new NullStreamConfigProvider();
    if (streamConf.isPresent() && conf.isPresent()) {
        String dynConfigPath = streamConf.get();
        String defaultConfigFile = conf.get();
        streamConfProvider = new ServiceStreamConfigProvider(
                dynConfigPath,
                defaultConfigFile,
                partitionConverter,
                configExecutorService,
                dlConf.getDynamicConfigReloadIntervalSec(),
                TimeUnit.SECONDS);
    } else if (conf.isPresent()) {
        String configFile = conf.get();
        streamConfProvider = new DefaultStreamConfigProvider(configFile, configExecutorService,
                dlConf.getDynamicConfigReloadIntervalSec(), TimeUnit.SECONDS);
    }
    return streamConfProvider;
}
 
Example #4
Source File: TestBKLogSegmentEntryReader.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
void generateCompletedLogSegments(DistributedLogManager dlm,
                                  DistributedLogConfiguration conf,
                                  long numCompletedSegments,
                                  long segmentSize) throws Exception {
    long txid = 1L;
    for (long i = 0; i < numCompletedSegments; i++) {
        AsyncLogWriter writer = Utils.ioResult(dlm.openAsyncLogWriter());
        for (long j = 1; j <= segmentSize; j++) {
            Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(txid++)));
            LogRecord ctrlRecord = DLMTestUtil.getLogRecordInstance(txid);
            ctrlRecord.setControl();
            Utils.ioResult(writer.write(ctrlRecord));
        }
        Utils.close(writer);
    }
}
 
Example #5
Source File: StreamFactoryImpl.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
public StreamFactoryImpl(String clientId,
    StreamOpStats streamOpStats,
    ServerConfiguration serverConfig,
    DistributedLogConfiguration dlConfig,
    FeatureProvider featureProvider,
    StreamConfigProvider streamConfigProvider,
    StreamPartitionConverter streamPartitionConverter,
    Namespace dlNamespace,
    OrderedScheduler scheduler,
    FatalErrorHandler fatalErrorHandler,
    HashedWheelTimer requestTimer) {

    this.clientId = clientId;
    this.streamOpStats = streamOpStats;
    this.serverConfig = serverConfig;
    this.dlConfig = dlConfig;
    this.featureProvider = featureProvider;
    this.streamConfigProvider = streamConfigProvider;
    this.streamPartitionConverter = streamPartitionConverter;
    this.dlNamespace = dlNamespace;
    this.scheduler = scheduler;
    this.fatalErrorHandler = fatalErrorHandler;
    this.requestTimer = requestTimer;
    this.futureTimer = new com.twitter.finagle.util.HashedWheelTimer(requestTimer);
}
 
Example #6
Source File: DlogStorage.java    From incubator-heron with Apache License 2.0 6 votes vote down vote up
Namespace initializeNamespace(URI uri) throws IOException {
  DistributedLogConfiguration conf = new DistributedLogConfiguration()
      .setWriteLockEnabled(false)
      .setOutputBufferSize(256 * 1024)                  // 256k
      .setPeriodicFlushFrequencyMilliSeconds(0)         // disable periodical flush
      .setImmediateFlushEnabled(false)                  // disable immediate flush
      .setLogSegmentRollingIntervalMinutes(0)           // disable time-based rolling
      .setMaxLogSegmentBytes(Long.MAX_VALUE)            // disable size-based rolling
      .setExplicitTruncationByApplication(true)         // no auto-truncation
      .setRetentionPeriodHours(Integer.MAX_VALUE)       // long retention
      .setEnsembleSize(numReplicas)                     // replica settings
      .setWriteQuorumSize(numReplicas)
      .setAckQuorumSize(numReplicas)
      .setUseDaemonThread(true)                         // use daemon thread
      .setNumWorkerThreads(1)                           // use 1 worker thread
      .setBKClientNumberIOThreads(1);

  conf.addProperty("bkc.allowShadedLedgerManagerFactoryClass", true);

  return this.nsBuilderSupplier.get()
      .clientId("heron-stateful-storage")
      .conf(conf)
      .uri(uri)
      .build();
}
 
Example #7
Source File: TestServiceRequestLimiter.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testDynamicLimiter() throws Exception {
    final AtomicInteger id = new AtomicInteger(0);
    final DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(
            new ConcurrentConstConfiguration(new DistributedLogConfiguration()));
    DynamicRequestLimiter<MockRequest> limiter = new DynamicRequestLimiter<MockRequest>(
            dynConf, NullStatsLogger.INSTANCE, new SettableFeature("", 0)) {
        @Override
        public RequestLimiter<MockRequest> build() {
            id.getAndIncrement();
            return new MockRequestLimiter();
        }
    };
    limiter.initialize();
    assertEquals(1, id.get());
    dynConf.setProperty("test1", 1);
    assertEquals(2, id.get());
    dynConf.setProperty("test2", 2);
    assertEquals(3, id.get());
}
 
Example #8
Source File: TestZKLogStreamMetadataStore.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testCreateLogMetadataWithCustomMetadata() throws Exception {
    String logName = testName.getMethodName();
    String logIdentifier = "<default>";
    List<String> pathsToDelete = Lists.newArrayList();

    DLMetadata.create(new BKDLConfig(zkServers, "/ledgers")).update(uri);

    Namespace namespace = NamespaceBuilder.newBuilder()
        .conf(new DistributedLogConfiguration())
        .uri(uri)
        .build();

    MetadataAccessor accessor = namespace.getNamespaceDriver().getMetadataAccessor(logName);
    accessor.createOrUpdateMetadata(logName.getBytes("UTF-8"));
    accessor.close();

    testCreateLogMetadataWithMissingPaths(uri, logName, logIdentifier, pathsToDelete, true, false);
}
 
Example #9
Source File: TestDistributedLogService.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
private DistributedLogServiceImpl createService(
        ServerConfiguration serverConf,
        DistributedLogConfiguration dlConf,
        CountDownLatch latch) throws Exception {
    // 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();
    }
    return new DistributedLogServiceImpl(
        serverConf,
        dlConf,
        ConfUtils.getConstDynConf(dlConf),
        new NullStreamConfigProvider(),
        uri,
        converter,
        new LocalRoutingService(),
        NullStatsLogger.INSTANCE,
        NullStatsLogger.INSTANCE,
        latch,
        new EqualLoadAppraiser());
}
 
Example #10
Source File: TestZKLogSegmentMetadataStore.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
    zkc = TestZooKeeperClientBuilder.newBuilder()
            .uri(createDLMURI("/"))
            .sessionTimeoutMs(zkSessionTimeoutMs)
            .build();
    scheduler = OrderedScheduler.newBuilder()
            .name("test-zk-logsegment-metadata-store")
            .corePoolSize(1)
            .build();
    DistributedLogConfiguration conf = new DistributedLogConfiguration();
    conf.addConfiguration(baseConf);
    this.uri = createDLMURI("/" + runtime.getMethodName());
    lsmStore = new ZKLogSegmentMetadataStore(conf, zkc, scheduler);
    zkc.get().create(
            "/" + runtime.getMethodName(),
            new byte[0],
            ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    this.rootZkPath = "/" + runtime.getMethodName();
}
 
Example #11
Source File: DLMetadata.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
public void create(URI uri) throws IOException {
    DistributedLogConfiguration conf = new DistributedLogConfiguration();
    ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder()
            .sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds())
            .retryThreadCount(conf.getZKClientNumberRetryThreads())
            .requestRateLimit(conf.getZKRequestRateLimit())
            .zkAclId(conf.getZkAclId())
            .uri(uri)
            .build();
    byte[] data = serialize();
    try {
        Utils.zkCreateFullPathOptimistic(zkc, uri.getPath(), data,
            zkc.getDefaultACL(), CreateMode.PERSISTENT);
    } catch (KeeperException ke) {
        throw new ZKException("Encountered zookeeper exception on creating dl metadata", ke);
    } finally {
        zkc.close();
    }
}
 
Example #12
Source File: DlogStorageTest.java    From incubator-heron with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws Exception {
  Map<String, Object> config = new HashMap<>();
  config.put(DlogStorage.NS_URI_KEY, ROOT_URI);

  mockNamespace = mock(Namespace.class);
  mockNsBuilder = mock(NamespaceBuilder.class);
  when(mockNsBuilder.clientId(anyString())).thenReturn(mockNsBuilder);
  when(mockNsBuilder.conf(any(DistributedLogConfiguration.class))).thenReturn(mockNsBuilder);
  when(mockNsBuilder.uri(any(URI.class))).thenReturn(mockNsBuilder);
  when(mockNsBuilder.build()).thenReturn(mockNamespace);

  dlogStorage = new DlogStorage(() -> mockNsBuilder);
  dlogStorage.init(StatefulStorageTestContext.TOPOLOGY_NAME, config);
  dlogStorage = spy(dlogStorage);

  instance = StatefulStorageTestContext.getInstance();
  checkpointPartition = StatefulStorageTestContext.getInstanceStateCheckpoint();
}
 
Example #13
Source File: DLFileSystem.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
private FSDataOutputStream append(Path path,
                                  int bufferSize,
                                  Optional<DistributedLogConfiguration> confLocal)
        throws IOException {
    try {
        DistributedLogManager dlm = namespace.openLog(
            getStreamName(path),
            confLocal,
            Optional.empty(),
            Optional.empty());
        AsyncLogWriter writer = Utils.ioResult(dlm.openAsyncLogWriter());
        return new FSDataOutputStream(
            new BufferedOutputStream(
                new DLOutputStream(dlm, writer), bufferSize
            ),
            statistics,
            writer.getLastTxId() < 0L ? 0L : writer.getLastTxId());
    } catch (LogNotFoundException le) {
        throw new FileNotFoundException(path.toString());
    }
}
 
Example #14
Source File: TestFederatedZKLogMetadataStore.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #15
Source File: BKLogSegmentEntryStore.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
public BKLogSegmentEntryStore(DistributedLogConfiguration conf,
                              DynamicDistributedLogConfiguration dynConf,
                              ZooKeeperClient zkc,
                              BookKeeperClient bkc,
                              OrderedScheduler scheduler,
                              LedgerAllocator allocator,
                              StatsLogger statsLogger,
                              AsyncFailureInjector failureInjector) {
    this.conf = conf;
    this.dynConf = dynConf;
    this.zkc = zkc;
    this.bkc = bkc;
    this.passwd = conf.getBKDigestPW().getBytes(UTF_8);
    this.scheduler = scheduler;
    this.allocator = allocator;
    this.statsLogger = statsLogger;
    this.failureInjector = failureInjector;
}
 
Example #16
Source File: TestFederatedZKLogMetadataStore.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
    zkc = TestZooKeeperClientBuilder.newBuilder()
            .uri(createDLMURI("/"))
            .sessionTimeoutMs(zkSessionTimeoutMs)
            .build();
    scheduler = OrderedScheduler.newBuilder()
            .name("test-zk-logmetadata-store")
            .corePoolSize(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);
}
 
Example #17
Source File: BKNamespaceDriver.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
public static String
validateAndGetFullLedgerAllocatorPoolPath(DistributedLogConfiguration conf, URI uri) throws IOException {
    String poolPath = conf.getLedgerAllocatorPoolPath();
    LOG.info("PoolPath is {}", poolPath);
    if (null == poolPath || !poolPath.startsWith(".") || poolPath.endsWith("/")) {
        LOG.error("Invalid ledger allocator pool path specified when enabling ledger allocator pool: {}", poolPath);
        throw new IOException("Invalid ledger allocator pool path specified : " + poolPath);
    }
    String poolName = conf.getLedgerAllocatorPoolName();
    if (null == poolName) {
        LOG.error("No ledger allocator pool name specified when enabling ledger allocator pool.");
        throw new IOException("No ledger allocator name specified when enabling ledger allocator pool.");
    }
    String rootPath = uri.getPath() + "/" + poolPath + "/" + poolName;
    try {
        PathUtils.validatePath(rootPath);
    } catch (IllegalArgumentException iae) {
        LOG.error("Invalid ledger allocator pool path specified when enabling ledger allocator pool: {}", poolPath);
        throw new IOException("Invalid ledger allocator pool path specified : " + poolPath);
    }
    return rootPath;
}
 
Example #18
Source File: BKNamespaceDriver.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
private BookKeeperClientBuilder createBKCBuilder(String bkcName,
                                                 DistributedLogConfiguration conf,
                                                 String zkServers,
                                                 String ledgersPath,
                                                 EventLoopGroup eventLoopGroup,
                                                 HashedWheelTimer requestTimer,
                                                 Optional<FeatureProvider> featureProviderOptional,
                                                 StatsLogger statsLogger) {
    BookKeeperClientBuilder builder = BookKeeperClientBuilder.newBuilder()
            .name(bkcName)
            .dlConfig(conf)
            .zkServers(zkServers)
            .ledgersPath(ledgersPath)
            .eventLoopGroup(eventLoopGroup)
            .requestTimer(requestTimer)
            .featureProvider(featureProviderOptional)
            .statsLogger(statsLogger);
    LOG.info("Created shared client builder {} : zkServers = {}, ledgersPath = {}, numIOThreads = {}",
            new Object[] { bkcName, zkServers, ledgersPath, conf.getBKClientNumberIOThreads() });
    return builder;
}
 
Example #19
Source File: TestBKLogSegmentEntryReader.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
AsyncLogWriter createInprogressLogSegment(DistributedLogManager dlm,
                                          DistributedLogConfiguration conf,
                                          long segmentSize) throws Exception {
    AsyncLogWriter writer = Utils.ioResult(dlm.openAsyncLogWriter());
    for (long i = 1L; i <= segmentSize; i++) {
        Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(i)));
        LogRecord ctrlRecord = DLMTestUtil.getLogRecordInstance(i);
        ctrlRecord.setControl();
        Utils.ioResult(writer.write(ctrlRecord));
    }
    return writer;
}
 
Example #20
Source File: DistributedLogServer.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
private DynamicDistributedLogConfiguration getServiceDynConf(DistributedLogConfiguration dlConf)
    throws ConfigurationException {
    Optional<DynamicDistributedLogConfiguration> dynConf = Optional.absent();
    if (conf.isPresent()) {
        DynamicConfigurationFactory configFactory = new DynamicConfigurationFactory(
                configExecutorService, dlConf.getDynamicConfigReloadIntervalSec(), TimeUnit.SECONDS);
        dynConf = configFactory.getDynamicConfiguration(conf.get());
    }
    if (dynConf.isPresent()) {
        return dynConf.get();
    } else {
        return ConfUtils.getConstDynConf(dlConf);
    }
}
 
Example #21
Source File: WorkerUtils.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public static DistributedLogConfiguration getDlogConf(WorkerConfig workerConfig) {
    int numReplicas = workerConfig.getNumFunctionPackageReplicas();

    DistributedLogConfiguration conf = new DistributedLogConfiguration()
            .setWriteLockEnabled(false)
            .setOutputBufferSize(256 * 1024)                  // 256k
            .setPeriodicFlushFrequencyMilliSeconds(0)         // disable periodical flush
            .setImmediateFlushEnabled(false)                  // disable immediate flush
            .setLogSegmentRollingIntervalMinutes(0)           // disable time-based rolling
            .setMaxLogSegmentBytes(Long.MAX_VALUE)            // disable size-based rolling
            .setExplicitTruncationByApplication(true)         // no auto-truncation
            .setRetentionPeriodHours(Integer.MAX_VALUE)       // long retention
            .setEnsembleSize(numReplicas)                     // replica settings
            .setWriteQuorumSize(numReplicas)
            .setAckQuorumSize(numReplicas)
            .setUseDaemonThread(true);
    conf.setProperty("bkc.allowShadedLedgerManagerFactoryClass", true);
    conf.setProperty("bkc.shadedLedgerManagerFactoryClassPrefix", "dlshade.");
    if (isNotBlank(workerConfig.getBookkeeperClientAuthenticationPlugin())) {
        conf.setProperty("bkc.clientAuthProviderFactoryClass",
                workerConfig.getBookkeeperClientAuthenticationPlugin());
        if (isNotBlank(workerConfig.getBookkeeperClientAuthenticationParametersName())) {
            conf.setProperty("bkc." + workerConfig.getBookkeeperClientAuthenticationParametersName(),
                    workerConfig.getBookkeeperClientAuthenticationParameters());
        }
    }
    return conf;
}
 
Example #22
Source File: DistributedLogTool.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
protected PerDLCommand(String name, String description) {
    super(name, description);
    dlConf = new DistributedLogConfiguration();
    // Tools are allowed to read old metadata as long as they can interpret it
    dlConf.setDLLedgerMetadataSkipMinVersionCheck(true);
    options.addOption("u", "uri", true, "DistributedLog URI");
    options.addOption("c", "conf", true, "DistributedLog Configuration File");
    options.addOption("a", "zk-acl-id", true, "Zookeeper ACL ID");
    options.addOption("f", "force", false, "Force command (no warnings or prompts)");
}
 
Example #23
Source File: TestBKLogSegmentEntryReader.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
BKLogSegmentEntryReader createEntryReader(LogSegmentMetadata segment,
                                          long startEntryId,
                                          DistributedLogConfiguration conf)
        throws Exception {
    LogSegmentEntryStore store = new BKLogSegmentEntryStore(
            conf,
            ConfUtils.getConstDynConf(conf),
            zkc,
            bkc,
            scheduler,
            null,
            NullStatsLogger.INSTANCE,
            AsyncFailureInjector.NULL);
    return (BKLogSegmentEntryReader) Utils.ioResult(store.openReader(segment, startEntryId));
}
 
Example #24
Source File: TestZkMetadataResolver.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #25
Source File: DynamicConfigurationFeatureProvider.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public DynamicConfigurationFeatureProvider(String rootScope,
                                           DistributedLogConfiguration conf,
                                           StatsLogger statsLogger) {
    super(rootScope, conf, statsLogger);
    this.features = new ConcurrentHashMap<String, SettableFeature>();
    this.featuresConf = new ConcurrentBaseConfiguration();
    this.executorService = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setNameFormat("DynamicConfigurationFeatureProvider-%d").build());
}
 
Example #26
Source File: DistributedLogTool.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
protected AuditCommand(String name, String description) {
    super(name, description);
    dlConf = new DistributedLogConfiguration();
    options.addOption("u", "uris", true, "List of distributedlog uris, separated by comma");
    options.addOption("c", "conf", true, "DistributedLog Configuration File");
    options.addOption("a", "zk-acl-id", true, "ZooKeeper ACL ID");
    options.addOption("f", "force", false, "Force command (no warnings or prompts)");
}
 
Example #27
Source File: TestZKLogStreamMetadataStore.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
    zkc = TestZooKeeperClientBuilder.newBuilder()
            .name("zkc")
            .uri(DLMTestUtil.createDLMURI(zkPort, "/"))
            .sessionTimeoutMs(sessionTimeoutMs)
            .build();
    uri = DLMTestUtil.createDLMURI(zkPort, "");
    try {
        ZkUtils.createFullPathOptimistic(
                zkc.get(),
                uri.getPath(),
                new byte[0],
                ZooDefs.Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);
    } catch (KeeperException.NodeExistsException nee) {
        logger.debug("The namespace uri already exists.");
    }
    scheduler = OrderedScheduler.newBuilder()
        .name("test-scheduler")
        .corePoolSize(1)
        .build();
    metadataStore = new ZKLogStreamMetadataStore(
        "test-logstream-metadata-store",
        new DistributedLogConfiguration(),
        zkc,
        scheduler,
        NullStatsLogger.INSTANCE);
}
 
Example #28
Source File: TestNamespaceBuilder.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testBuildWhenMissingBackendInUri() throws Exception {
    Namespace namespace = NamespaceBuilder.newBuilder()
            .conf(new DistributedLogConfiguration())
            .uri(new URI("distributedlog://" + zkServers + DLOG_NAMESPACE + "/defaultnamespace"))
            .build();
    try {
        assertTrue("distributedlog:// should build bookkeeper based distributedlog namespace",
                namespace instanceof BKDistributedLogNamespace);
    } finally {
        namespace.close();
    }
}
 
Example #29
Source File: BKLogSegmentEntryReader.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
BKLogSegmentEntryReader(LogSegmentMetadata metadata,
                        LedgerHandle lh,
                        long startEntryId,
                        BookKeeper bk,
                        OrderedScheduler scheduler,
                        DistributedLogConfiguration conf,
                        StatsLogger statsLogger,
                        AsyncFailureInjector failureInjector) {
    this.metadata = metadata;
    this.lssn = metadata.getLogSegmentSequenceNumber();
    this.startSequenceId = metadata.getStartSequenceId();
    this.envelopeEntries = metadata.getEnvelopeEntries();
    this.deserializeRecordSet = conf.getDeserializeRecordSetOnReads();
    this.lh = lh;
    this.nextEntryId = Math.max(startEntryId, 0);
    this.bk = bk;
    this.conf = conf;
    this.numPrefetchEntries = conf.getNumPrefetchEntriesPerLogSegment();
    this.maxPrefetchEntries = conf.getMaxPrefetchEntriesPerLogSegment();
    this.scheduler = scheduler;
    this.openLedgerHandles = Lists.newArrayList();
    this.openLedgerHandles.add(lh);
    this.outstandingLongPoll = null;
    // create the readahead queue
    this.readAheadEntries = new LinkedBlockingQueue<CacheEntry>();
    // create the read request queue
    this.readQueue = new LinkedList<PendingReadRequest>();
    // read backoff settings
    this.readAheadWaitTime = conf.getReadAheadWaitTime();
    this.maxReadBackoffTime = 4 * conf.getReadAheadWaitTime();
    // other read settings
    this.skipBrokenEntries = conf.getReadAheadSkipBrokenEntries();

    // Failure Injection
    this.failureInjector = failureInjector;
    // Stats
    this.skippedBrokenEntriesCounter = statsLogger.getCounter("skipped_broken_entries");
}
 
Example #30
Source File: TestNamespaceBuilder.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testBuildBKDistributedLogNamespace() throws Exception {
    Namespace namespace = NamespaceBuilder.newBuilder()
            .conf(new DistributedLogConfiguration())
            .uri(new URI("distributedlog-bk://" + zkServers + DLOG_NAMESPACE + "/bknamespace"))
            .build();
    try {
        assertTrue("distributedlog-bk:// should build bookkeeper based distributedlog namespace",
                namespace instanceof BKDistributedLogNamespace);
    } finally {
        namespace.close();
    }
}