org.apache.hadoop.hdfs.server.datanode
Class ReplicaInPipeline

java.lang.Object
  extended by org.apache.hadoop.hdfs.protocol.Block
      extended by org.apache.hadoop.hdfs.server.datanode.ReplicaInfo
          extended by org.apache.hadoop.hdfs.server.datanode.ReplicaInPipeline
All Implemented Interfaces:
Comparable<org.apache.hadoop.hdfs.protocol.Block>, org.apache.hadoop.hdfs.server.datanode.Replica, ReplicaInPipelineInterface, org.apache.hadoop.io.Writable
Direct Known Subclasses:
ReplicaBeingWritten

public class ReplicaInPipeline
extends org.apache.hadoop.hdfs.server.datanode.ReplicaInfo
implements ReplicaInPipelineInterface

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


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.hadoop.hdfs.server.datanode.ReplicaInfo
ReplicaInfo.ReplicaDirInfo
 
Field Summary
 
Fields inherited from class org.apache.hadoop.hdfs.protocol.Block
BLOCK_FILE_PREFIX, blockFilePattern, METADATA_EXTENSION, metaFilePattern
 
Constructor Summary
ReplicaInPipeline(long blockId, long genStamp, FsVolumeSpi vol, File dir)
          Constructor for a zero length replica
ReplicaInPipeline(ReplicaInPipeline from)
          Copy constructor.
 
Method Summary
 ReplicaOutputStreams createStreams(boolean isCreate, org.apache.hadoop.util.DataChecksum requestedChecksum)
          Create output streams for writing to this replica, one for block file and one for CRC file
 boolean equals(Object o)
           
 long getBytesAcked()
          Get the number of bytes acked
 long getBytesOnDisk()
          Get the number of bytes that have written to disk
 org.apache.hadoop.hdfs.server.datanode.ChunkChecksum getLastChecksumAndDataLen()
          gets the last chunk checksum and the length of the block corresponding to that checksum
 HdfsServerConstants.ReplicaState getState()
          Get the replica state
 long getVisibleLength()
          Get the number of bytes that are visible to readers
 int hashCode()
           
 void setBytesAcked(long bytesAcked)
          Set the number bytes that have acked
 void setLastChecksumAndDataLen(long dataLength, byte[] lastChecksum)
          store the checksum for the last chunk along with the data length
 void setWriter(Thread writer)
          Set the thread that is writing to this replica
 void stopWriter(long xceiverStopTimeout)
          Interrupt the writing thread and wait until it dies
 String toString()
           
 
Methods inherited from class org.apache.hadoop.hdfs.server.datanode.ReplicaInfo
getBlockFile, getMetaFile, getVolume, isUnlinked, parseSubDirs, setDir, setUnlinked, unlinkBlock
 
Methods inherited from class org.apache.hadoop.hdfs.protocol.Block
appendStringTo, compareTo, filename2id, getBlockId, getBlockId, getBlockName, getGenerationStamp, getGenerationStamp, getNumBytes, isBlockFilename, isMetaFilename, matchingIdAndGenStamp, readFields, readId, set, setBlockId, setGenerationStamp, setNumBytes, write, writeId
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.hadoop.hdfs.server.datanode.ReplicaInPipelineInterface
setNumBytes
 
Methods inherited from interface org.apache.hadoop.hdfs.server.datanode.Replica
getBlockId, getGenerationStamp, getNumBytes
 

Constructor Detail

ReplicaInPipeline

public ReplicaInPipeline(long blockId,
                         long genStamp,
                         FsVolumeSpi vol,
                         File dir)
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

ReplicaInPipeline

public ReplicaInPipeline(ReplicaInPipeline from)
Copy constructor.

Parameters:
from -
Method Detail

getVisibleLength

public long getVisibleLength()
Description copied from interface: org.apache.hadoop.hdfs.server.datanode.Replica
Get the number of bytes that are visible to readers

Specified by:
getVisibleLength in interface org.apache.hadoop.hdfs.server.datanode.Replica
Returns:
the number of bytes that are visible to readers

getState

public HdfsServerConstants.ReplicaState getState()
Description copied from interface: org.apache.hadoop.hdfs.server.datanode.Replica
Get the replica state

Specified by:
getState in interface org.apache.hadoop.hdfs.server.datanode.Replica
Returns:
the replica state

getBytesAcked

public long getBytesAcked()
Description copied from interface: ReplicaInPipelineInterface
Get the number of bytes acked

Specified by:
getBytesAcked in interface ReplicaInPipelineInterface
Returns:
the number of bytes acked

setBytesAcked

public void setBytesAcked(long bytesAcked)
Description copied from interface: ReplicaInPipelineInterface
Set the number bytes that have acked

Specified by:
setBytesAcked in interface ReplicaInPipelineInterface

getBytesOnDisk

public long getBytesOnDisk()
Description copied from interface: org.apache.hadoop.hdfs.server.datanode.Replica
Get the number of bytes that have written to disk

Specified by:
getBytesOnDisk in interface org.apache.hadoop.hdfs.server.datanode.Replica
Returns:
the number of bytes that have written to disk

setLastChecksumAndDataLen

public void setLastChecksumAndDataLen(long dataLength,
                                      byte[] lastChecksum)
Description copied from interface: ReplicaInPipelineInterface
store the checksum for the last chunk along with the data length

Specified by:
setLastChecksumAndDataLen in interface ReplicaInPipelineInterface
Parameters:
dataLength - number of bytes on disk
lastChecksum - - checksum bytes for the last chunk

getLastChecksumAndDataLen

public org.apache.hadoop.hdfs.server.datanode.ChunkChecksum getLastChecksumAndDataLen()
Description copied from interface: ReplicaInPipelineInterface
gets the last chunk checksum and the length of the block corresponding to that checksum

Specified by:
getLastChecksumAndDataLen in interface ReplicaInPipelineInterface

setWriter

public void setWriter(Thread writer)
Set the thread that is writing to this replica

Parameters:
writer - a thread writing to this replica

equals

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

stopWriter

public void stopWriter(long xceiverStopTimeout)
                throws IOException
Interrupt the writing thread and wait until it dies

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: ReplicaInPipelineInterface
Create output streams for writing to this replica, one for block file and one for CRC file

Specified by:
createStreams in interface ReplicaInPipelineInterface
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

toString

public String toString()
Overrides:
toString in class org.apache.hadoop.hdfs.server.datanode.ReplicaInfo


Copyright © 2013 Apache Software Foundation. All Rights Reserved.