in ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLog.java [166:205]
private ServerLogMethods newServerLogMethods(RaftServer.Division impl,
Consumer<LogEntryProto> notifyTruncatedLogEntry,
BiFunction<LogEntryProto, Boolean, TransactionContext> getTransactionContext) {
if (impl == null) {
return ServerLogMethods.DUMMY;
}
return new ServerLogMethods() {
@Override
public long[] getFollowerNextIndices() {
return impl.getInfo().getFollowerNextIndices();
}
@Override
public long getLastAppliedIndex() {
return impl.getInfo().getLastAppliedIndex();
}
@Override
public void notifyTruncatedLogEntry(TermIndex ti) {
ReferenceCountedObject<LogEntryProto> ref = null;
try {
ref = retainLog(ti.getIndex());
final LogEntryProto entry = ref != null ? ref.get() : null;
notifyTruncatedLogEntry.accept(entry);
} catch (RaftLogIOException e) {
LOG.error("{}: Failed to read log {}", getName(), ti, e);
} finally {
if (ref != null) {
ref.release();
}
}
}
@Override
public TransactionContext getTransactionContext(LogEntryProto entry, boolean createNew) {
return getTransactionContext.apply(entry, createNew);
}
};
}