in ratis-logservice/src/main/java/org/apache/ratis/logservice/server/LogStateMachine.java [219:245]
private long load(SingleFileSnapshotInfo snapshot, boolean reload) throws IOException {
if (snapshot == null) {
LOG.warn("The snapshot info is null.");
return RaftLog.INVALID_LOG_INDEX;
}
final File snapshotFile = snapshot.getFile().getPath().toFile();
if (!snapshotFile.exists()) {
LOG.warn("The snapshot file {} does not exist for snapshot {}", snapshotFile, snapshot);
return RaftLog.INVALID_LOG_INDEX;
}
final TermIndex last = SimpleStateMachineStorage.getTermIndexFromSnapshotFile(snapshotFile);
try(AutoCloseableLock writeLock = writeLock();
ObjectInputStream in = new ObjectInputStream(
new BufferedInputStream(new FileInputStream(snapshotFile)))) {
if (reload) {
reset();
}
setLastAppliedTermIndex(last);
this.length = in.readLong();
this.dataRecordsSize = in.readLong();
this.state = (State) in.readObject();
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e);
}
return last.getIndex();
}