use of org.apache.ratis.server.storage.FileChunkReader in project incubator-ratis by apache.
the class InstallSnapshotRequests method nextInstallSnapshotRequestProto.
private InstallSnapshotRequestProto nextInstallSnapshotRequestProto() {
final int numFiles = snapshot.getFiles().size();
if (fileIndex >= numFiles) {
throw new NoSuchElementException();
}
final FileInfo info = snapshot.getFiles().get(fileIndex);
try {
if (current == null) {
current = new FileChunkReader(info, server.getRaftStorage().getStorageDir());
}
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);
}
}
Aggregations