use of org.apache.distributedlog.bk.LedgerAllocator in project bookkeeper by apache.
the class BKLogSegmentEntryStore method createLedgerAllocator.
//
// Writers
//
LedgerAllocator createLedgerAllocator(LogMetadataForWriter logMetadata, DynamicDistributedLogConfiguration dynConf) throws IOException {
LedgerAllocator ledgerAllocatorDelegator;
if (null == allocator || !dynConf.getEnableLedgerAllocatorPool()) {
QuorumConfigProvider quorumConfigProvider = new DynamicQuorumConfigProvider(dynConf);
LedgerAllocator allocator = new SimpleLedgerAllocator(logMetadata.getAllocationPath(), logMetadata.getAllocationData(), quorumConfigProvider, zkc, bkc);
ledgerAllocatorDelegator = new LedgerAllocatorDelegator(allocator, true);
} else {
ledgerAllocatorDelegator = allocator;
}
return ledgerAllocatorDelegator;
}
use of org.apache.distributedlog.bk.LedgerAllocator 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