Search in sources :

Example 6 with DistributedLogManager

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

the class TestDistributedLogTool method setupDefaults.

@BeforeClass
public static void setupDefaults() throws Exception {
    defaultUri = DLMTestUtil.createDLMURI(zkPort, defaultPath);
    DistributedLogManager dlm = DLMTestUtil.createNewDLM("DefaultStream", conf, defaultUri);
    bindStream(defaultUri, defaultLedgerPath, defaultHost);
    DLMTestUtil.generateCompletedLogSegments(dlm, conf, 3, 8192);
    dlm.close();
}
Also used : DistributedLogManager(com.twitter.distributedlog.DistributedLogManager) BeforeClass(org.junit.BeforeClass)

Example 7 with DistributedLogManager

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

the class TestDistributedLogTool method testToolTruncateStream.

@Test(timeout = 60000)
public void testToolTruncateStream() throws Exception {
    DistributedLogManager dlm = DLMTestUtil.createNewDLM("testToolTruncateStream", conf, defaultUri);
    DLMTestUtil.generateCompletedLogSegments(dlm, conf, 3, 1000);
    DLSN dlsn = new DLSN(2, 1, 0);
    TruncateStreamCommand cmd = new TruncateStreamCommand();
    cmd.setDlsn(dlsn);
    cmd.setUri(defaultUri);
    cmd.setStreamName("testToolTruncateStream");
    cmd.setForce(true);
    assertEquals(0, cmd.runCmd());
    LogReader reader = dlm.getInputStream(0);
    LogRecordWithDLSN record = reader.readNext(false);
    assertEquals(dlsn, record.getDlsn());
    reader.close();
    dlm.close();
}
Also used : LogRecordWithDLSN(com.twitter.distributedlog.LogRecordWithDLSN) DLSN(com.twitter.distributedlog.DLSN) LogRecordWithDLSN(com.twitter.distributedlog.LogRecordWithDLSN) DistributedLogManager(com.twitter.distributedlog.DistributedLogManager) LogReader(com.twitter.distributedlog.LogReader) Test(org.junit.Test)

Example 8 with DistributedLogManager

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

the class TestDLCK method testCheckAndRepairDLNamespace.

@Test(timeout = 60000)
@SuppressWarnings("deprecation")
public void testCheckAndRepairDLNamespace() throws Exception {
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.loadConf(conf);
    confLocal.setImmediateFlushEnabled(true);
    confLocal.setOutputBufferSize(0);
    confLocal.setLogSegmentSequenceNumberValidationEnabled(false);
    URI uri = createDLMURI("/check-and-repair-dl-namespace");
    zkc.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);
    ExecutorService executorService = Executors.newCachedThreadPool();
    String streamName = "check-and-repair-dl-namespace";
    // Create completed log segments
    DistributedLogManager dlm = factory.createDistributedLogManagerWithSharedClients(streamName);
    DLMTestUtil.injectLogSegmentWithLastDLSN(dlm, confLocal, 1L, 1L, 10, false);
    DLMTestUtil.injectLogSegmentWithLastDLSN(dlm, confLocal, 2L, 11L, 10, true);
    DLMTestUtil.injectLogSegmentWithLastDLSN(dlm, confLocal, 3L, 21L, 10, false);
    DLMTestUtil.injectLogSegmentWithLastDLSN(dlm, confLocal, 4L, 31L, 10, true);
    // dryrun
    BookKeeperClient bkc = getBookKeeperClient(factory);
    DistributedLogAdmin.checkAndRepairDLNamespace(uri, factory, new DryrunLogSegmentMetadataStoreUpdater(confLocal, getLogSegmentMetadataStore(factory)), executorService, bkc, confLocal.getBKDigestPW(), false, false);
    Map<Long, LogSegmentMetadata> segments = getLogSegments(dlm);
    LOG.info("segments after drynrun {}", segments);
    verifyLogSegment(segments, new DLSN(1L, 18L, 0L), 1L, 10, 10L);
    verifyLogSegment(segments, new DLSN(2L, 16L, 0L), 2L, 9, 19L);
    verifyLogSegment(segments, new DLSN(3L, 18L, 0L), 3L, 10, 30L);
    verifyLogSegment(segments, new DLSN(4L, 16L, 0L), 4L, 9, 39L);
    // check and repair
    bkc = getBookKeeperClient(factory);
    DistributedLogAdmin.checkAndRepairDLNamespace(uri, factory, LogSegmentMetadataStoreUpdater.createMetadataUpdater(confLocal, getLogSegmentMetadataStore(factory)), executorService, bkc, confLocal.getBKDigestPW(), false, false);
    segments = getLogSegments(dlm);
    LOG.info("segments after repair {}", segments);
    verifyLogSegment(segments, new DLSN(1L, 18L, 0L), 1L, 10, 10L);
    verifyLogSegment(segments, new DLSN(2L, 18L, 0L), 2L, 10, 20L);
    verifyLogSegment(segments, new DLSN(3L, 18L, 0L), 3L, 10, 30L);
    verifyLogSegment(segments, new DLSN(4L, 18L, 0L), 4L, 10, 40L);
    dlm.close();
    SchedulerUtils.shutdownScheduler(executorService, 5, TimeUnit.MINUTES);
    factory.close();
}
Also used : DLSN(com.twitter.distributedlog.DLSN) LogSegmentMetadata(com.twitter.distributedlog.LogSegmentMetadata) URI(java.net.URI) DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) DistributedLogManager(com.twitter.distributedlog.DistributedLogManager) BookKeeperClient(com.twitter.distributedlog.BookKeeperClient) DryrunLogSegmentMetadataStoreUpdater(com.twitter.distributedlog.metadata.DryrunLogSegmentMetadataStoreUpdater) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 9 with DistributedLogManager

