Search in sources :

Example 96 with DistributedLogManager

use of org.apache.distributedlog.api.DistributedLogManager in project bookkeeper by apache.

the class TestBKLogSegmentEntryReader method testMaxPrefetchEntriesSmallSegment.

@Test(timeout = 60000)
public void testMaxPrefetchEntriesSmallSegment() throws Exception {
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(conf);
    confLocal.setOutputBufferSize(0);
    confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
    confLocal.setImmediateFlushEnabled(false);
    confLocal.setNumPrefetchEntriesPerLogSegment(10);
    confLocal.setMaxPrefetchEntriesPerLogSegment(20);
    DistributedLogManager dlm = createNewDLM(confLocal, runtime.getMethodName());
    generateCompletedLogSegments(dlm, confLocal, 1, 5);
    List<LogSegmentMetadata> segments = dlm.getLogSegments();
    assertEquals(segments.size() + " log segments found, expected to be only one", 1, segments.size());
    BKLogSegmentEntryReader reader = createEntryReader(segments.get(0), 0, confLocal);
    reader.start();
    // wait for the read ahead entries to become available
    while (reader.readAheadEntries.size() < (reader.getLastAddConfirmed() + 1)) {
        TimeUnit.MILLISECONDS.sleep(10);
    }
    long txId = 1L;
    long entryId = 0L;
    assertEquals((reader.getLastAddConfirmed() + 1), reader.readAheadEntries.size());
    assertEquals((reader.getLastAddConfirmed() + 1), reader.getNextEntryId());
    // read first entry
    Entry.Reader entryReader = Utils.ioResult(reader.readNext(1)).get(0);
    LogRecordWithDLSN record = entryReader.nextRecord();
    while (null != record) {
        if (!record.isControl()) {
            DLMTestUtil.verifyLogRecord(record);
            assertEquals(txId, record.getTransactionId());
            ++txId;
        }
        DLSN dlsn = record.getDlsn();
        assertEquals(1L, dlsn.getLogSegmentSequenceNo());
        assertEquals(entryId, dlsn.getEntryId());
        record = entryReader.nextRecord();
    }
    ++entryId;
    assertEquals(2L, txId);
    assertEquals(reader.getLastAddConfirmed(), reader.readAheadEntries.size());
    assertEquals((reader.getLastAddConfirmed() + 1), reader.getNextEntryId());
    assertFalse(reader.hasCaughtUpOnInprogress());
    Utils.close(reader);
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) Entry(org.apache.distributedlog.Entry) LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) DLSN(org.apache.distributedlog.DLSN) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LogSegmentMetadata(org.apache.distributedlog.LogSegmentMetadata) Test(org.junit.Test)

Example 97 with DistributedLogManager

use of org.apache.distributedlog.api.DistributedLogManager in project bookkeeper by apache.

the class TestBKLogSegmentEntryReader method testReadEntriesFromCompleteLogSegment.

@Test(timeout = 60000)
public void testReadEntriesFromCompleteLogSegment() throws Exception {
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(conf);
    confLocal.setOutputBufferSize(0);
    confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
    confLocal.setImmediateFlushEnabled(false);
    confLocal.setNumPrefetchEntriesPerLogSegment(10);
    confLocal.setMaxPrefetchEntriesPerLogSegment(10);
    DistributedLogManager dlm = createNewDLM(confLocal, runtime.getMethodName());
    generateCompletedLogSegments(dlm, confLocal, 1, 20);
    List<LogSegmentMetadata> segments = dlm.getLogSegments();
    assertEquals(segments.size() + " log segments found, expected to be only one", 1, segments.size());
    BKLogSegmentEntryReader reader = createEntryReader(segments.get(0), 0, confLocal);
    reader.start();
    boolean done = false;
    long txId = 1L;
    long entryId = 0L;
    while (!done) {
        Entry.Reader entryReader;
        try {
            entryReader = Utils.ioResult(reader.readNext(1)).get(0);
        } catch (EndOfLogSegmentException eol) {
            done = true;
            continue;
        }
        LogRecordWithDLSN record = entryReader.nextRecord();
        while (null != record) {
            if (!record.isControl()) {
                DLMTestUtil.verifyLogRecord(record);
                assertEquals(txId, record.getTransactionId());
                ++txId;
            }
            DLSN dlsn = record.getDlsn();
            assertEquals(1L, dlsn.getLogSegmentSequenceNo());
            assertEquals(entryId, dlsn.getEntryId());
            record = entryReader.nextRecord();
        }
        ++entryId;
    }
    assertEquals(21, txId);
    assertFalse(reader.hasCaughtUpOnInprogress());
    Utils.close(reader);
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) Entry(org.apache.distributedlog.Entry) LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) DLSN(org.apache.distributedlog.DLSN) EndOfLogSegmentException(org.apache.distributedlog.exceptions.EndOfLogSegmentException) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LogSegmentMetadata(org.apache.distributedlog.LogSegmentMetadata) Test(org.junit.Test)

