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 Details

    • BLOCK_FILE_PREFIX

      public static final String BLOCK_FILE_PREFIX
      See Also:
    • METADATA_EXTENSION

      public static final String METADATA_EXTENSION
      See Also:
    • blockFilePattern

      public static final Pattern blockFilePattern
    • metaFilePattern

      public static final Pattern metaFilePattern
    • metaOrBlockFilePattern

      public static final Pattern metaOrBlockFilePattern
  • Constructor Details

    • Block

      public Block()
    • Block

      public Block(long blkid, long len, long generationStamp)
    • Block

      public Block(long blkid)
    • Block

      public Block(Block blk)
    • Block

      public Block(File f, long len, long genstamp)
      Find the blockid from the given filename
  • Method Details

    • isBlockFilename

      public static boolean isBlockFilename(File f)
    • filename2id

      public static long filename2id(String name)
    • isMetaFilename

      public static boolean isMetaFilename(String name)
    • metaToBlockFile

      public static File metaToBlockFile(File metaFile)
    • getGenerationStamp

      public static long getGenerationStamp(String metaFile)
      Get generation stamp from the name of the metafile name
    • getBlockId

      public static long getBlockId(String metaOrBlockFile)
      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

      public String 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

      public static String toString(Block b)
      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

      public String 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.

      Overrides:
      toString in class Object
      Returns:
      the full block name
    • appendStringTo

      public void appendStringTo(StringBuilder sb)
    • write

      public void write(DataOutput out) throws IOException
      Specified by:
      write in interface org.apache.hadoop.io.Writable
      Throws:
      IOException
    • readFields

      public void readFields(DataInput in) throws IOException
      Specified by:
      readFields in interface org.apache.hadoop.io.Writable
      Throws:
      IOException
    • writeId

      public void writeId(DataOutput out) throws IOException
      Throws:
      IOException
    • readId

      public void readId(DataInput in) throws IOException
      Throws:
      IOException
    • compareTo

      public int compareTo(@Nonnull Block b)
      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:
      compareTo in interface Comparable<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

      public boolean equals(Object obj)
      Indicates whether some Block is "equal to" this one. Two blocks are considered equal if they have the same block ID.
      Overrides:
      equals in class Object
      Parameters:
      obj - the reference object with which to compare.
      Returns:
      true if this Block is the same as the argument; false otherwise.
    • 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.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for this block
      See Also:
    • matchingIdAndGenStamp

      public static boolean matchingIdAndGenStamp(Block a, Block b)
      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 object
      b - an object to be compared with a for equality
      Returns:
      true if the blocks are deeply equal to each other and false otherwise
      See Also: