public static FileBlockInfo createRandom() { FileBlockInfo result = new FileBlockInfo(); Random random = new Random(); BlockInfo blockInfo = BlockInfoTest.createRandom(); long offset = random.nextLong(); List<String> ufsLocations = new ArrayList<>(); long numUfsLocations = random.nextInt(10); for (int i = 0; i < numUfsLocations; i++) { ufsLocations.add(HostAndPort.fromParts(CommonUtils.randomAlphaNumString(random.nextInt(10)), random.nextInt(Constants.MAX_PORT)).toString()); } result.setBlockInfo(blockInfo); result.setOffset(offset); result.setUfsLocations(ufsLocations); return result; } }
/** * Converts a proto type to a wire type. * * @param fileBlockPInfo the proto type to convert * @return the converted wire type */ public static FileBlockInfo fromProto(alluxio.grpc.FileBlockInfo fileBlockPInfo) { return new FileBlockInfo().setBlockInfo(fromProto(fileBlockPInfo.getBlockInfo())) .setOffset(fileBlockPInfo.getOffset()).setUfsLocations( fileBlockPInfo.getUfsLocationsCount() > 0 ? fileBlockPInfo.getUfsStringLocationsList() : map(addr -> HostAndPort.fromParts(addr.getHost(), addr.getDataPort()).toString(), fileBlockPInfo.getUfsLocationsList())); }
/** * Generates a {@link FileBlockInfo} object from internal metadata. This adds file information to * the block, such as the file offset, and additional UFS locations for the block. * * @param inodePath the file the block is a part of * @param blockInfo the {@link BlockInfo} to generate the {@link FileBlockInfo} from * @return a new {@link FileBlockInfo} for the block */ private FileBlockInfo generateFileBlockInfo(LockedInodePath inodePath, BlockInfo blockInfo) throws FileDoesNotExistException { InodeFile file = inodePath.getInodeFile(); FileBlockInfo fileBlockInfo = new FileBlockInfo(); fileBlockInfo.setBlockInfo(blockInfo); fileBlockInfo.setUfsLocations(new ArrayList<>()); // The sequence number part of the block id is the block index. long offset = file.getBlockSizeBytes() * BlockId.getSequenceNumber(blockInfo.getBlockId()); fileBlockInfo.setOffset(offset); if (fileBlockInfo.getBlockInfo().getLocations().isEmpty() && file.isPersisted()) { // No alluxio locations, but there is a checkpoint in the under storage system. Add the // locations from the under storage system. long blockId = fileBlockInfo.getBlockInfo().getBlockId(); List<String> locations = mUfsBlockLocationCache.get(blockId, inodePath.getUri(), fileBlockInfo.getOffset()); if (locations != null) { fileBlockInfo.setUfsLocations(locations); } } return fileBlockInfo; }
/** * Creates a new instance of {@link FileBlockInfo} from a thrift representation. * * @param info the thrift representation of a file block information * @return the instance */ public static FileBlockInfo fromThrift(alluxio.thrift.FileBlockInfo info) { return new FileBlockInfo() .setBlockInfo(BlockInfo.fromThrift(info.getBlockInfo())) .setOffset(info.getOffset()) .setUfsLocations(info.getUfsStringLocationsSize() > 0 ? info.getUfsStringLocations() : map(addr -> HostAndPort.fromParts(addr.getHost(), addr.getDataPort()).toString(), info.getUfsLocations())); }
/** * Generates a {@link FileBlockInfo} object from internal metadata. This adds file information to * the block, such as the file offset, and additional UFS locations for the block. * * @param inodePath the file the block is a part of * @param blockInfo the {@link BlockInfo} to generate the {@link FileBlockInfo} from * @return a new {@link FileBlockInfo} for the block * @throws InvalidPathException if the mount table is not able to resolve the file */ private FileBlockInfo generateFileBlockInfo(LockedInodePath inodePath, BlockInfo blockInfo) throws InvalidPathException, FileDoesNotExistException { InodeFile file = inodePath.getInodeFile(); FileBlockInfo fileBlockInfo = new FileBlockInfo(); fileBlockInfo.setBlockInfo(blockInfo); fileBlockInfo.setUfsLocations(new ArrayList<>()); // The sequence number part of the block id is the block index. long offset = file.getBlockSizeBytes() * BlockId.getSequenceNumber(blockInfo.getBlockId()); fileBlockInfo.setOffset(offset); if (fileBlockInfo.getBlockInfo().getLocations().isEmpty() && file.isPersisted()) { // No alluxio locations, but there is a checkpoint in the under storage system. Add the // locations from the under storage system. long blockId = fileBlockInfo.getBlockInfo().getBlockId(); List<String> locations = mUfsBlockLocationCache.get(blockId, inodePath.getUri(), fileBlockInfo.getOffset()); if (locations != null) { fileBlockInfo.setUfsLocations(locations); } } return fileBlockInfo; }