use of org.apache.ratis.server.storage.LogSegment.LogRecordWithEntry in project incubator-ratis by apache.
the class SegmentedRaftLog method get.
@Override
public LogEntryProto get(long index) throws RaftLogIOException {
checkLogState();
LogSegment segment;
LogRecordWithEntry recordAndEntry;
try (AutoCloseableLock readLock = readLock()) {
segment = cache.getSegment(index);
if (segment == null) {
return null;
}
recordAndEntry = segment.getEntryWithoutLoading(index);
if (recordAndEntry == null) {
return null;
}
if (recordAndEntry.hasEntry()) {
return recordAndEntry.getEntry();
}
}
// the entry is not in the segment's cache. Load the cache without holding
// RaftLog's lock.
checkAndEvictCache();
return segment.loadCache(recordAndEntry.getRecord());
}
use of org.apache.ratis.server.storage.LogSegment.LogRecordWithEntry in project incubator-ratis by apache.
the class TestRaftLogSegment method checkLogSegment.
private void checkLogSegment(LogSegment segment, long start, long end, boolean isOpen, long totalSize, long term) throws Exception {
Assert.assertEquals(start, segment.getStartIndex());
Assert.assertEquals(end, segment.getEndIndex());
Assert.assertEquals(isOpen, segment.isOpen());
Assert.assertEquals(totalSize, segment.getTotalSize());
long offset = SegmentedRaftLog.HEADER_BYTES.length;
for (long i = start; i <= end; i++) {
LogSegment.LogRecord record = segment.getLogRecord(i);
LogRecordWithEntry lre = segment.getEntryWithoutLoading(i);
Assert.assertEquals(i, lre.getRecord().getTermIndex().getIndex());
Assert.assertEquals(term, lre.getRecord().getTermIndex().getTerm());
Assert.assertEquals(offset, record.getOffset());
LogEntryProto entry = lre.hasEntry() ? lre.getEntry() : segment.loadCache(lre.getRecord());
offset += getEntrySize(entry);
}
}
Aggregations