Package org.apache.hadoop.hdfs.protocol
Class Block
java.lang.Object
org.apache.hadoop.hdfs.protocol.Block
- All Implemented Interfaces:
Comparable<Block>,org.apache.hadoop.io.Writable
@Private
@Evolving
public class Block
extends Object
implements org.apache.hadoop.io.Writable, Comparable<Block>
A Block is a Hadoop FS primitive, identified by its block ID (a long). A
block also has an accompanying generation stamp. A generation stamp is a
monotonically increasing 8-byte number for each block that is maintained
persistently by the NameNode. However, for the purposes of this class, two
Blocks are considered equal iff they have the same block ID.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidintCompares this Block with the specified Block for order.booleanIndicates whether some Block is "equal to" this one.static longfilename2id(String name) longstatic longgetBlockId(String metaOrBlockFile) Get the blockId from the name of the meta or block fileGet the block name.longstatic longgetGenerationStamp(String metaFile) Get generation stamp from the name of the metafile namelonginthashCode()Returns a hash code value for the Block.static booleanstatic booleanisMetaFilename(String name) static booleanmatchingIdAndGenStamp(Block a, Block b) A helper function to determine if two blocks are equal, based on the block ID and the generation stamp.static FilemetaToBlockFile(File metaFile) voidreadFields(DataInput in) voidvoidset(long blkid, long len, long genStamp) voidsetBlockId(long bid) voidsetGenerationStamp(long stamp) voidsetNumBytes(long len) toString()Get the block name.static StringA helper method to output the string representation of the Block portion of a derived class' instance.voidwrite(DataOutput out) voidwriteId(DataOutput out)
-
Field Details
-
BLOCK_FILE_PREFIX
- See Also:
-
METADATA_EXTENSION
- See Also:
-
blockFilePattern
-
metaFilePattern
-
metaOrBlockFilePattern
-
-
Constructor Details
-
Block
public Block() -
Block
public Block(long blkid, long len, long generationStamp) -
Block
public Block(long blkid) -
Block
-
Block
Find the blockid from the given filename
-
-
Method Details
-
isBlockFilename
-
filename2id
-
isMetaFilename
-
metaToBlockFile
-
getGenerationStamp
Get generation stamp from the name of the metafile name -
getBlockId
Get the blockId from the name of the meta or block file -
set
public void set(long blkid, long len, long genStamp) -
getBlockId
public long getBlockId() -
setBlockId
public void setBlockId(long bid) -
getBlockName
Get the block name. The format of the name is in the format:blk_1, blk_2, blk_3, etc.
- Returns:
- the block name
-
getNumBytes
public long getNumBytes() -
setNumBytes
public void setNumBytes(long len) -
getGenerationStamp
public long getGenerationStamp() -
setGenerationStamp
public void setGenerationStamp(long stamp) -
toString
A helper method to output the string representation of the Block portion of a derived class' instance.- Parameters:
b- the target object- Returns:
- the string representation of the block
-
toString
Get the block name. The format of the name is in the format:blk_block-id_generation, blk_1_1, blk_1_2, blk_2_1, etc.
-
appendStringTo
-
write
- Specified by:
writein interfaceorg.apache.hadoop.io.Writable- Throws:
IOException
-
readFields
- Specified by:
readFieldsin interfaceorg.apache.hadoop.io.Writable- Throws:
IOException
-
writeId
- Throws:
IOException
-
readId
- Throws:
IOException
-
compareTo
Compares this Block with the specified Block for order. Returns a negative integer, zero, or a positive integer as this Block is less than, equal to, or greater than the specified Block. Blocks are ordered based on their block ID.- Specified by:
compareToin interfaceComparable<Block>- Parameters:
b- the Block to be compared- Returns:
- a negative integer, zero, or a positive integer as this Block is less than, equal to, or greater than the specified Block.
-
equals
Indicates whether some Block is "equal to" this one. Two blocks are considered equal if they have the same block ID. -
hashCode
public int hashCode()Returns a hash code value for the Block. The hash code adheres to the general contract of hashCode. If two Blocks are equal according to the equals(Object) method, then calling the hashCode method on each of the two blocks produce the same integer result. -
matchingIdAndGenStamp
A helper function to determine if two blocks are equal, based on the block ID and the generation stamp. This is a different equalities check than the default behavior of the Block class. Two blocks are considered equal by this function iff the two blocks have the same block ID and the same generation stamp, or if both blocks are null.- Parameters:
a- an objectb- an object to be compared withafor equality- Returns:
trueif the blocks are deeply equal to each other andfalseotherwise- See Also:
-