Example usage for org.apache.hadoop.fs HdfsBlockLocation HdfsBlockLocation

List of usage examples for org.apache.hadoop.fs HdfsBlockLocation HdfsBlockLocation

Introduction

In this page you can find the example usage for org.apache.hadoop.fs HdfsBlockLocation HdfsBlockLocation.

Prototype

public HdfsBlockLocation(BlockLocation loc, LocatedBlock block) 

Source Link

Usage

From source file:com.mellanox.r4h.DFSClient.java

License:Apache License

/**
 * Get block location info about file/*w ww.j a v  a 2 s.  c om*/
 * 
 * getBlockLocations() returns a list of hostnames that store
 * data for a specific file region. It returns a set of hostnames
 * for every block within the indicated region.
 * 
 * This function is very useful when writing code that considers
 * data-placement when performing operations. For example, the
 * MapReduce system tries to schedule tasks on the same machines
 * as the data-block the task processes.
 */
public BlockLocation[] getBlockLocations(String src, long start, long length)
        throws IOException, UnresolvedLinkException {
    TraceScope scope = getPathTraceScope("getBlockLocations", src);
    try {
        LocatedBlocks blocks = getLocatedBlocks(src, start, length);
        BlockLocation[] locations = DFSUtil.locatedBlocks2Locations(blocks);
        HdfsBlockLocation[] hdfsLocations = new HdfsBlockLocation[locations.length];
        for (int i = 0; i < locations.length; i++) {
            hdfsLocations[i] = new HdfsBlockLocation(locations[i], blocks.get(i));
        }
        return hdfsLocations;
    } finally {
        scope.close();
    }
}