Search in sources :

Example 1 with FileChunkReader

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);
    }
}
Also used : FileInfo(org.apache.ratis.server.storage.FileInfo) FileChunkReader(org.apache.ratis.server.storage.FileChunkReader) FileChunkProto(org.apache.ratis.proto.RaftProtos.FileChunkProto) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

IOException (java.io.IOException)1 NoSuchElementException (java.util.NoSuchElementException)1 FileChunkProto (org.apache.ratis.proto.RaftProtos.FileChunkProto)1 FileChunkReader (org.apache.ratis.server.storage.FileChunkReader)1 FileInfo (org.apache.ratis.server.storage.FileInfo)1