use of org.apache.distributedlog.LogSegmentMetadata in project bookkeeper by apache.
the class LogSegmentMetadataStoreUpdater method updateLastRecord.
@Override
public CompletableFuture<LogSegmentMetadata> updateLastRecord(LogSegmentMetadata segment, LogRecordWithDLSN record) {
DLSN dlsn = record.getDlsn();
checkState(!segment.isInProgress(), "Updating last dlsn for an inprogress log segment isn't supported.");
checkArgument(segment.isDLSNinThisSegment(dlsn), "DLSN " + dlsn + " doesn't belong to segment " + segment);
final LogSegmentMetadata newSegment = segment.mutator().setLastDLSN(dlsn).setLastTxId(record.getTransactionId()).setRecordCount(record).build();
return updateSegmentMetadata(newSegment);
}
use of org.apache.distributedlog.LogSegmentMetadata in project bookkeeper by apache.
the class LogSegmentMetadataStoreUpdater method setLogSegmentTruncated.
@Override
public LogSegmentMetadata setLogSegmentTruncated(Transaction<Object> txn, LogSegmentMetadata segment) {
final LogSegmentMetadata newSegment = segment.mutator().setTruncationStatus(LogSegmentMetadata.TruncationStatus.TRUNCATED).build();
addNewSegmentAndDeleteOldSegment(txn, newSegment, segment);
return newSegment;
}
use of org.apache.distributedlog.LogSegmentMetadata in project bookkeeper by apache.
the class LogSegmentMetadataStoreUpdater method setLogSegmentPartiallyTruncated.
@Override
public LogSegmentMetadata setLogSegmentPartiallyTruncated(Transaction<Object> txn, LogSegmentMetadata segment, DLSN minActiveDLSN) {
final LogSegmentMetadata newSegment = segment.mutator().setTruncationStatus(LogSegmentMetadata.TruncationStatus.PARTIALLY_TRUNCATED).setMinActiveDLSN(minActiveDLSN).build();
addNewSegmentAndDeleteOldSegment(txn, newSegment, segment);
return newSegment;
}
use of org.apache.distributedlog.LogSegmentMetadata in project bookkeeper by apache.
the class TestBKLogSegmentEntryReader method testMaxPrefetchEntriesSmallBatch.
@Test(timeout = 60000)
public void testMaxPrefetchEntriesSmallBatch() throws Exception {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(conf);
confLocal.setOutputBufferSize(0);
confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
confLocal.setImmediateFlushEnabled(false);
confLocal.setNumPrefetchEntriesPerLogSegment(2);
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();
// wait for the read ahead entries to become available
while (reader.readAheadEntries.size() < 10) {
TimeUnit.MILLISECONDS.sleep(10);
}
long txId = 1L;
long entryId = 0L;
assertEquals(10, reader.readAheadEntries.size());
assertEquals(10, reader.getNextEntryId());
assertFalse(reader.hasCaughtUpOnInprogress());
// 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);
// wait for the read ahead entries to become 10 again
while (reader.readAheadEntries.size() < 10) {
TimeUnit.MILLISECONDS.sleep(10);
}
assertEquals(10, reader.readAheadEntries.size());
assertEquals(11, reader.getNextEntryId());
assertFalse(reader.hasCaughtUpOnInprogress());
Utils.close(reader);
}
use of org.apache.distributedlog.LogSegmentMetadata in project bookkeeper by apache.
the class TestBKLogSegmentEntryReader method testReadEntriesFromInprogressSegment.
@Test(timeout = 60000)
public void testReadEntriesFromInprogressSegment() throws Exception {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(conf);
confLocal.setOutputBufferSize(0);
confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
confLocal.setImmediateFlushEnabled(false);
confLocal.setNumPrefetchEntriesPerLogSegment(20);
confLocal.setMaxPrefetchEntriesPerLogSegment(20);
DistributedLogManager dlm = createNewDLM(confLocal, runtime.getMethodName());
AsyncLogWriter writer = createInprogressLogSegment(dlm, confLocal, 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();
long expectedLastAddConfirmed = 8L;
// wait until sending out all prefetch requests
while (reader.readAheadEntries.size() < expectedLastAddConfirmed + 2) {
TimeUnit.MILLISECONDS.sleep(10);
}
assertEquals(expectedLastAddConfirmed + 2, reader.getNextEntryId());
long txId = 1L;
long entryId = 0L;
while (true) {
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;
if (entryId == expectedLastAddConfirmed + 1) {
break;
}
}
assertEquals(6L, txId);
CompletableFuture<List<Entry.Reader>> nextReadFuture = reader.readNext(1);
// write another record to commit previous writes
Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(txId)));
// the long poll will be satisfied
List<Entry.Reader> nextReadEntries = Utils.ioResult(nextReadFuture);
assertEquals(1, nextReadEntries.size());
assertTrue(reader.hasCaughtUpOnInprogress());
Entry.Reader entryReader = nextReadEntries.get(0);
LogRecordWithDLSN record = entryReader.nextRecord();
assertNotNull(record);
assertTrue(record.isControl());
assertNull(entryReader.nextRecord());
// once the read is advanced, we will prefetch next record
while (reader.getNextEntryId() <= entryId) {
TimeUnit.MILLISECONDS.sleep(10);
}
assertEquals(entryId + 2, reader.getNextEntryId());
assertEquals(1, reader.readAheadEntries.size());
Utils.close(reader);
Utils.close(writer);
}
Aggregations