use of org.apache.ratis.server.raftlog.segmented.SegmentedRaftLogInputStream in project incubator-ratis by apache.
the class SimpleStateMachine4Testing method loadSnapshot.
private synchronized long loadSnapshot(SingleFileSnapshotInfo snapshot) throws IOException {
if (snapshot == null || !snapshot.getFile().getPath().toFile().exists()) {
LOG.info("The snapshot file {} does not exist", snapshot == null ? null : snapshot.getFile());
return RaftLog.INVALID_LOG_INDEX;
} else {
LOG.info("Loading snapshot {}", snapshot);
final long endIndex = snapshot.getIndex();
try (SegmentedRaftLogInputStream in = new SegmentedRaftLogInputStream(snapshot.getFile().getPath().toFile(), 0, endIndex, false)) {
LogEntryProto entry;
while ((entry = in.nextEntry()) != null) {
put(entry);
updateLastAppliedTermIndex(entry.getTerm(), entry.getIndex());
}
}
// The end index is greater than last entry in indexMap as it also
// includes the configuration and metadata entries
Preconditions.assertTrue(!indexMap.isEmpty() && endIndex >= indexMap.lastKey(), "endIndex=%s, indexMap=%s", endIndex, indexMap);
this.endIndexLastCkpt = endIndex;
setLastAppliedTermIndex(snapshot.getTermIndex());
this.storage.loadLatestSnapshot();
return endIndex;
}
}
Aggregations