Class ReplicaInfo

java.lang.Object
org.apache.hadoop.hdfs.protocol.Block
org.apache.hadoop.hdfs.server.datanode.ReplicaInfo
All Implemented Interfaces:
Comparable<org.apache.hadoop.hdfs.protocol.Block>, Replica, org.apache.hadoop.io.Writable, org.apache.hadoop.util.LightWeightGSet.LinkedElement
Direct Known Subclasses:
LocalReplica, ProvidedReplica

@Private public abstract class ReplicaInfo extends org.apache.hadoop.hdfs.protocol.Block implements Replica, org.apache.hadoop.util.LightWeightGSet.LinkedElement
This class is used by datanodes to maintain meta data of its replicas. It provides a general interface for meta information of a replica.
  • Method Details

    • getVolume

      public FsVolumeSpi getVolume()
      Description copied from interface: Replica
      Get the volume of replica.
      Specified by:
      getVolume in interface Replica
      Returns:
      the volume where this replica is located on disk
    • getFileIoProvider

      public FileIoProvider getFileIoProvider()
      Get the FileIoProvider for disk IO operations.
    • getStorageUuid

      public String getStorageUuid()
      Get the storageUuid of the volume that stores this replica.
      Specified by:
      getStorageUuid in interface Replica
    • getBytesReserved

      public long getBytesReserved()
      Number of bytes reserved for this replica on disk.
    • getBlockURI

      public abstract URI getBlockURI()
      Get the URI for where the data of this replica is stored.
      Returns:
      URI for the location of replica data.
    • getDataInputStream

      public abstract InputStream getDataInputStream(long seekOffset) throws IOException
      Returns an InputStream to the replica's data.
      Parameters:
      seekOffset - the offset at which the read is started from.
      Returns:
      the InputStream to read the replica data.
      Throws:
      IOException - if an error occurs in opening a stream to the data.
    • getDataOutputStream

      public abstract OutputStream getDataOutputStream(boolean append) throws IOException
      Returns an OutputStream to the replica's data.
      Parameters:
      append - indicates if the block should be opened for append.
      Returns:
      the OutputStream to write to the replica.
      Throws:
      IOException - if an error occurs in creating an OutputStream.
    • blockDataExists

      public abstract boolean blockDataExists()
      Returns:
      true if the replica's data exists.
    • deleteBlockData

      public abstract boolean deleteBlockData()
      Used to deletes the replica's block data.
      Returns:
      true if the replica's data is successfully deleted.
    • getBlockDataLength

      public abstract long getBlockDataLength()
      Returns:
      the length of the block on storage.
    • getMetadataURI

      public abstract URI getMetadataURI()
      Get the URI for where the metadata of this replica is stored.
      Returns:
      URI for the location of replica metadata.
    • getMetadataInputStream

      public abstract LengthInputStream getMetadataInputStream(long offset) throws IOException
      Returns an InputStream to the replica's metadata.
      Parameters:
      offset - the offset at which the read is started from.
      Returns:
      the LengthInputStream to read the replica metadata.
      Throws:
      IOException
    • getMetadataOutputStream

      public abstract OutputStream getMetadataOutputStream(boolean append) throws IOException
      Returns an OutputStream to the replica's metadata.
      Parameters:
      append - indicates if the block metadata should be opened for append.
      Returns:
      the OutputStream to write to the replica's metadata.
      Throws:
      IOException - if an error occurs in creating an OutputStream.
    • metadataExists

      public abstract boolean metadataExists()
      Returns:
      true if the replica's metadata exists.
    • deleteMetadata

      public abstract boolean deleteMetadata()
      Used to deletes the replica's metadata.
      Returns:
      true if the replica's metadata is successfully deleted.
    • getMetadataLength

      public abstract long getMetadataLength()
      Returns:
      the length of the metadata on storage.
    • renameMeta

      public abstract boolean renameMeta(URI destURI) throws IOException
      Rename the metadata URI to that referenced by destURI.
      Parameters:
      destURI - the target URI.
      Returns:
      true if the rename is successful.
      Throws:
      IOException - if an exception occurs in the rename.
    • renameData

      public abstract boolean renameData(URI destURI) throws IOException
      Rename the data URI to that referenced by destURI.
      Parameters:
      destURI - the target URI.
      Returns:
      true if the rename is successful.
      Throws:
      IOException - if an exception occurs in the rename.
    • updateWithReplica

      public abstract void updateWithReplica(StorageLocation replicaLocation)
      Update this replica with the StorageLocation found.
      Parameters:
      replicaLocation - the StorageLocation found for this replica.
    • getPinning

      public abstract boolean getPinning(org.apache.hadoop.fs.LocalFileSystem localFS) throws IOException
      Check whether the block was pinned.
      Parameters:
      localFS - the local filesystem to use.
      Returns:
      true if the block is pinned.
      Throws:
      IOException
    • setPinning

      public abstract void setPinning(org.apache.hadoop.fs.LocalFileSystem localFS) throws IOException
      Set a block to be pinned on this datanode so that it cannot be moved by Balancer/Mover.
      Parameters:
      localFS - the local filesystem to use.
      Throws:
      IOException - if there is an exception in the pinning.
    • bumpReplicaGS

      public abstract void bumpReplicaGS(long newGS) throws IOException
      Bump a replica's generation stamp to a new one. Its on-disk meta file name is renamed to be the new one too.
      Parameters:
      newGS - new generation stamp
      Throws:
      IOException - if the change fails
    • getOriginalReplica

      public abstract ReplicaInfo getOriginalReplica()
    • getRecoveryID

      public abstract long getRecoveryID()
      Get the recovery id.
      Returns:
      the generation stamp that the replica will be bumped to
    • setRecoveryID

      public abstract void setRecoveryID(long recoveryId)
      Set the recovery id.
      Parameters:
      recoveryId - the new recoveryId
    • breakHardLinksIfNeeded

      public abstract boolean breakHardLinksIfNeeded() throws IOException
      Throws:
      IOException
    • createInfo

      public abstract ReplicaRecoveryInfo createInfo()
    • compareWith

      public abstract int compareWith(FsVolumeSpi.ScanInfo info)
    • truncateBlock

      public abstract void truncateBlock(long newLength) throws IOException
      Throws:
      IOException
    • copyMetadata

      public abstract void copyMetadata(URI destination) throws IOException
      Throws:
      IOException
    • copyBlockdata

      public abstract void copyBlockdata(URI destination) throws IOException
      Throws:
      IOException
    • getOriginalBytesReserved

      public long getOriginalBytesReserved()
      Number of bytes originally reserved for this replica. The actual reservation is adjusted as data is written to disk.
      Returns:
      the number of bytes originally reserved for this replica.
    • toString

      public String toString()
      Overrides:
      toString in class org.apache.hadoop.hdfs.protocol.Block
    • isOnTransientStorage

      public boolean isOnTransientStorage()
      Description copied from interface: Replica
      Return true if the target volume is backed by RAM.
      Specified by:
      isOnTransientStorage in interface Replica
    • getNext

      public org.apache.hadoop.util.LightWeightGSet.LinkedElement getNext()
      Specified by:
      getNext in interface org.apache.hadoop.util.LightWeightGSet.LinkedElement
    • setNext

      public void setNext(org.apache.hadoop.util.LightWeightGSet.LinkedElement next)
      Specified by:
      setNext in interface org.apache.hadoop.util.LightWeightGSet.LinkedElement