use of org.apache.distributedlog.impl.BKNamespaceDriver in project bookkeeper by apache.
the class TestBKDistributedLogManager method testDeleteLog.
@Test(timeout = 60000)
public void testDeleteLog() throws Exception {
String name = "delete-log-should-delete-ledgers";
DistributedLogManager dlm = createNewDLM(conf, name);
long txid = 1;
// Create the log and write some records
BKSyncLogWriter writer = (BKSyncLogWriter) dlm.startLogSegmentNonPartitioned();
for (long j = 1; j <= DEFAULT_SEGMENT_SIZE; j++) {
writer.write(DLMTestUtil.getLogRecordInstance(txid++));
}
BKLogSegmentWriter perStreamLogWriter = writer.getCachedLogWriter();
writer.closeAndComplete();
BKLogWriteHandler blplm = ((BKDistributedLogManager) (dlm)).createWriteHandler(true);
assertNotNull(zkc.exists(blplm.completedLedgerZNode(txid, txid - 1, perStreamLogWriter.getLogSegmentSequenceNumber()), false));
Utils.ioResult(blplm.asyncClose());
// Should be able to open the underline ledger using BK client
long ledgerId = perStreamLogWriter.getLogSegmentId();
BKNamespaceDriver driver = (BKNamespaceDriver) dlm.getNamespaceDriver();
driver.getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes(UTF_8));
// Delete the log and we shouldn't be able the open the ledger
dlm.delete();
try {
driver.getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes(UTF_8));
fail("Should fail to open ledger after we delete the log");
} catch (BKException.BKNoSuchLedgerExistsException e) {
// ignore
}
// delete again should not throw any exception
try {
dlm.delete();
} catch (IOException ioe) {
fail("Delete log twice should not throw any exception");
}
}
use of org.apache.distributedlog.impl.BKNamespaceDriver in project bookkeeper by apache.
the class TestAsyncReaderWriter method testCreateLogStreamWithDifferentReplicationFactor.
@Test(timeout = 60000)
public void testCreateLogStreamWithDifferentReplicationFactor() throws Exception {
String name = runtime.getMethodName();
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(testConf);
confLocal.setOutputBufferSize(0);
confLocal.setImmediateFlushEnabled(false);
confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
ConcurrentBaseConfiguration baseConf = new ConcurrentConstConfiguration(confLocal);
DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(baseConf);
dynConf.setProperty(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE, DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT - 1);
URI uri = createDLMURI("/" + name);
ensureURICreated(uri);
Namespace namespace = NamespaceBuilder.newBuilder().conf(confLocal).uri(uri).build();
// use the pool
DistributedLogManager dlm = namespace.openLog(name + "-pool");
AsyncLogWriter writer = dlm.startAsyncLogSegmentNonPartitioned();
Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
List<LogSegmentMetadata> segments = dlm.getLogSegments();
assertEquals(1, segments.size());
long ledgerId = segments.get(0).getLogSegmentId();
LedgerHandle lh = ((BKNamespaceDriver) namespace.getNamespaceDriver()).getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
LedgerMetadata metadata = BookKeeperAccessor.getLedgerMetadata(lh);
assertEquals(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT, metadata.getEnsembleSize());
lh.close();
Utils.close(writer);
dlm.close();
// use customized configuration
dlm = namespace.openLog(name + "-custom", java.util.Optional.empty(), java.util.Optional.of(dynConf), java.util.Optional.empty());
writer = dlm.startAsyncLogSegmentNonPartitioned();
Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
segments = dlm.getLogSegments();
assertEquals(1, segments.size());
ledgerId = segments.get(0).getLogSegmentId();
lh = ((BKNamespaceDriver) namespace.getNamespaceDriver()).getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
metadata = BookKeeperAccessor.getLedgerMetadata(lh);
assertEquals(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT - 1, metadata.getEnsembleSize());
lh.close();
Utils.close(writer);
dlm.close();
namespace.close();
}
use of org.apache.distributedlog.impl.BKNamespaceDriver in project bookkeeper by apache.
the class TestAsyncReaderWriter method testCloseAndCompleteLogSegmentWhenCloseFailed.
@Test(timeout = 60000)
public void testCloseAndCompleteLogSegmentWhenCloseFailed() throws Exception {
String name = "distrlog-close-and-complete-logsegment-when-close-failed";
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 {
// insert a write to detect the fencing state, to make test more robust.
writer.write(DLMTestUtil.getLogRecordInstance(txId++));
writer.closeAndComplete();
fail("Should fail to complete a log segment when its ledger is fenced");
} catch (IOException ioe) {
// expected
LOG.error("Failed to close and complete log segment {} : ", logWriter.getFullyQualifiedLogSegment(), ioe);
}
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 TestDistributedLogBase method getBookKeeperClient.
@SuppressWarnings("deprecation")
protected BookKeeperClient getBookKeeperClient(Namespace namespace) throws Exception {
NamespaceDriver driver = namespace.getNamespaceDriver();
assertTrue(driver instanceof BKNamespaceDriver);
return ((BKNamespaceDriver) driver).getReaderBKC();
}
use of org.apache.distributedlog.impl.BKNamespaceDriver in project bookkeeper by apache.
the class TestDistributedLogBase method getZooKeeperClient.
protected ZooKeeperClient getZooKeeperClient(Namespace namespace) throws Exception {
NamespaceDriver driver = namespace.getNamespaceDriver();
assertTrue(driver instanceof BKNamespaceDriver);
return ((BKNamespaceDriver) driver).getWriterZKC();
}
Aggregations