Search in sources :

Example 6 with BKNamespaceDriver

use of org.apache.distributedlog.impl.BKNamespaceDriver in project bookkeeper by apache.

the class TestAsyncReaderWriter method testCloseAndCompleteLogSegmentWhenStreamIsInError.

@Test(timeout = 60000)
public void testCloseAndCompleteLogSegmentWhenStreamIsInError() throws Exception {
    String name = "distrlog-close-and-complete-logsegment-when-stream-is-in-error";
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.loadConf(testConf);
    confLocal.setOutputBufferSize(0);
    confLocal.setImmediateFlushEnabled(true);
    BKDistributedLogManager dlm = (BKDistributedLogManager) createNewDLM(confLocal, name);
    BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm.startAsyncLogSegmentNonPartitioned());
    long txId = 1L;
    for (int i = 0; i < 5; i++) {
        Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(txId++)));
    }
    BKLogSegmentWriter logWriter = writer.getCachedLogWriter();
    BKNamespaceDriver driver = (BKNamespaceDriver) dlm.getNamespaceDriver();
    // fence the ledger
    driver.getReaderBKC().get().openLedger(logWriter.getLogSegmentId(), BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
    try {
        Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(txId++)));
        fail("Should fail write to a fenced ledger with BKTransmitException");
    } catch (BKTransmitException bkte) {
    // expected
    }
    try {
        writer.closeAndComplete();
        fail("Should fail to complete a log segment when its ledger is fenced");
    } catch (BKTransmitException bkte) {
    // expected
    }
    List<LogSegmentMetadata> segments = dlm.getLogSegments();
    assertEquals(1, segments.size());
    assertTrue(segments.get(0).isInProgress());
    dlm.close();
}
Also used : DynamicDistributedLogConfiguration(org.apache.distributedlog.config.DynamicDistributedLogConfiguration) BKTransmitException(org.apache.distributedlog.exceptions.BKTransmitException) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) Test(org.junit.Test)

Example 7 with BKNamespaceDriver

use of org.apache.distributedlog.impl.BKNamespaceDriver in project bookkeeper by apache.

the class TestAsyncReaderLock method testReaderLockIfLockPathDoesntExist.

@Test(timeout = 60000)
public void testReaderLockIfLockPathDoesntExist() throws Exception {
    final String name = runtime.getMethodName();
    DistributedLogManager dlm = createNewDLM(conf, name);
    BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm.startAsyncLogSegmentNonPartitioned());
    writer.write(DLMTestUtil.getLogRecordInstance(1L));
    writer.closeAndComplete();
    CompletableFuture<AsyncLogReader> futureReader1 = dlm.getAsyncLogReaderWithLock(DLSN.InitialDLSN);
    BKAsyncLogReader reader1 = (BKAsyncLogReader) Utils.ioResult(futureReader1);
    LogRecordWithDLSN record = Utils.ioResult(reader1.readNext());
    assertEquals(1L, record.getTransactionId());
    assertEquals(0L, record.getSequenceId());
    DLMTestUtil.verifyLogRecord(record);
    String readLockPath = reader1.readHandler.getReadLockPath();
    Utils.close(reader1);
    // simulate a old stream created without readlock path
    NamespaceDriver driver = dlm.getNamespaceDriver();
    ((BKNamespaceDriver) driver).getWriterZKC().get().delete(readLockPath, -1);
    CompletableFuture<AsyncLogReader> futureReader2 = dlm.getAsyncLogReaderWithLock(DLSN.InitialDLSN);
    AsyncLogReader reader2 = Utils.ioResult(futureReader2);
    record = Utils.ioResult(reader2.readNext());
    assertEquals(1L, record.getTransactionId());
    assertEquals(0L, record.getSequenceId());
    DLMTestUtil.verifyLogRecord(record);
}
Also used : AsyncLogReader(org.apache.distributedlog.api.AsyncLogReader) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) NamespaceDriver(org.apache.distributedlog.namespace.NamespaceDriver) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) Test(org.junit.Test)

Example 8 with BKNamespaceDriver

use of org.apache.distributedlog.impl.BKNamespaceDriver in project bookkeeper by apache.

the class TestBKLogWriteHandler method testAbortTransactionOnStartLogSegment.

/**
 * Testcase: when write handler encounters exceptions on starting log segment
 * it should abort the transaction and return the ledger to the pool.
 */
@Test(timeout = 60000)
public void testAbortTransactionOnStartLogSegment() throws Exception {
    URI uri = createDLMURI("/" + runtime.getMethodName());
    ensureURICreated(zkc, uri);
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(conf);
    confLocal.setOutputBufferSize(0);
    confLocal.setEnableLedgerAllocatorPool(true);
    confLocal.setLedgerAllocatorPoolCoreSize(1);
    confLocal.setLedgerAllocatorPoolName("test-allocator-pool");
    BKDistributedLogNamespace namespace = (BKDistributedLogNamespace) NamespaceBuilder.newBuilder().conf(confLocal).uri(uri).build();
    DistributedLogManager dlm = namespace.openLog("test-stream");
    FailpointUtils.setFailpoint(FailpointUtils.FailPointName.FP_StartLogSegmentOnAssignLogSegmentSequenceNumber, FailpointUtils.FailPointActions.FailPointAction_Throw);
    try {
        AsyncLogWriter writer = Utils.ioResult(dlm.openAsyncLogWriter());
        Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
        fail("Should fail opening the writer");
    } catch (IOException ioe) {
    // expected
    } finally {
        FailpointUtils.removeFailpoint(FailpointUtils.FailPointName.FP_StartLogSegmentOnAssignLogSegmentSequenceNumber);
    }
    LedgerAllocator allocator = ((BKNamespaceDriver) namespace.getNamespaceDriver()).getLedgerAllocator();
    assertTrue(allocator instanceof LedgerAllocatorPool);
    LedgerAllocatorPool allocatorPool = (LedgerAllocatorPool) allocator;
    assertEquals(0, allocatorPool.obtainMapSize());
    AsyncLogWriter writer = Utils.ioResult(dlm.openAsyncLogWriter());
    writer.write(DLMTestUtil.getLogRecordInstance(1L));
    Utils.close(writer);
}
Also used : LedgerAllocatorPool(org.apache.distributedlog.bk.LedgerAllocatorPool) LedgerAllocator(org.apache.distributedlog.bk.LedgerAllocator) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) AsyncLogWriter(org.apache.distributedlog.api.AsyncLogWriter) IOException(java.io.IOException) URI(java.net.URI) Test(org.junit.Test)

Aggregations

BKNamespaceDriver (org.apache.distributedlog.impl.BKNamespaceDriver)8 Test (org.junit.Test)6 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)4 IOException (java.io.IOException)3 DynamicDistributedLogConfiguration (org.apache.distributedlog.config.DynamicDistributedLogConfiguration)3 NamespaceDriver (org.apache.distributedlog.namespace.NamespaceDriver)3 URI (java.net.URI)2 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)2 BKException (org.apache.bookkeeper.client.BKException)1 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)1 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)1 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)1 Namespace (org.apache.distributedlog.api.namespace.Namespace)1 LedgerAllocator (org.apache.distributedlog.bk.LedgerAllocator)1 LedgerAllocatorPool (org.apache.distributedlog.bk.LedgerAllocatorPool)1 ConcurrentBaseConfiguration (org.apache.distributedlog.common.config.ConcurrentBaseConfiguration)1 ConcurrentConstConfiguration (org.apache.distributedlog.common.config.ConcurrentConstConfiguration)1 BKTransmitException (org.apache.distributedlog.exceptions.BKTransmitException)1