public UiBlockInfo(FileBlockInfo fileBlockInfo) { Preconditions.checkNotNull(fileBlockInfo); mId = fileBlockInfo.getBlockInfo().getBlockId(); mBlockLength = fileBlockInfo.getBlockInfo().getLength(); mInMemory = isInMemory(fileBlockInfo.getBlockInfo()); mLastAccessTimeMs = -1; addLocations(fileBlockInfo); }
return new LocalBlockInStream(blockId, blockInfo.getLength(), new InetSocketAddress(workerNetAddress.getHost(), workerNetAddress.getDataPort())); } catch (IOException e) { return new RemoteBlockInStream(blockId, blockInfo.getLength(), new InetSocketAddress(workerNetAddress.getHost(), workerNetAddress.getDataPort())); } finally {
for (int i = 0; i < blockInfoList.size(); i ++) { BlockInfo blockInfo = blockInfoList.get(i); fileLength += blockInfo.getLength(); if (i < blockInfoList.size() - 1 && blockInfo.getLength() != fileBlockSize) { throw new BlockInfoException( "Block index " + i + " has a block size smaller than the file block size ("
/** * Get the in-memory percentage of an Inode. For a file that has all blocks in memory, it returns * 100; for a file that has no block in memory, it returns 0. Returns 0 for a directory. * * @param inode the inode * @return the in memory percentage */ private int getInMemoryPercentage(Inode inode) { if (!inode.isFile()) { return 0; } InodeFile inodeFile = (InodeFile) inode; long length = inodeFile.getLength(); if (length == 0) { return 100; } long inMemoryLength = 0; for (BlockInfo info : mBlockMaster.getBlockInfoList(inodeFile.getBlockIds())) { if (isInMemory(info)) { inMemoryLength += info.getLength(); } } return (int) (inMemoryLength * 100 / length); }
BlockMasterClient blockMasterClient = mContext.acquireMasterClient(); try { blockSize = blockMasterClient.getBlockInfo(blockId).getLength(); } finally { mContext.releaseMasterClient(blockMasterClient);