Skip to content

Commit

Permalink
Fix checkstyle and some minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
szetszwo committed Aug 1, 2024
1 parent e4af201 commit 49a6ac6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private void assertSegment(long expectedStart, int expectedEntryCount, boolean c
final long expectedLastIndex = expectedStart + expectedEntryCount - 1;
Preconditions.assertSame(expectedLastIndex, getEndIndex(), "Segment end index");

final LogRecord last = getLastRecord();
final LogRecord last = records.getLast();
if (last != null) {
Preconditions.assertSame(expectedLastIndex, last.getTermIndex().getIndex(), "Index at the last record");
final LogRecord first = records.getFirst();
Expand Down Expand Up @@ -449,12 +449,8 @@ LogRecord getLogRecord(long index) {
return null;
}

private LogRecord getLastRecord() {
return records.getLast();
}

TermIndex getLastTermIndex() {
LogRecord last = getLastRecord();
final LogRecord last = records.getLast();
return last == null ? null : last.getTermIndex();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ private void checkAndEvictCache() {
@Override
public TermIndex getTermIndex(long index) {
checkLogState();
final LogRecord record = cache.getLogRecord(index);
return record != null ? record.getTermIndex() : null;
return cache.getTermIndex(index);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,17 +521,21 @@ void rollOpenSegment(boolean createNewOpen) {
}

LogSegment getSegment(long index) {
final LogSegment openSegment = this.openSegment;
if (openSegment != null && index >= openSegment.getStartIndex()) {
return openSegment;
final LogSegment open = this.openSegment;
if (open != null && index >= open.getStartIndex()) {
return open;
} else {
return closedSegments.search(index);
}
}

LogRecord getLogRecord(long index) {
TermIndex getTermIndex(long index) {
LogSegment segment = getSegment(index);
return segment == null ? null : segment.getLogRecord(index);
if (segment == null) {
return null;
}
final LogRecord record = segment.getLogRecord(index);
return record != null ? record.getTermIndex() : null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.apache.ratis.server.metrics.SegmentedRaftLogMetrics.*;
import static org.apache.ratis.server.raftlog.segmented.SegmentedRaftLogTestUtils.MAX_OP_SIZE;

import java.io.IOException;
import java.util.Iterator;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -286,12 +285,12 @@ private void populatedSegment(int start, int end, int segmentSize, boolean isOpe
});
}

private void testIterator(long startIndex) throws IOException {
private void testIterator(long startIndex) {
Iterator<TermIndex> iterator = cache.iterator(startIndex);
TermIndex prev = null;
while (iterator.hasNext()) {
TermIndex termIndex = iterator.next();
Assertions.assertEquals(cache.getLogRecord(termIndex.getIndex()).getTermIndex(), termIndex);
Assertions.assertEquals(cache.getTermIndex(termIndex.getIndex()), termIndex);
if (prev != null) {
Assertions.assertEquals(prev.getIndex() + 1, termIndex.getIndex());
}
Expand Down

0 comments on commit 49a6ac6

Please sign in to comment.