/** * Convenience method for updating mCurrentBlockInStream, mShouldCacheCurrentBlock, and * mCurrentCacheStream. If the block boundary has been reached, the current BlockInStream is * closed and a the next one is opened. mShouldCacheCurrent block is set to * mTachyonStorageType.isCache(). mCurrentCacheStream is also closed and a new one is created for * the next block. * * @throws IOException if the next BlockInStream cannot be obtained */ private void checkAndAdvanceBlockInStream() throws IOException { long currentBlockId = getCurrentBlockId(); if (mCurrentBlockInStream == null || mCurrentBlockInStream.remaining() == 0) { closeCacheStream(); updateBlockInStream(currentBlockId); if (mShouldCacheCurrentBlock) { try { // TODO(calvin): Specify the location to be local. mCurrentCacheStream = mContext.getTachyonBlockStore().getOutStream(currentBlockId, -1, NetworkAddressUtils.getLocalHostName(ClientContext.getConf())); } catch (IOException ioe) { LOG.warn("Failed to get TachyonStore stream, the block " + currentBlockId + " will not be in TachyonStorage. Exception:" + ioe.getMessage()); mShouldCacheCurrentBlock = false; } } } }
/** * Similar to checkAndAdvanceBlockInStream, but a specific position can be specified and the * stream pointer will be at that offset after this method completes. * * @param newPos the new position to set the stream to * @throws IOException if the stream at the specified position cannot be opened */ private void seekBlockInStream(long newPos) throws IOException { long oldBlockId = getCurrentBlockId(); mPos = newPos; closeCacheStream(); long currentBlockId = getCurrentBlockId(); if (oldBlockId != currentBlockId) { updateBlockInStream(currentBlockId); // Reading next block entirely. if (mPos % mBlockSize == 0 && mShouldCacheCurrentBlock) { try { mCurrentCacheStream = mContext.getTachyonBlockStore().getOutStream(currentBlockId, -1, NetworkAddressUtils.getLocalHostName(ClientContext.getConf())); } catch (IOException ioe) { LOG.warn("Failed to write to TachyonStore stream, block " + getCurrentBlockId() + " will not be in TachyonStorage. Exception:" + ioe.getMessage()); mShouldCacheCurrentBlock = false; } } else { mShouldCacheCurrentBlock = false; } } }