/** * @param blockId id of the block * @return the block info associated with the block id, note that this will be a cached copy * and will not fetch the latest info from the master */ public BlockInfo getBlockInfo(long blockId) { Preconditions.checkArgument(mStatus.getBlockIds().contains(blockId), "blockId"); return mStatus.getFileBlockInfos().stream().map(FileBlockInfo::getBlockInfo) .filter(blockInfo -> blockInfo.getBlockId() == blockId).findFirst().get(); }
@Override protected void runPlainPath(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { URIStatus status = mFileSystem.getStatus(path); if (cl.hasOption('f')) { System.out.println(formatOutput(cl, status)); } else { if (status.isFolder()) { System.out.println(path + " is a directory path."); System.out.println(status); } else { System.out.println(path + " is a file path."); System.out.println(status); AlluxioBlockStore blockStore = AlluxioBlockStore.create(mFsContext); List<Long> blockIds = status.getBlockIds(); if (blockIds.isEmpty()) { System.out.println("This file does not contain any blocks."); } else { System.out.println("Containing the following blocks: "); for (long blockId : blockIds) { System.out.println(blockStore.getInfo(blockId)); } } } } }
@Override protected void runPlainPath(AlluxioURI plainPath, CommandLine cl) throws AlluxioException, IOException { URIStatus status = mFileSystem.getStatus(plainPath); System.out.println(plainPath + " with file id " + status.getFileId() + " is on nodes: "); AlluxioBlockStore blockStore = AlluxioBlockStore.create(mFsContext); for (long blockId : status.getBlockIds()) { for (BlockLocation location : blockStore.getInfo(blockId).getLocations()) { System.out.println(location.getWorkerAddress().getHost()); } } }
/** * Initializes the underlying block stream if necessary. This method must be called before * reading from mBlockInStream. */ private void updateStream() throws IOException { if (mBlockInStream != null && mBlockInStream.remaining() > 0) { // can still read from stream return; } if (mBlockInStream != null && mBlockInStream.remaining() == 0) { // current stream is done closeBlockInStream(mBlockInStream); } /* Create a new stream to read from mPosition. */ // Calculate block id. long blockId = mStatus.getBlockIds().get(Math.toIntExact(mPosition / mBlockSize)); // Create stream mBlockInStream = mBlockStore.getInStream(blockId, mOptions, mFailedWorkers); // Set the stream to the correct position. long offset = mPosition % mBlockSize; mBlockInStream.seek(offset); }
break; long blockId = mStatus.getBlockIds().get(Math.toIntExact(pos / mBlockSize)); try {
URIStatus status = mFsClient.getStatus(new AlluxioURI(requestPath)); UIFileInfo uiFileInfo = new UIFileInfo(status); for (long blockId : status.getBlockIds()) { if (mBlockWorker.hasBlockMeta(blockId)) { BlockMeta blockMeta = mBlockWorker.getVolatileBlockMeta(blockId); URIStatus status = new URIStatus(mBlockWorker.getFileInfo(fileId)); UIFileInfo uiFileInfo = new UIFileInfo(status); for (long blockId : status.getBlockIds()) { if (mBlockWorker.hasBlockMeta(blockId)) { BlockMeta blockMeta = mBlockWorker.getVolatileBlockMeta(blockId);
/** * @param blockId id of the block * @return a {@link Protocol.OpenUfsBlockOptions} based on the block id and options */ public Protocol.OpenUfsBlockOptions getOpenUfsBlockOptions(long blockId) { Preconditions.checkArgument(mStatus.getBlockIds().contains(blockId), "blockId"); boolean readFromUfs = mStatus.isPersisted(); // In case it is possible to fallback to read UFS blocks, also fill in the options. boolean storedAsUfsBlock = mStatus.getPersistenceState().equals("TO_BE_PERSISTED"); readFromUfs = readFromUfs || storedAsUfsBlock; if (!readFromUfs) { return Protocol.OpenUfsBlockOptions.getDefaultInstance(); } long blockStart = BlockId.getSequenceNumber(blockId) * mStatus.getBlockSizeBytes(); BlockInfo info = getBlockInfo(blockId); Protocol.OpenUfsBlockOptions openUfsBlockOptions = Protocol.OpenUfsBlockOptions.newBuilder() .setUfsPath(mStatus.getUfsPath()).setOffsetInFile(blockStart).setBlockSize(info.getLength()) .setMaxUfsReadConcurrency(mProtoOptions.getMaxUfsReadConcurrency()) .setNoCache(!ReadType.fromProto(mProtoOptions.getReadType()).isCache()) .setMountId(mStatus.getMountId()).build(); if (storedAsUfsBlock) { // On client-side, we do not have enough mount information to fill in the UFS file path. // Instead, we unset the ufsPath field and fill in a flag ufsBlock to indicate the UFS file // path can be derived from mount id and the block ID. Also because the entire file is only // one block, we set the offset in file to be zero. openUfsBlockOptions = openUfsBlockOptions.toBuilder().clearUfsPath().setBlockInUfsTier(true) .setOffsetInFile(0).build(); } return openUfsBlockOptions; }
/** * @return the current block id based on mPos, -1 if at the end of the file */ private long getCurrentBlockId() { if (mPos == mFileLength) { return -1; } int index = (int) (mPos / mBlockSize); Preconditions.checkState(index < mStatus.getBlockIds().size(), PreconditionMessage.ERR_BLOCK_INDEX); return mStatus.getBlockIds().get(index); }
FileInfo fileInfo = FileInfoTest.createRandom(); URIStatus uriStatus = new URIStatus(fileInfo); Assert.assertEquals(uriStatus.getBlockIds(), fileInfo.getBlockIds()); Assert.assertEquals(uriStatus.getBlockSizeBytes(), fileInfo.getBlockSizeBytes());