/** * Get the block id by the file id and block index. it will check whether the file and the block * exist. * * @param fileId the file id * @param blockIndex The index of the block in the file. * @return the block id if exists * @throws IOException if the file does not exist, or connection issue was encountered */ public synchronized long getBlockId(long fileId, int blockIndex) throws IOException { FileInfo info = getFileStatus(fileId, true); if (info == null) { throw new IOException("File " + fileId + " does not exist."); } if (info.blockIds.size() > blockIndex) { return info.blockIds.get(blockIndex); } try { return mFSMasterClient.getFileBlockInfo(fileId, blockIndex).blockInfo.getBlockId(); } catch (TachyonException e) { throw new IOException(e); } }
/** * Promotes block back to top layer after access. * * @param blockIndex the index of the block * @return true if success, false otherwise * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public boolean promoteBlock(int blockIndex) throws IOException { FileBlockInfo fileBlockInfo = getClientBlockInfo(blockIndex); return mTachyonFS.promoteBlock(fileBlockInfo.blockInfo.getBlockId()); }
public UiBlockInfo(FileBlockInfo fileBlockInfo) { Preconditions.checkNotNull(fileBlockInfo); mId = fileBlockInfo.getBlockInfo().getBlockId(); mBlockLength = fileBlockInfo.getBlockInfo().getLength(); mInMemory = isInMemory(fileBlockInfo.getBlockInfo()); mLastAccessTimeMs = -1; addLocations(fileBlockInfo); }
/** * Returns the local filename for the block if that file exists on the local file system. This is * an alpha power-api feature for applications that want short-circuit-read files directly. There * is no guarantee that the file still exists after this call returns, as Tachyon may evict blocks * from memory at any time. * * @param blockIndex The index of the block in the file * @return filename on local file system or null if file not present on local file system * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public String getLocalFilename(int blockIndex) throws IOException { FileBlockInfo fileBlockInfo = getClientBlockInfo(blockIndex); long blockId = fileBlockInfo.blockInfo.getBlockId(); int blockLockId = mTachyonFS.getBlockLockId(); String filename = mTachyonFS.lockBlock(blockId, blockLockId); if (filename != null) { mTachyonFS.unlockBlock(blockId, blockLockId); } return filename; }