Package org.apache.hadoop.fs
Class BlockLocation
java.lang.Object
org.apache.hadoop.fs.BlockLocation
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionDefault Constructor.BlockLocation(String[] names, String[] hosts, long offset, long length) Constructor with host, name, offset and length.BlockLocation(String[] names, String[] hosts, long offset, long length, boolean corrupt) Constructor with host, name, offset, length and corrupt flag.BlockLocation(String[] names, String[] hosts, String[] topologyPaths, long offset, long length) Constructor with host, name, network topology, offset and length.BlockLocation(String[] names, String[] hosts, String[] topologyPaths, long offset, long length, boolean corrupt) Constructor with host, name, network topology, offset, length and corrupt flag.BlockLocation(String[] names, String[] hosts, String[] cachedHosts, String[] topologyPaths, long offset, long length, boolean corrupt) BlockLocation(String[] names, String[] hosts, String[] cachedHosts, String[] topologyPaths, String[] storageIds, StorageType[] storageTypes, long offset, long length, boolean corrupt) BlockLocation(BlockLocation that) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionString[]Get the list of hosts (hostname) hosting a cached replica of the block.String[]getHosts()Get the list of hosts (hostname) hosting this block.longGet the length of the block.String[]getNames()Get the list of names (IP:xferPort) hosting this block.longGet the start offset of file associated with this block.String[]Get the storageID of each replica of the block.Get the storage type of each replica of the block.String[]Get the list of network topology paths for each of the hosts.booleanGet the corrupt flag.booleanReturn true if the block is striped (erasure coded).voidsetCachedHosts(String[] cachedHosts) Set the hosts hosting a cached replica of this block.voidsetCorrupt(boolean corrupt) Set the corrupt flag.voidSet the hosts hosting this block.voidsetLength(long length) Set the length of block.voidSet the names (host:port) hosting this block.voidsetOffset(long offset) Set the start offset of file associated with this block.voidsetStorageIds(String[] storageIds) voidsetStorageTypes(StorageType[] storageTypes) voidsetTopologyPaths(String[] topologyPaths) Set the network topology paths of the hosts.toString()
-
Constructor Details
-
BlockLocation
public BlockLocation()Default Constructor. -
BlockLocation
Copy constructor.- Parameters:
that- blocklocation.
-
BlockLocation
Constructor with host, name, offset and length.- Parameters:
names- names array.hosts- host array.offset- offset.length- length.
-
BlockLocation
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
-
BlockLocation
-
-
Method Details
-
getHosts
Get the list of hosts (hostname) hosting this block.- Returns:
- hosts array.
- Throws:
IOException- If an I/O error occurred.
-
getCachedHosts
Get the list of hosts (hostname) hosting a cached replica of the block.- Returns:
- cached hosts.
-
getNames
Get the list of names (IP:xferPort) hosting this block.- Returns:
- names array.
- Throws:
IOException- If an I/O error occurred.
-
getTopologyPaths
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
Get the storageID of each replica of the block.- Returns:
- storage ids.
-
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
Set the hosts hosting this block.- Parameters:
hosts- hosts array.- Throws:
IOException- If an I/O error occurred.
-
setCachedHosts
Set the hosts hosting a cached replica of this block.- Parameters:
cachedHosts- cached hosts.
-
setNames
Set the names (host:port) hosting this block.- Parameters:
names- names.- Throws:
IOException- If an I/O error occurred.
-
setTopologyPaths
Set the network topology paths of the hosts.- Parameters:
topologyPaths- topology paths.- Throws:
IOException- If an I/O error occurred.
-
setStorageIds
-
setStorageTypes
-
toString
-