Search in sources :

Example 1 with BKLogSegmentEntryWriter

use of org.apache.distributedlog.impl.logsegment.BKLogSegmentEntryWriter in project bookkeeper by apache.

the class DLMTestUtil method injectLogSegmentWithGivenLogSegmentSeqNo.

public static void injectLogSegmentWithGivenLogSegmentSeqNo(DistributedLogManager manager, DistributedLogConfiguration conf, long logSegmentSeqNo, long startTxID, boolean writeEntries, long segmentSize, boolean completeLogSegment) throws Exception {
    BKDistributedLogManager dlm = (BKDistributedLogManager) manager;
    BKLogWriteHandler writeHandler = dlm.createWriteHandler(false);
    Utils.ioResult(writeHandler.lockHandler());
    // Start a log segment with a given ledger seq number.
    BookKeeperClient bkc = getBookKeeperClient(dlm);
    LedgerHandle lh = bkc.get().createLedger(conf.getEnsembleSize(), conf.getWriteQuorumSize(), conf.getAckQuorumSize(), BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes());
    String inprogressZnodeName = writeHandler.inprogressZNodeName(lh.getId(), startTxID, logSegmentSeqNo);
    String znodePath = writeHandler.inprogressZNode(lh.getId(), startTxID, logSegmentSeqNo);
    int logSegmentMetadataVersion = conf.getDLLedgerMetadataLayoutVersion();
    LogSegmentMetadata l = new LogSegmentMetadata.LogSegmentMetadataBuilder(znodePath, logSegmentMetadataVersion, lh.getId(), startTxID).setLogSegmentSequenceNo(logSegmentSeqNo).setEnvelopeEntries(LogSegmentMetadata.supportsEnvelopedEntries(logSegmentMetadataVersion)).build();
    l.write(getZooKeeperClient(dlm));
    writeHandler.maxTxId.update(Version.ANY, startTxID);
    writeHandler.addLogSegmentToCache(inprogressZnodeName, l);
    BKLogSegmentWriter writer = new BKLogSegmentWriter(writeHandler.getFullyQualifiedName(), inprogressZnodeName, conf, conf.getDLLedgerMetadataLayoutVersion(), new BKLogSegmentEntryWriter(lh), writeHandler.lock, startTxID, logSegmentSeqNo, writeHandler.scheduler, writeHandler.statsLogger, writeHandler.statsLogger, writeHandler.alertStatsLogger, PermitLimiter.NULL_PERMIT_LIMITER, new SettableFeatureProvider("", 0), ConfUtils.getConstDynConf(conf));
    if (writeEntries) {
        long txid = startTxID;
        for (long j = 1; j <= segmentSize; j++) {
            writer.write(DLMTestUtil.getLogRecordInstance(txid++));
        }
        Utils.ioResult(writer.flushAndCommit());
    }
    if (completeLogSegment) {
        Utils.ioResult(writeHandler.completeAndCloseLogSegment(writer));
    }
    Utils.ioResult(writeHandler.unlockHandler());
}
Also used : BKLogSegmentEntryWriter(org.apache.distributedlog.impl.logsegment.BKLogSegmentEntryWriter) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider)

Example 2 with BKLogSegmentEntryWriter

use of org.apache.distributedlog.impl.logsegment.BKLogSegmentEntryWriter in project bookkeeper by apache.

the class TestBKLogSegmentWriter method testNondurableWrite.

/**
 * Non durable write should fail if writer is marked as end of stream.
 *
 * @throws Exception
 */
@Test(timeout = 60000)
public void testNondurableWrite() throws Exception {
    DistributedLogConfiguration confLocal = newLocalConf();
    confLocal.setImmediateFlushEnabled(false);
    confLocal.setOutputBufferSize(Integer.MAX_VALUE);
    confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
    confLocal.setDurableWriteEnabled(false);
    ZKDistributedLock lock = createLock("/test/lock-" + runtime.getMethodName(), zkc, true);
    BKLogSegmentWriter writer = createLogSegmentWriter(confLocal, 0L, -1L, lock);
    assertEquals(DLSN.InvalidDLSN, Utils.ioResult(writer.asyncWrite(DLMTestUtil.getLogRecordInstance(2))));
    assertEquals(-1L, ((BKLogSegmentEntryWriter) writer.getEntryWriter()).getLedgerHandle().getLastAddPushed());
    closeWriterAndLock(writer, lock);
}
Also used : BKLogSegmentEntryWriter(org.apache.distributedlog.impl.logsegment.BKLogSegmentEntryWriter) ZKDistributedLock(org.apache.distributedlog.lock.ZKDistributedLock) Test(org.junit.Test)

Example 3 with BKLogSegmentEntryWriter

use of org.apache.distributedlog.impl.logsegment.BKLogSegmentEntryWriter in project bookkeeper by apache.

