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();
}
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);
}
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);
}
Aggregations