in ratis-server/src/main/java/org/apache/ratis/server/leader/InstallSnapshotRequests.java [114:143]
public InstallSnapshotRequestProto next() {
if (!hasNext()) {
throw new NoSuchElementException("fileIndex = " + fileIndex + " >= numFiles = " + numFiles);
}
final FileInfo info = snapshot.getFiles().get(fileIndex);
try {
if (current == null) {
current = new FileChunkReader(info, getRelativePath.apply(info));
}
final FileChunkProto chunk = current.readFileChunk(snapshotChunkMaxSize);
if (chunk.getDone()) {
current.close();
current = null;
fileIndex++;
}
final boolean done = fileIndex == numFiles && chunk.getDone();
return newInstallSnapshotRequest(chunk, done);
} catch (IOException e) {
if (current != null) {
try {
current.close();
current = null;
} catch (IOException ignored) {
}
}
throw new IllegalStateException("Failed to iterate installSnapshot requests: " + this, e);
}
}