Search in sources :

Example 1 with IgfsCorruptedFileException

use of org.apache.ignite.igfs.IgfsCorruptedFileException in project ignite by apache.

the class IgfsInputStreamImpl method block.

/**
 * @param blockIdx Block index.
 * @return File block data.
 * @throws IOException If failed.
 * @throws IgniteCheckedException If failed.
 */
private byte[] block(long blockIdx) throws IOException, IgniteCheckedException {
    assert blockIdx >= 0;
    IgniteInternalFuture<byte[]> bytesFut = locCache.get(blockIdx);
    if (bytesFut == null) {
        if (closed)
            throw new IOException("Stream is already closed: " + this);
        seqReads = (prevBlockIdx != -1 && prevBlockIdx + 1 == blockIdx) ? ++seqReads : 0;
        prevBlockIdx = blockIdx;
        bytesFut = dataBlock(blockIdx);
        assert bytesFut != null;
        addLocalCacheFuture(blockIdx, bytesFut);
    }
    // Schedule the next block(s) prefetch.
    if (prefetchBlocks > 0 && seqReads >= seqReadsBeforePrefetch - 1) {
        for (int i = 1; i <= prefetchBlocks; i++) {
            // Ensure that we do not prefetch over file size.
            if (blockSize * (i + blockIdx) >= len)
                break;
            else if (locCache.get(blockIdx + i) == null)
                addLocalCacheFuture(blockIdx + i, dataBlock(blockIdx + i));
        }
    }
    byte[] bytes = bytesFut.get();
    if (bytes == null)
        throw new IgfsCorruptedFileException("Failed to retrieve file's data block (corrupted file?) " + "[path=" + path + ", blockIdx=" + blockIdx + ']');
    int blockSize0 = blockSize;
    if (blockIdx == blocksCnt - 1)
        blockSize0 = (int) (len % blockSize0);
    // If part of the file was reserved for writing, but was not actually written.
    if (bytes.length < blockSize0)
        throw new IOException("Inconsistent file's data block (incorrectly written?)" + " [path=" + path + ", blockIdx=" + blockIdx + ", blockSize=" + bytes.length + ", expectedBlockSize=" + blockSize0 + ", fileBlockSize=" + blockSize + ", fileLen=" + len + ']');
    return bytes;
}
Also used : IgfsCorruptedFileException(org.apache.ignite.igfs.IgfsCorruptedFileException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 IgfsCorruptedFileException (org.apache.ignite.igfs.IgfsCorruptedFileException)1