Search in sources :

Example 1 with BKLogSegmentEntryWriter

use of com.twitter.distributedlog.impl.BKLogSegmentEntryWriter in project distributedlog by twitter.

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, Await.result(writer.asyncWrite(DLMTestUtil.getLogRecordInstance(2))));
    assertEquals(-1L, ((BKLogSegmentEntryWriter) writer.getEntryWriter()).getLedgerHandle().getLastAddPushed());
    closeWriterAndLock(writer, lock);
}
Also used : BKLogSegmentEntryWriter(com.twitter.distributedlog.impl.BKLogSegmentEntryWriter) ZKDistributedLock(com.twitter.distributedlog.lock.ZKDistributedLock) Test(org.junit.Test)

Example 2 with BKLogSegmentEntryWriter

use of com.twitter.distributedlog.impl.BKLogSegmentEntryWriter in project distributedlog by twitter.

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);
    FutureUtils.result(writeHandler.lockHandler());
    // Start a log segment with a given ledger seq number.
    BookKeeperClient bkc = dlm.getWriterBKC();
    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).build();
    l.write(dlm.writerZKC);
    writeHandler.maxTxId.store(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++));
        }
        FutureUtils.result(writer.flushAndCommit());
    }
    if (completeLogSegment) {
        FutureUtils.result(writeHandler.completeAndCloseLogSegment(writer));
    }
    FutureUtils.result(writeHandler.unlockHandler());
}
Also used : BKLogSegmentEntryWriter(com.twitter.distributedlog.impl.BKLogSegmentEntryWriter) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider)

Example 3 with BKLogSegmentEntryWriter

use of com.twitter.distributedlog.impl.BKLogSegmentEntryWriter in project distributedlog by twitter.

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);
    FutureUtils.result(writeHandler.lockHandler());
    // Start a log segment with a given ledger seq number.
    BookKeeperClient bkc = dlm.getReaderBKC();
    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(dlm.writerZKC);
    writeHandler.maxTxId.store(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 = Await.result(writer.asyncWrite(DLMTestUtil.getLogRecordInstance(txid++)));
        if (j == (segmentSize - 1)) {
            wrongDLSN = dlsn;
        }
    }
    assertNotNull(wrongDLSN);
    if (recordWrongLastDLSN) {
        FutureUtils.result(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 {
        FutureUtils.result(writeHandler.completeAndCloseLogSegment(writer));
    }
    FutureUtils.result(writeHandler.unlockHandler());
}
Also used : BKLogSegmentEntryWriter(com.twitter.distributedlog.impl.BKLogSegmentEntryWriter) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider)

Aggregations

BKLogSegmentEntryWriter (com.twitter.distributedlog.impl.BKLogSegmentEntryWriter)3 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)2 SettableFeatureProvider (org.apache.bookkeeper.feature.SettableFeatureProvider)2 ZKDistributedLock (com.twitter.distributedlog.lock.ZKDistributedLock)1 Test (org.junit.Test)1