Class BlockLocation

java.lang.Object
org.apache.hadoop.fs.BlockLocation
All Implemented Interfaces:
Serializable

@Public @Stable public class BlockLocation extends Object implements Serializable
Represents the network location of a block, information about the hosts that contain block replicas, and other block metadata (E.g. the file offset associated with the block, length, whether it is corrupt, etc). For a single BlockLocation, it will have different meanings for replicated and erasure coded files. If the file is 3-replicated, offset and length of a BlockLocation represent the absolute value in the file and the hosts are the 3 datanodes that holding the replicas. Here is an example:
 BlockLocation(offset: 0, length: BLOCK_SIZE,
   hosts: {"host1:9866", "host2:9866, host3:9866"})
 
And if the file is erasure-coded, each BlockLocation represents a logical block groups. Value offset is the offset of a block group in the file and value length is the total length of a block group. Hosts of a BlockLocation are the datanodes that holding all the data blocks and parity blocks of a block group. Suppose we have a RS_3_2 coded file (3 data units and 2 parity units). A BlockLocation example will be like:
 BlockLocation(offset: 0, length: 3 * BLOCK_SIZE, hosts: {"host1:9866",
   "host2:9866","host3:9866","host4:9866","host5:9866"})
 
Please refer to FileSystem.getFileBlockLocations(FileStatus, long, long) or FileContext.getFileBlockLocations(Path, long, long) for more examples.
See Also:
  • Constructor Details

    • BlockLocation

      public BlockLocation()
      Default Constructor.
    • BlockLocation

      public BlockLocation(BlockLocation that)
      Copy constructor.
      Parameters:
      that - blocklocation.
    • BlockLocation

      public BlockLocation(String[] names, String[] hosts, long offset, long length)
      Constructor with host, name, offset and length.
      Parameters:
      names - names array.
      hosts - host array.
      offset - offset.
      length - length.
    • BlockLocation

      public BlockLocation(String[] names, String[] hosts, long offset, long length, boolean corrupt)
      Constructor with host, name, offset, length and corrupt flag.
      Parameters:
      names - names.
      hosts - hosts.
      offset - offset.
      length - length.
      corrupt - corrupt.
    • BlockLocation

      public BlockLocation(String[] names, String[] hosts, String[] topologyPaths, long offset, long length)
      Constructor with host, name, network topology, offset and length.
      Parameters:
      names - names.
      hosts - hosts.
      topologyPaths - topologyPaths.
      offset - offset.
      length - length.
    • BlockLocation

      public BlockLocation(String[] names, String[] hosts, String[] topologyPaths, long offset, long length, boolean corrupt)
      Constructor with host, name, network topology, offset, length and corrupt flag.
      Parameters:
      names - names.
      hosts - hosts.
      topologyPaths - topologyPaths.
      offset - offset.
      length - length.
      corrupt - corrupt.
    • BlockLocation

      public BlockLocation(String[] names, String[] hosts, String[] cachedHosts, String[] topologyPaths, long offset, long length, boolean corrupt)
    • BlockLocation

      public BlockLocation(String[] names, String[] hosts, String[] cachedHosts, String[] topologyPaths, String[] storageIds, StorageType[] storageTypes, long offset, long length, boolean corrupt)
  • Method Details

    • getHosts

      public String[] getHosts() throws IOException
      Get the list of hosts (hostname) hosting this block.
      Returns:
      hosts array.
      Throws:
      IOException - If an I/O error occurred.
    • getCachedHosts

      public String[] getCachedHosts()
      Get the list of hosts (hostname) hosting a cached replica of the block.
      Returns:
      cached hosts.
    • getNames

      public String[] getNames() throws IOException
      Get the list of names (IP:xferPort) hosting this block.
      Returns:
      names array.
      Throws:
      IOException - If an I/O error occurred.
    • getTopologyPaths

      public String[] getTopologyPaths() throws IOException
      Get the list of network topology paths for each of the hosts. The last component of the path is the "name" (IP:xferPort).
      Returns:
      topology paths.
      Throws:
      IOException - If an I/O error occurred.
    • getStorageIds

      public String[] getStorageIds()
      Get the storageID of each replica of the block.
      Returns:
      storage ids.
    • getStorageTypes

      public StorageType[] getStorageTypes()
      Get the storage type of each replica of the block.
      Returns:
      storage type of each replica of the block.
    • getOffset

      public long getOffset()
      Get the start offset of file associated with this block.
      Returns:
      start offset of file associated with this block.
    • getLength

      public long getLength()
      Get the length of the block.
      Returns:
      length of the block.
    • isCorrupt

      public boolean isCorrupt()
      Get the corrupt flag.
      Returns:
      corrupt flag.
    • isStriped

      public boolean isStriped()
      Return true if the block is striped (erasure coded).
      Returns:
      if the block is striped true, not false.
    • setOffset

      public void setOffset(long offset)
      Set the start offset of file associated with this block.
      Parameters:
      offset - start offset.
    • setLength

      public void setLength(long length)
      Set the length of block.
      Parameters:
      length - length of block.
    • setCorrupt

      public void setCorrupt(boolean corrupt)
      Set the corrupt flag.
      Parameters:
      corrupt - corrupt flag.
    • setHosts

      public void setHosts(String[] hosts) throws IOException
      Set the hosts hosting this block.
      Parameters:
      hosts - hosts array.
      Throws:
      IOException - If an I/O error occurred.
    • setCachedHosts

      public void setCachedHosts(String[] cachedHosts)
      Set the hosts hosting a cached replica of this block.
      Parameters:
      cachedHosts - cached hosts.
    • setNames

      public void setNames(String[] names) throws IOException
      Set the names (host:port) hosting this block.
      Parameters:
      names - names.
      Throws:
      IOException - If an I/O error occurred.
    • setTopologyPaths

      public void setTopologyPaths(String[] topologyPaths) throws IOException
      Set the network topology paths of the hosts.
      Parameters:
      topologyPaths - topology paths.
      Throws:
      IOException - If an I/O error occurred.
    • setStorageIds

      public void setStorageIds(String[] storageIds)
    • setStorageTypes

      public void setStorageTypes(StorageType[] storageTypes)
    • toString

      public String toString()
      Overrides:
      toString in class Object