the class TestDistributedLogBase method getLedgerHandle.

protected LedgerHandle getLedgerHandle(BKLogSegmentWriter segmentWriter) {
    LogSegmentEntryWriter entryWriter = segmentWriter.getEntryWriter();
    assertTrue(entryWriter instanceof BKLogSegmentEntryWriter);
    return ((BKLogSegmentEntryWriter) entryWriter).getLedgerHandle();
}
Also used : BKLogSegmentEntryWriter(org.apache.distributedlog.impl.logsegment.BKLogSegmentEntryWriter) LogSegmentEntryWriter(org.apache.distributedlog.logsegment.LogSegmentEntryWriter) BKLogSegmentEntryWriter(org.apache.distributedlog.impl.logsegment.BKLogSegmentEntryWriter)

Example 4 with BKLogSegmentEntryWriter

use of org.apache.distributedlog.impl.logsegment.BKLogSegmentEntryWriter in project bookkeeper by apache.

the class DLMTestUtil method injectLogSegmentWithLastDLSN.

public static void injectLogSegmentWithLastDLSN(DistributedLogManager manager, DistributedLogConfiguration conf, long logSegmentSeqNo, long startTxID, long segmentSize, boolean recordWrongLastDLSN) throws Exception {
    BKDistributedLogManager dlm = (BKDistributedLogManager) manager;
    BKLogWriteHandler writeHandler = dlm.createWriteHandler(false);
    Utils.ioResult(writeHandler.lockHandler());
    // Start a log segment with a given ledger seq number.
    BookKeeperClient bkc = getBookKeeperClient(dlm);
    LedgerHandle lh = bkc.get().createLedger(conf.getEnsembleSize(), conf.getWriteQuorumSize(), conf.getAckQuorumSize(), BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes());
    String inprogressZnodeName = writeHandler.inprogressZNodeName(lh.getId(), startTxID, logSegmentSeqNo);
    String znodePath = writeHandler.inprogressZNode(lh.getId(), startTxID, logSegmentSeqNo);
    LogSegmentMetadata l = new LogSegmentMetadata.LogSegmentMetadataBuilder(znodePath, conf.getDLLedgerMetadataLayoutVersion(), lh.getId(), startTxID).setLogSegmentSequenceNo(logSegmentSeqNo).setInprogress(false).build();
    l.write(getZooKeeperClient(dlm));
    writeHandler.maxTxId.update(Version.ANY, startTxID);
    writeHandler.addLogSegmentToCache(inprogressZnodeName, l);
    BKLogSegmentWriter writer = new BKLogSegmentWriter(writeHandler.getFullyQualifiedName(), inprogressZnodeName, conf, conf.getDLLedgerMetadataLayoutVersion(), new BKLogSegmentEntryWriter(lh), writeHandler.lock, startTxID, logSegmentSeqNo, writeHandler.scheduler, writeHandler.statsLogger, writeHandler.statsLogger, writeHandler.alertStatsLogger, PermitLimiter.NULL_PERMIT_LIMITER, new SettableFeatureProvider("", 0), ConfUtils.getConstDynConf(conf));
    long txid = startTxID;
    DLSN wrongDLSN = null;
    for (long j = 1; j <= segmentSize; j++) {
        DLSN dlsn = Utils.ioResult(writer.asyncWrite(DLMTestUtil.getLogRecordInstance(txid++)));
        if (j == (segmentSize - 1)) {
            wrongDLSN = dlsn;
        }
    }
    assertNotNull(wrongDLSN);
    if (recordWrongLastDLSN) {
        Utils.ioResult(writer.asyncClose());
        writeHandler.completeAndCloseLogSegment(writeHandler.inprogressZNodeName(writer.getLogSegmentId(), writer.getStartTxId(), writer.getLogSegmentSequenceNumber()), writer.getLogSegmentSequenceNumber(), writer.getLogSegmentId(), writer.getStartTxId(), startTxID + segmentSize - 2, writer.getPositionWithinLogSegment() - 1, wrongDLSN.getEntryId(), wrongDLSN.getSlotId());
    } else {
        Utils.ioResult(writeHandler.completeAndCloseLogSegment(writer));
    }
    Utils.ioResult(writeHandler.unlockHandler());
}
Also used : BKLogSegmentEntryWriter(org.apache.distributedlog.impl.logsegment.BKLogSegmentEntryWriter) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider)

Aggregations

BKLogSegmentEntryWriter (org.apache.distributedlog.impl.logsegment.BKLogSegmentEntryWriter)4 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)2 SettableFeatureProvider (org.apache.bookkeeper.feature.SettableFeatureProvider)2 ZKDistributedLock (org.apache.distributedlog.lock.ZKDistributedLock)1 LogSegmentEntryWriter (org.apache.distributedlog.logsegment.LogSegmentEntryWriter)1 Test (org.junit.Test)1