Search in sources :

Example 21 with DistributedLogManager

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

the class TestDistributedLogTool method testToolTruncate.

@Test(timeout = 60000)
public void testToolTruncate() throws Exception {
    DistributedLogManager dlm = DLMTestUtil.createNewDLM("TruncateStream", conf, defaultUri);
    DLMTestUtil.generateCompletedLogSegments(dlm, conf, 3, 1000);
    dlm.close();
    TruncateCommand cmd = new TruncateCommand();
    cmd.setUri(defaultUri);
    cmd.setFilter("TruncateStream");
    cmd.setForce(true);
    assertEquals(0, cmd.runCmd());
}
Also used : DistributedLogManager(com.twitter.distributedlog.DistributedLogManager) Test(org.junit.Test)

Example 22 with DistributedLogManager

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

the class DistributedLogAdmin method fixInprogressSegmentWithLowerSequenceNumber.

/**
     * Fix inprogress segment with lower ledger sequence number.
     *
     * @param factory
     *          dlm factory.
     * @param metadataUpdater
     *          metadata updater.
     * @param streamName
     *          stream name.
     * @param verbose
     *          print verbose messages.
     * @param interactive
     *          is confirmation needed before executing actual action.
     * @throws IOException
     */
public static void fixInprogressSegmentWithLowerSequenceNumber(final com.twitter.distributedlog.DistributedLogManagerFactory factory, final MetadataUpdater metadataUpdater, final String streamName, final boolean verbose, final boolean interactive) throws IOException {
    DistributedLogManager dlm = factory.createDistributedLogManagerWithSharedClients(streamName);
    try {
        List<LogSegmentMetadata> segments = dlm.getLogSegments();
        if (verbose) {
            System.out.println("LogSegments for " + streamName + " : ");
            for (LogSegmentMetadata segment : segments) {
                System.out.println(segment.getLogSegmentSequenceNumber() + "\t: " + segment);
            }
        }
        LOG.info("Get log segments for {} : {}", streamName, segments);
        // validate log segments
        long maxCompletedLogSegmentSequenceNumber = -1L;
        LogSegmentMetadata inprogressSegment = null;
        for (LogSegmentMetadata segment : segments) {
            if (!segment.isInProgress()) {
                maxCompletedLogSegmentSequenceNumber = Math.max(maxCompletedLogSegmentSequenceNumber, segment.getLogSegmentSequenceNumber());
            } else {
                // we already found an inprogress segment
                if (null != inprogressSegment) {
                    throw new DLIllegalStateException("Multiple inprogress segments found for stream " + streamName + " : " + segments);
                }
                inprogressSegment = segment;
            }
        }
        if (null == inprogressSegment || inprogressSegment.getLogSegmentSequenceNumber() > maxCompletedLogSegmentSequenceNumber) {
            // nothing to fix
            return;
        }
        final long newLogSegmentSequenceNumber = maxCompletedLogSegmentSequenceNumber + 1;
        if (interactive && !IOUtils.confirmPrompt("Confirm to fix (Y/N), Ctrl+C to break : ")) {
            return;
        }
        final LogSegmentMetadata newSegment = FutureUtils.result(metadataUpdater.changeSequenceNumber(inprogressSegment, newLogSegmentSequenceNumber));
        LOG.info("Fixed {} : {} -> {} ", new Object[] { streamName, inprogressSegment, newSegment });
        if (verbose) {
            System.out.println("Fixed " + streamName + " : " + inprogressSegment.getZNodeName() + " -> " + newSegment.getZNodeName());
            System.out.println("\t old: " + inprogressSegment);
            System.out.println("\t new: " + newSegment);
            System.out.println();
        }
    } finally {
        dlm.close();
    }
}
Also used : DistributedLogManager(com.twitter.distributedlog.DistributedLogManager) LogSegmentMetadata(com.twitter.distributedlog.LogSegmentMetadata) DLIllegalStateException(com.twitter.distributedlog.exceptions.DLIllegalStateException)

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