Class LocalReplicaInPipeline

java.lang.Object
org.apache.hadoop.hdfs.protocol.Block
All Implemented Interfaces:
Comparable<org.apache.hadoop.hdfs.protocol.Block>, Replica, ReplicaInPipeline, org.apache.hadoop.io.Writable, org.apache.hadoop.util.LightWeightGSet.LinkedElement
Direct Known Subclasses:
ReplicaBeingWritten

public class LocalReplicaInPipeline extends LocalReplica implements ReplicaInPipeline
This class defines a replica in a pipeline, which includes a persistent replica being written to by a dfs client or a temporary replica being replicated by a source datanode or being copied for the balancing purpose. The base class implements a temporary replica
  • Constructor Details

    • LocalReplicaInPipeline

      public LocalReplicaInPipeline(long blockId, long genStamp, FsVolumeSpi vol, File dir, long bytesToReserve)
      Constructor for a zero length replica.
      Parameters:
      blockId - block id
      genStamp - replica generation stamp
      vol - volume where replica is located
      dir - directory path where block and meta files are located
      bytesToReserve - disk space to reserve for this replica, based on the estimated maximum block length.
    • LocalReplicaInPipeline

      public LocalReplicaInPipeline(LocalReplicaInPipeline from)
      Copy constructor.
      Parameters:
      from - where to copy from
  • Method Details

    • getVisibleLength

      public long getVisibleLength()
      Description copied from interface: Replica
      Get the number of bytes that are visible to readers
      Specified by:
      getVisibleLength in interface Replica
      Returns:
      the number of bytes that are visible to readers
    • getState

      Description copied from interface: Replica
      Get the replica state
      Specified by:
      getState in interface Replica
      Returns:
      the replica state
    • getBytesAcked

      public long getBytesAcked()
      Description copied from interface: ReplicaInPipeline
      Get the number of bytes acked
      Specified by:
      getBytesAcked in interface ReplicaInPipeline
      Returns:
      the number of bytes acked
    • setBytesAcked

      public void setBytesAcked(long bytesAcked)
      Description copied from interface: ReplicaInPipeline
      Set the number bytes that have acked
      Specified by:
      setBytesAcked in interface ReplicaInPipeline
      Parameters:
      bytesAcked - number bytes acked
    • getBytesOnDisk

      public long getBytesOnDisk()
      Description copied from interface: Replica
      Get the number of bytes that have written to disk
      Specified by:
      getBytesOnDisk in interface Replica
      Returns:
      the number of bytes that have written to disk
    • getBytesReserved

      public long getBytesReserved()
      Description copied from class: ReplicaInfo
      Number of bytes reserved for this replica on disk.
      Overrides:
      getBytesReserved in class ReplicaInfo
    • getOriginalBytesReserved

      public long getOriginalBytesReserved()
      Description copied from class: ReplicaInfo
      Number of bytes originally reserved for this replica. The actual reservation is adjusted as data is written to disk.
      Overrides:
      getOriginalBytesReserved in class ReplicaInfo
      Returns:
      the number of bytes originally reserved for this replica.
    • releaseAllBytesReserved

      public void releaseAllBytesReserved()
      Description copied from interface: ReplicaInPipeline
      Release any disk space reserved for this replica.
      Specified by:
      releaseAllBytesReserved in interface ReplicaInPipeline
    • releaseReplicaInfoBytesReserved

      public void releaseReplicaInfoBytesReserved()
      Description copied from interface: ReplicaInPipeline
      Release the reserved space from the ReplicaInfo.
      Specified by:
      releaseReplicaInfoBytesReserved in interface ReplicaInPipeline
    • setLastChecksumAndDataLen

      public void setLastChecksumAndDataLen(long dataLength, byte[] checksum)
      Description copied from interface: ReplicaInPipeline
      store the checksum for the last chunk along with the data length
      Specified by:
      setLastChecksumAndDataLen in interface ReplicaInPipeline
      Parameters:
      dataLength - number of bytes on disk
      checksum - - checksum bytes for the last chunk
    • getLastChecksumAndDataLen

      public ChunkChecksum getLastChecksumAndDataLen()
      Description copied from interface: ReplicaInPipeline
      gets the last chunk checksum and the length of the block corresponding to that checksum
      Specified by:
      getLastChecksumAndDataLen in interface ReplicaInPipeline
    • waitForMinLength

      public void waitForMinLength(long minLength, long time, TimeUnit unit) throws IOException
      Description copied from interface: ReplicaInPipeline
      Causes the current thread to wait until a minimum length is reached, the thread is interrupted, or the specified waiting time elapses.
      Specified by:
      waitForMinLength in interface ReplicaInPipeline
      Parameters:
      minLength - The minimum length to achieve
      time - the maximum time to wait
      unit - the time unit of the time argument
      Throws:
      IOException - if the current thread is interrupted or the minimum length is not achieved within the time allowed.
    • setWriter

      public void setWriter(Thread writer)
      Description copied from interface: ReplicaInPipeline
      Set the thread that is writing to this replica
      Specified by:
      setWriter in interface ReplicaInPipeline
      Parameters:
      writer - a thread writing to this replica
    • interruptThread

      public void interruptThread()
      Specified by:
      interruptThread in interface ReplicaInPipeline
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class org.apache.hadoop.hdfs.protocol.Block
    • attemptToSetWriter

      public boolean attemptToSetWriter(Thread prevWriter, Thread newWriter)
      Attempt to set the writer to a new value.
      Specified by:
      attemptToSetWriter in interface ReplicaInPipeline
    • stopWriter

      public void stopWriter(long xceiverStopTimeout) throws IOException
      Interrupt the writing thread and wait until it dies.
      Specified by:
      stopWriter in interface ReplicaInPipeline
      Throws:
      IOException - the waiting is interrupted
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class org.apache.hadoop.hdfs.protocol.Block
    • createStreams

      public ReplicaOutputStreams createStreams(boolean isCreate, org.apache.hadoop.util.DataChecksum requestedChecksum) throws IOException
      Description copied from interface: ReplicaInPipeline
      Create output streams for writing to this replica, one for block file and one for CRC file
      Specified by:
      createStreams in interface ReplicaInPipeline
      Parameters:
      isCreate - if it is for creation
      requestedChecksum - the checksum the writer would prefer to use
      Returns:
      output streams for writing
      Throws:
      IOException - if any error occurs
    • createRestartMetaStream

      public OutputStream createRestartMetaStream() throws IOException
      Description copied from interface: ReplicaInPipeline
      Create an output stream to write restart metadata in case of datanode shutting down for quick restart.
      Specified by:
      createRestartMetaStream in interface ReplicaInPipeline
      Returns:
      output stream for writing.
      Throws:
      IOException - if any error occurs
    • toString

      public String toString()
      Overrides:
      toString in class ReplicaInfo
    • getOriginalReplica

      public ReplicaInfo getOriginalReplica()
      Specified by:
      getOriginalReplica in class ReplicaInfo
    • getRecoveryID

      public long getRecoveryID()
      Description copied from class: ReplicaInfo
      Get the recovery id.
      Specified by:
      getRecoveryID in class ReplicaInfo
      Returns:
      the generation stamp that the replica will be bumped to
    • setRecoveryID

      public void setRecoveryID(long recoveryId)
      Description copied from class: ReplicaInfo
      Set the recovery id.
      Specified by:
      setRecoveryID in class ReplicaInfo
      Parameters:
      recoveryId - the new recoveryId
    • createInfo

      public ReplicaRecoveryInfo createInfo()
      Specified by:
      createInfo in class ReplicaInfo
    • moveReplicaFrom

      public void moveReplicaFrom(ReplicaInfo oldReplicaInfo, File newBlkFile) throws IOException
      Throws:
      IOException
    • getReplicaInfo

      public ReplicaInfo getReplicaInfo()
      Specified by:
      getReplicaInfo in interface ReplicaInPipeline