Search in sources :

Example 11 with FileBlockInfo

use of alluxio.wire.FileBlockInfo in project alluxio by Alluxio.

the class AbstractFileSystem method getFileBlockLocations.

@Override
public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException {
    if (file == null) {
        return null;
    }
    if (mStatistics != null) {
        mStatistics.incrementReadOps(1);
    }
    AlluxioURI path = new AlluxioURI(HadoopUtils.getPathWithoutScheme(file.getPath()));
    List<FileBlockInfo> blocks = getFileBlocks(path);
    List<BlockLocation> blockLocations = new ArrayList<>();
    for (FileBlockInfo fileBlockInfo : blocks) {
        long offset = fileBlockInfo.getOffset();
        long end = offset + fileBlockInfo.getBlockInfo().getLength();
        // Check if there is any overlapping between [start, start+len] and [offset, end]
        if (end >= start && offset <= start + len) {
            ArrayList<String> names = new ArrayList<>();
            ArrayList<String> hosts = new ArrayList<>();
            // add the existing in-memory block locations
            for (alluxio.wire.BlockLocation location : fileBlockInfo.getBlockInfo().getLocations()) {
                HostAndPort address = HostAndPort.fromParts(location.getWorkerAddress().getHost(), location.getWorkerAddress().getDataPort());
                names.add(address.toString());
                hosts.add(address.getHostText());
            }
            // add under file system locations
            for (String location : fileBlockInfo.getUfsLocations()) {
                names.add(location);
                hosts.add(HostAndPort.fromString(location).getHostText());
            }
            blockLocations.add(new BlockLocation(CommonUtils.toStringArray(names), CommonUtils.toStringArray(hosts), offset, fileBlockInfo.getBlockInfo().getLength()));
        }
    }
    BlockLocation[] ret = new BlockLocation[blockLocations.size()];
    blockLocations.toArray(ret);
    return ret;
}
Also used : ArrayList(java.util.ArrayList) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocation(org.apache.hadoop.fs.BlockLocation) HostAndPort(com.google.common.net.HostAndPort) AlluxioURI(alluxio.AlluxioURI)

Aggregations

FileBlockInfo (alluxio.wire.FileBlockInfo)11 ArrayList (java.util.ArrayList)8 AlluxioURI (alluxio.AlluxioURI)4 BlockLocation (alluxio.wire.BlockLocation)4 FileInfo (alluxio.wire.FileInfo)4 InvalidPathException (alluxio.exception.InvalidPathException)3 BlockInfo (alluxio.wire.BlockInfo)3 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)2 FileSystemMasterView (alluxio.master.file.meta.FileSystemMasterView)2 InodeFile (alluxio.master.file.meta.InodeFile)2 LockedInodePath (alluxio.master.file.meta.LockedInodePath)2 PersistFile (alluxio.thrift.PersistFile)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 FileInStream (alluxio.client.file.FileInStream)1 FileSystem (alluxio.client.file.FileSystem)1 URIStatus (alluxio.client.file.URIStatus)1 OpenFileOptions (alluxio.client.file.options.OpenFileOptions)1 AccessControlException (alluxio.exception.AccessControlException)1