use of org.apache.distributedlog.api.DistributedLogManager in project bookkeeper by apache.
the class TestBKDistributedLogManager method testGetLastDLSN.
@Test(timeout = 60000)
public void testGetLastDLSN() throws Exception {
String name = "distrlog-get-last-dlsn";
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.loadConf(conf);
confLocal.setFirstNumEntriesPerReadLastRecordScan(2);
confLocal.setMaxNumEntriesPerReadLastRecordScan(4);
confLocal.setImmediateFlushEnabled(true);
confLocal.setOutputBufferSize(0);
DistributedLogManager dlm = createNewDLM(confLocal, name);
BKAsyncLogWriter writer = (BKAsyncLogWriter) dlm.startAsyncLogSegmentNonPartitioned();
long txid = 1;
LOG.info("Writing 10 control records");
for (int i = 0; i < 10; i++) {
LogRecord record = DLMTestUtil.getLogRecordInstance(txid++);
record.setControl();
Utils.ioResult(writer.writeControlRecord(record));
}
LOG.info("10 control records are written");
try {
dlm.getLastDLSN();
fail("Should fail on getting last dlsn from an empty log.");
} catch (LogEmptyException lee) {
// expected
}
writer.closeAndComplete();
LOG.info("Completed first log segment");
writer = (BKAsyncLogWriter) dlm.startAsyncLogSegmentNonPartitioned();
Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(txid++)));
LOG.info("Completed second log segment");
LOG.info("Writing another 10 control records");
for (int i = 1; i < 10; i++) {
LogRecord record = DLMTestUtil.getLogRecordInstance(txid++);
record.setControl();
Utils.ioResult(writer.write(record));
}
assertEquals(new DLSN(2, 0, 0), dlm.getLastDLSN());
writer.closeAndComplete();
LOG.info("Completed third log segment");
assertEquals(new DLSN(2, 0, 0), dlm.getLastDLSN());
writer.close();
dlm.close();
}
use of org.apache.distributedlog.api.DistributedLogManager in project bookkeeper by apache.
the class TestBKDistributedLogManager method testWriteFailsAfterMarkEndOfStream.
@Test(timeout = 60000)
public void testWriteFailsAfterMarkEndOfStream() throws Exception {
String name = "distrlog-mark-end-failure";
DistributedLogManager dlm = createNewDLM(conf, name);
long txid = 1;
txid = writeAndMarkEndOfStream(dlm, txid);
assertEquals(txid - 1, dlm.getLastTxId());
LogRecord last = dlm.getLastLogRecord();
assertEquals(txid - 1, last.getTransactionId());
DLMTestUtil.verifyLogRecord(last);
assertTrue(dlm.isEndOfStreamMarked());
LogWriter writer = null;
boolean exceptionEncountered = false;
try {
writer = dlm.startLogSegmentNonPartitioned();
for (long j = 1; j <= DEFAULT_SEGMENT_SIZE / 2; j++) {
writer.write(DLMTestUtil.getLogRecordInstance(txid++));
}
} catch (EndOfStreamException exc) {
exceptionEncountered = true;
}
writer.close();
assertTrue(exceptionEncountered);
}
use of org.apache.distributedlog.api.DistributedLogManager 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.api.DistributedLogManager in project bookkeeper by apache.
the class TestBKLogReadHandler method prepareLogSegmentsNonPartitioned.
private void prepareLogSegmentsNonPartitioned(String name, int numSegments, int numEntriesPerSegment) throws Exception {
DistributedLogManager dlm = createNewDLM(conf, name);
long txid = 1;
for (int sid = 0; sid < numSegments; ++sid) {
LogWriter out = dlm.startLogSegmentNonPartitioned();
for (int eid = 0; eid < numEntriesPerSegment; ++eid) {
LogRecord record = DLMTestUtil.getLargeLogRecordInstance(txid);
out.write(record);
++txid;
}
out.close();
}
dlm.close();
}
use of org.apache.distributedlog.api.DistributedLogManager in project bookkeeper by apache.
the class TestBKLogReadHandler method testGetLogRecordCountAtLedgerBoundary.
@Test(timeout = 60000)
public void testGetLogRecordCountAtLedgerBoundary() throws Exception {
String dlName = runtime.getMethodName();
prepareLogSegmentsNonPartitioned(dlName, 11, 3);
DistributedLogManager dlm = createNewDLM(conf, dlName);
BKLogReadHandler readHandler = ((BKDistributedLogManager) dlm).createReadHandler();
CompletableFuture<Long> count = null;
count = readHandler.asyncGetLogRecordCount(new DLSN(2, 0, 0));
assertEquals(30, Utils.ioResult(count).longValue());
count = readHandler.asyncGetLogRecordCount(new DLSN(3, 0, 0));
assertEquals(27, Utils.ioResult(count).longValue());
}
Aggregations