Search in sources :

Example 1 with LogRecordWithEntry

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());
}
Also used : LogRecordWithEntry(org.apache.ratis.server.storage.LogSegment.LogRecordWithEntry) AutoCloseableLock(org.apache.ratis.util.AutoCloseableLock)

Example 2 with LogRecordWithEntry

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);
    }
}
Also used : SMLogEntryProto(org.apache.ratis.shaded.proto.RaftProtos.SMLogEntryProto) LogEntryProto(org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto) LogRecordWithEntry(org.apache.ratis.server.storage.LogSegment.LogRecordWithEntry)

Aggregations

LogRecordWithEntry (org.apache.ratis.server.storage.LogSegment.LogRecordWithEntry)2 LogEntryProto (org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto)1 SMLogEntryProto (org.apache.ratis.shaded.proto.RaftProtos.SMLogEntryProto)1 AutoCloseableLock (org.apache.ratis.util.AutoCloseableLock)1