/** * @param file the file the block belongs to * @param readType the InStream's read type * @param blockIndex the index of the block in the file * @param ufsConf the under file system configuration * @throws IOException */ RemoteBlockInStream(TachyonFile file, ReadType readType, int blockIndex, Object ufsConf) throws IOException { super(file, readType, blockIndex); mBlockInfo = TFS.getClientBlockInfo(FILE.FID, BLOCK_INDEX); mReadByte = 0; mBufferStartPosition = 0; if (!FILE.isComplete()) { throw new IOException("File " + FILE.getPath() + " is not ready to read"); } mRecache = readType.isCache(); if (mRecache) { mBlockOutStream = new BlockOutStream(file, WriteType.TRY_CACHE, blockIndex); } updateCurrentBuffer(); mUFSConf = ufsConf; if (mCurrentBuffer == null) { setupStreamFromUnderFs(mBlockInfo.offset, mUFSConf); if (mCheckpointInputStream == null) { TFS.reportLostFile(FILE.FID); throw new IOException("Can not find the block " + FILE + " " + BLOCK_INDEX); } } }
private void updateCurrentBuffer() throws IOException { long length = BUFFER_SIZE; if (mBufferStartPosition + length > mBlockInfo.length) { length = mBlockInfo.length - mBufferStartPosition; } LOG.info( String.format( "Try to find remote worker and read block %d from %d, with len %d", mBlockInfo.blockId, mBufferStartPosition, length)); mCurrentBuffer = readRemoteByteBuffer(mBlockInfo, mBufferStartPosition, length); if (mCurrentBuffer == null) { mBlockInfo = TFS.getClientBlockInfo(FILE.FID, BLOCK_INDEX); mCurrentBuffer = readRemoteByteBuffer(mBlockInfo, mBufferStartPosition, length); } }