use of com.twitter.distributedlog.DistributedLogManager 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 10 with DistributedLogManager

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

the class TestZKLogMetadataForWriter method testCreateLogMetadataWithCustomMetadata.

@Test(timeout = 60000)
public void testCreateLogMetadataWithCustomMetadata() throws Exception {
    URI uri = DLMTestUtil.createDLMURI(zkPort, "");
    String logName = testName.getMethodName();
    String logIdentifier = "<default>";
    List<String> pathsToDelete = Lists.newArrayList();
    DLMetadata.create(new BKDLConfig(zkServers, "/ledgers")).update(uri);
    DistributedLogNamespace namespace = DistributedLogNamespaceBuilder.newBuilder().conf(new DistributedLogConfiguration()).uri(uri).build();
    DistributedLogManager dlm = namespace.openLog(logName);
    dlm.createOrUpdateMetadata(logName.getBytes("UTF-8"));
    dlm.close();
    testCreateLogMetadataWithMissingPaths(uri, logName, logIdentifier, pathsToDelete, true, false);
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) DistributedLogNamespace(com.twitter.distributedlog.namespace.DistributedLogNamespace) DistributedLogManager(com.twitter.distributedlog.DistributedLogManager) BKDLConfig(com.twitter.distributedlog.metadata.BKDLConfig) URI(java.net.URI) Test(org.junit.Test)

Aggregations

DistributedLogManager (com.twitter.distributedlog.DistributedLogManager)22 Test (org.junit.Test)11 AsyncLogReader (com.twitter.distributedlog.AsyncLogReader)9 DLSN (com.twitter.distributedlog.DLSN)8 LogReader (com.twitter.distributedlog.LogReader)8 LogRecord (com.twitter.distributedlog.LogRecord)7 LogRecordWithDLSN (com.twitter.distributedlog.LogRecordWithDLSN)7 LogSegmentMetadata (com.twitter.distributedlog.LogSegmentMetadata)6 IOException (java.io.IOException)5 Stopwatch (com.google.common.base.Stopwatch)3 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)3 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 Counter (org.apache.bookkeeper.stats.Counter)3 DLIllegalStateException (com.twitter.distributedlog.exceptions.DLIllegalStateException)2 BKDLConfig (com.twitter.distributedlog.metadata.BKDLConfig)2 DryrunLogSegmentMetadataStoreUpdater (com.twitter.distributedlog.metadata.DryrunLogSegmentMetadataStoreUpdater)2 Future (com.twitter.util.Future)2 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)2 OpStatsLogger (org.apache.bookkeeper.stats.OpStatsLogger)2