use of org.apache.distributedlog.api.DistributedLogManager in project bookkeeper by apache.
the class TestBKLogSegmentEntryReader method testMaxPrefetchEntriesSmallSegment.
@Test(timeout = 60000)
public void testMaxPrefetchEntriesSmallSegment() throws Exception {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(conf);
confLocal.setOutputBufferSize(0);
confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
confLocal.setImmediateFlushEnabled(false);
confLocal.setNumPrefetchEntriesPerLogSegment(10);
confLocal.setMaxPrefetchEntriesPerLogSegment(20);
DistributedLogManager dlm = createNewDLM(confLocal, runtime.getMethodName());
generateCompletedLogSegments(dlm, confLocal, 1, 5);
List<LogSegmentMetadata> segments = dlm.getLogSegments();
assertEquals(segments.size() + " log segments found, expected to be only one", 1, segments.size());
BKLogSegmentEntryReader reader = createEntryReader(segments.get(0), 0, confLocal);
reader.start();
// wait for the read ahead entries to become available
while (reader.readAheadEntries.size() < (reader.getLastAddConfirmed() + 1)) {
TimeUnit.MILLISECONDS.sleep(10);
}
long txId = 1L;
long entryId = 0L;
assertEquals((reader.getLastAddConfirmed() + 1), reader.readAheadEntries.size());
assertEquals((reader.getLastAddConfirmed() + 1), reader.getNextEntryId());
// read first entry
Entry.Reader entryReader = Utils.ioResult(reader.readNext(1)).get(0);
LogRecordWithDLSN record = entryReader.nextRecord();
while (null != record) {
if (!record.isControl()) {
DLMTestUtil.verifyLogRecord(record);
assertEquals(txId, record.getTransactionId());
++txId;
}
DLSN dlsn = record.getDlsn();
assertEquals(1L, dlsn.getLogSegmentSequenceNo());
assertEquals(entryId, dlsn.getEntryId());
record = entryReader.nextRecord();
}
++entryId;
assertEquals(2L, txId);
assertEquals(reader.getLastAddConfirmed(), reader.readAheadEntries.size());
assertEquals((reader.getLastAddConfirmed() + 1), reader.getNextEntryId());
assertFalse(reader.hasCaughtUpOnInprogress());
Utils.close(reader);
}
use of org.apache.distributedlog.api.DistributedLogManager in project bookkeeper by apache.
the class TestBKLogSegmentEntryReader method testReadEntriesFromCompleteLogSegment.
@Test(timeout = 60000)
public void testReadEntriesFromCompleteLogSegment() throws Exception {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(conf);
confLocal.setOutputBufferSize(0);
confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
confLocal.setImmediateFlushEnabled(false);
confLocal.setNumPrefetchEntriesPerLogSegment(10);
confLocal.setMaxPrefetchEntriesPerLogSegment(10);
DistributedLogManager dlm = createNewDLM(confLocal, runtime.getMethodName());
generateCompletedLogSegments(dlm, confLocal, 1, 20);
List<LogSegmentMetadata> segments = dlm.getLogSegments();
assertEquals(segments.size() + " log segments found, expected to be only one", 1, segments.size());
BKLogSegmentEntryReader reader = createEntryReader(segments.get(0), 0, confLocal);
reader.start();
boolean done = false;
long txId = 1L;
long entryId = 0L;
while (!done) {
Entry.Reader entryReader;
try {
entryReader = Utils.ioResult(reader.readNext(1)).get(0);
} catch (EndOfLogSegmentException eol) {
done = true;
continue;
}
LogRecordWithDLSN record = entryReader.nextRecord();
while (null != record) {
if (!record.isControl()) {
DLMTestUtil.verifyLogRecord(record);
assertEquals(txId, record.getTransactionId());
++txId;
}
DLSN dlsn = record.getDlsn();
assertEquals(1L, dlsn.getLogSegmentSequenceNo());
assertEquals(entryId, dlsn.getEntryId());
record = entryReader.nextRecord();
}
++entryId;
}
assertEquals(21, txId);
assertFalse(reader.hasCaughtUpOnInprogress());
Utils.close(reader);
}
use of org.apache.distributedlog.api.DistributedLogManager in project bookkeeper by apache.
the class TestDistributedLogTool method testToolTruncateStream.
@Test(timeout = 60000)
public void testToolTruncateStream() throws Exception {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(conf);
confLocal.setLogSegmentCacheEnabled(false);
DistributedLogManager dlm = DLMTestUtil.createNewDLM("testToolTruncateStream", confLocal, defaultUri);
DLMTestUtil.generateCompletedLogSegments(dlm, confLocal, 3, 1000);
DLSN dlsn = new DLSN(2, 1, 0);
TruncateStreamCommand cmd = new TruncateStreamCommand();
cmd.setDlsn(dlsn);
cmd.setUri(defaultUri);
cmd.setStreamName("testToolTruncateStream");
cmd.setForce(true);
assertEquals(0, cmd.runCmd());
LogReader reader = dlm.getInputStream(0);
LogRecordWithDLSN record = reader.readNext(false);
assertEquals(dlsn, record.getDlsn());
reader.close();
dlm.close();
}
use of org.apache.distributedlog.api.DistributedLogManager in project bookkeeper by apache.
the class TestDistributedLogTool method testToolCreateZkAclId.
@Test(timeout = 60000)
public void testToolCreateZkAclId() throws Exception {
createStream(defaultUri, "0", "CreateAclStream", defaultPrivilegedZkAclId);
try {
DistributedLogManager dlm = DLMTestUtil.createNewDLM("0CreateAclStream", conf, defaultUri);
DLMTestUtil.generateCompletedLogSegments(dlm, conf, 3, 1000);
dlm.close();
} catch (ZKException ex) {
assertEquals(KeeperException.Code.NOAUTH, ex.getKeeperExceptionCode());
}
}
use of org.apache.distributedlog.api.DistributedLogManager in project bookkeeper by apache.
the class DLFileSystem method getFileStatus.
@Override
public FileStatus getFileStatus(Path path) throws IOException {
String logName = getStreamName(path);
boolean exists = namespace.logExists(logName);
if (!exists) {
throw new FileNotFoundException(path.toString());
}
long endPos;
try {
DistributedLogManager dlm = namespace.openLog(logName);
endPos = dlm.getLastTxId();
} catch (LogNotFoundException e) {
throw new FileNotFoundException(path.toString());
} catch (LogEmptyException e) {
endPos = 0L;
}
// we need to store more metadata information on logs for supporting filesystem-like use cases
return new FileStatus(endPos, false, 3, dlConf.getMaxLogSegmentBytes(), 0L, makeAbsolute(path));
}
Aggregations