Search in sources :

Example 11 with DistributedLogManager

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

the class DistributedLogAdmin method checkStream.

private static StreamCandidate checkStream(final com.twitter.distributedlog.DistributedLogManagerFactory factory, final String streamName, final ExecutorService executorService, final BookKeeperClient bkc, String digestpw) throws IOException {
    DistributedLogManager dlm = factory.createDistributedLogManagerWithSharedClients(streamName);
    try {
        List<LogSegmentMetadata> segments = dlm.getLogSegments();
        if (segments.isEmpty()) {
            return null;
        }
        List<Future<LogSegmentCandidate>> futures = new ArrayList<Future<LogSegmentCandidate>>(segments.size());
        for (LogSegmentMetadata segment : segments) {
            futures.add(checkLogSegment(streamName, segment, executorService, bkc, digestpw));
        }
        List<LogSegmentCandidate> segmentCandidates;
        try {
            segmentCandidates = Await.result(Future.collect(futures));
        } catch (Exception e) {
            throw new IOException("Failed on checking stream " + streamName, e);
        }
        StreamCandidate streamCandidate = new StreamCandidate(streamName);
        for (LogSegmentCandidate segmentCandidate : segmentCandidates) {
            if (null != segmentCandidate) {
                streamCandidate.addLogSegmentCandidate(segmentCandidate);
            }
        }
        if (streamCandidate.segmentCandidates.isEmpty()) {
            return null;
        }
        return streamCandidate;
    } finally {
        dlm.close();
    }
}
Also used : DistributedLogManager(com.twitter.distributedlog.DistributedLogManager) LogSegmentMetadata(com.twitter.distributedlog.LogSegmentMetadata) ArrayList(java.util.ArrayList) Future(com.twitter.util.Future) IOException(java.io.IOException) DLIllegalStateException(com.twitter.distributedlog.exceptions.DLIllegalStateException) ParseException(org.apache.commons.cli.ParseException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 12 with DistributedLogManager

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

the class DLAuditor method collectLedgersFromStream.

private List<Long> collectLedgersFromStream(com.twitter.distributedlog.DistributedLogManagerFactory factory, String stream, Set<Long> ledgers) throws IOException {
    DistributedLogManager dlm = factory.createDistributedLogManager(stream, com.twitter.distributedlog.DistributedLogManagerFactory.ClientSharingOption.SharedClients);
    try {
        List<LogSegmentMetadata> segments = dlm.getLogSegments();
        List<Long> sLedgers = new ArrayList<Long>();
        for (LogSegmentMetadata segment : segments) {
            synchronized (ledgers) {
                ledgers.add(segment.getLedgerId());
            }
            sLedgers.add(segment.getLedgerId());
        }
        return sLedgers;
    } finally {
        dlm.close();
    }
}
Also used : DistributedLogManager(com.twitter.distributedlog.DistributedLogManager) LogSegmentMetadata(com.twitter.distributedlog.LogSegmentMetadata) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 13 with DistributedLogManager

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

the class DLAuditor method calculateStreamSpaceUsage.

private long calculateStreamSpaceUsage(final com.twitter.distributedlog.DistributedLogManagerFactory factory, final String stream) throws IOException {
    DistributedLogManager dlm = factory.createDistributedLogManager(stream, com.twitter.distributedlog.DistributedLogManagerFactory.ClientSharingOption.SharedClients);
    long totalBytes = 0;
    try {
        List<LogSegmentMetadata> segments = dlm.getLogSegments();
        for (LogSegmentMetadata segment : segments) {
            try {
                LedgerHandle lh = getBookKeeperClient(factory).get().openLedgerNoRecovery(segment.getLedgerId(), BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes(UTF_8));
                totalBytes += lh.getLength();
                lh.close();
            } catch (BKException e) {
                logger.error("Failed to open ledger {} : ", segment.getLedgerId(), e);
                throw new IOException("Failed to open ledger " + segment.getLedgerId(), e);
            } catch (InterruptedException e) {
                logger.warn("Interrupted on opening ledger {} : ", segment.getLedgerId(), e);
                Thread.currentThread().interrupt();
                throw new DLInterruptedException("Interrupted on opening ledger " + segment.getLedgerId(), e);
            }
        }
    } finally {
        dlm.close();
    }
    return totalBytes;
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) DistributedLogManager(com.twitter.distributedlog.DistributedLogManager) LogSegmentMetadata(com.twitter.distributedlog.LogSegmentMetadata) BKException(org.apache.bookkeeper.client.BKException) DLInterruptedException(com.twitter.distributedlog.exceptions.DLInterruptedException) IOException(java.io.IOException) DLInterruptedException(com.twitter.distributedlog.exceptions.DLInterruptedException)

Example 14 with DistributedLogManager

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

the class ReaderWorker method close.

@Override
public void close() throws IOException {
    this.running = false;
    for (AsyncLogReader reader : logReaders) {
        if (null != reader) {
            FutureUtils.result(reader.asyncClose());
        }
    }
    for (DistributedLogManager dlm : dlms) {
        if (null != dlm) {
            dlm.close();
        }
    }
    namespace.close();
    SchedulerUtils.shutdownScheduler(executorService, 2, TimeUnit.MINUTES);
    SchedulerUtils.shutdownScheduler(callbackExecutor, 2, TimeUnit.MINUTES);
    if (this.dlc != null) {
        this.dlc.close();
    }
    for (DLZkServerSet serverSet : serverSets) {
        serverSet.close();
    }
}
Also used : AsyncLogReader(com.twitter.distributedlog.AsyncLogReader) DistributedLogManager(com.twitter.distributedlog.DistributedLogManager) DLZkServerSet(com.twitter.distributedlog.client.serverset.DLZkServerSet)

Example 15 with DistributedLogManager

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

the class TestDistributedLogTool method testToolCreateZkAclId.

@Test(timeout = 60000)
public void testToolCreateZkAclId() throws Exception {
    createStream(defaultUri, "0", "CreateAclStream", defaultPrivilegedZkAclId);
    try {
        DistributedLogManager dlm = DLMTestUtil.createNewDLM("0CreateAclStream", conf, defaultUri);
        DLMTestUtil.generateCompletedLogSegments(dlm, conf, 3, 1000);
        dlm.close();
    } catch (ZKException ex) {
        assertEquals(KeeperException.Code.NOAUTH, ex.getKeeperExceptionCode());
    }
}
Also used : ZKException(com.twitter.distributedlog.exceptions.ZKException) DistributedLogManager(com.twitter.distributedlog.DistributedLogManager) 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