Example 98 with DistributedLogManager

use of org.apache.distributedlog.api.DistributedLogManager in project bookkeeper by apache.

the class TestDistributedLogTool method testToolTruncateStream.

@Test(timeout = 60000)
public void testToolTruncateStream() throws Exception {
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(conf);
    confLocal.setLogSegmentCacheEnabled(false);
    DistributedLogManager dlm = DLMTestUtil.createNewDLM("testToolTruncateStream", confLocal, defaultUri);
    DLMTestUtil.generateCompletedLogSegments(dlm, confLocal, 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 : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) DLSN(org.apache.distributedlog.DLSN) LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LogReader(org.apache.distributedlog.api.LogReader) TruncateStreamCommand(org.apache.distributedlog.tools.DistributedLogTool.TruncateStreamCommand) Test(org.junit.Test)

Example 99 with DistributedLogManager

use of org.apache.distributedlog.api.DistributedLogManager in project bookkeeper by apache.

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(org.apache.distributedlog.exceptions.ZKException) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) Test(org.junit.Test)

Example 100 with DistributedLogManager

use of org.apache.distributedlog.api.DistributedLogManager in project bookkeeper by apache.

the class DLFileSystem method getFileStatus.

@Override
public FileStatus getFileStatus(Path path) throws IOException {
    String logName = getStreamName(path);
    boolean exists = namespace.logExists(logName);
    if (!exists) {
        throw new FileNotFoundException(path.toString());
    }
    long endPos;
    try {
        DistributedLogManager dlm = namespace.openLog(logName);
        endPos = dlm.getLastTxId();
    } catch (LogNotFoundException e) {
        throw new FileNotFoundException(path.toString());
    } catch (LogEmptyException e) {
        endPos = 0L;
    }
    // we need to store more metadata information on logs for supporting filesystem-like use cases
    return new FileStatus(endPos, false, 3, dlConf.getMaxLogSegmentBytes(), 0L, makeAbsolute(path));
}
Also used : LogEmptyException(org.apache.distributedlog.exceptions.LogEmptyException) FileStatus(org.apache.hadoop.fs.FileStatus) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) FileNotFoundException(java.io.FileNotFoundException) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException)

Aggregations

DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)174 Test (org.junit.Test)139 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)34 DynamicDistributedLogConfiguration (org.apache.distributedlog.config.DynamicDistributedLogConfiguration)33 URI (java.net.URI)29 LogReader (org.apache.distributedlog.api.LogReader)26 Namespace (org.apache.distributedlog.api.namespace.Namespace)26 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)23 CountDownLatch (java.util.concurrent.CountDownLatch)18 DLSN (org.apache.distributedlog.DLSN)17 LogRecordWithDLSN (org.apache.distributedlog.LogRecordWithDLSN)16 EndOfStreamException (org.apache.distributedlog.exceptions.EndOfStreamException)14 IOException (java.io.IOException)13 AppendOnlyStreamWriter (org.apache.distributedlog.AppendOnlyStreamWriter)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 LogSegmentMetadata (org.apache.distributedlog.LogSegmentMetadata)12 ArrayList (java.util.ArrayList)11 CompletableFuture (java.util.concurrent.CompletableFuture)11 DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)11 List (java.util.List)8