Class LocalReplicaInPipeline
java.lang.Object
org.apache.hadoop.hdfs.protocol.Block
org.apache.hadoop.hdfs.server.datanode.ReplicaInfo
org.apache.hadoop.hdfs.server.datanode.LocalReplica
org.apache.hadoop.hdfs.server.datanode.LocalReplicaInPipeline
- 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
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.LocalReplica
LocalReplica.ReplicaDirInfo -
Field Summary
Fields inherited from class org.apache.hadoop.hdfs.protocol.Block
BLOCK_FILE_PREFIX, blockFilePattern, METADATA_EXTENSION, metaFilePattern, metaOrBlockFilePattern -
Constructor Summary
ConstructorsConstructorDescriptionLocalReplicaInPipeline(long blockId, long genStamp, FsVolumeSpi vol, File dir, long bytesToReserve) Constructor for a zero length replica.Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanattemptToSetWriter(Thread prevWriter, Thread newWriter) Attempt to set the writer to a new value.Create an output stream to write restart metadata in case of datanode shutting down for quick restart.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 filebooleanlongGet the number of bytes ackedlongGet the number of bytes that have written to disklongNumber of bytes reserved for this replica on disk.gets the last chunk checksum and the length of the block corresponding to that checksumlongNumber of bytes originally reserved for this replica.longGet the recovery id.getState()Get the replica statelongGet the number of bytes that are visible to readersinthashCode()voidvoidmoveReplicaFrom(ReplicaInfo oldReplicaInfo, File newBlkFile) voidRelease any disk space reserved for this replica.voidRelease the reserved space from the ReplicaInfo.voidsetBytesAcked(long bytesAcked) Set the number bytes that have ackedvoidsetLastChecksumAndDataLen(long dataLength, byte[] checksum) store the checksum for the last chunk along with the data lengthvoidsetRecoveryID(long recoveryId) Set the recovery id.voidSet the thread that is writing to this replicavoidstopWriter(long xceiverStopTimeout) Interrupt the writing thread and wait until it dies.toString()voidwaitForMinLength(long minLength, long time, TimeUnit unit) Causes the current thread to wait until a minimum length is reached, the thread is interrupted, or the specified waiting time elapses.Methods inherited from class org.apache.hadoop.hdfs.server.datanode.LocalReplica
blockDataExists, breakHardLinksIfNeeded, bumpReplicaGS, compareWith, copyBlockdata, copyMetadata, deleteBlockData, deleteMetadata, fsyncDirectory, getBlockDataLength, getBlockFile, getBlockURI, getDataInputStream, getDataOutputStream, getDir, getMetadataInputStream, getMetadataLength, getMetadataOutputStream, getMetadataURI, getMetaFile, getPinning, getPinning, metadataExists, parseBaseDir, renameData, renameMeta, setPinning, setPinning, truncateBlock, truncateBlock, updateWithReplicaMethods inherited from class org.apache.hadoop.hdfs.server.datanode.ReplicaInfo
getFileIoProvider, getNext, getStorageUuid, getVolume, isOnTransientStorage, setNextMethods inherited from class org.apache.hadoop.hdfs.protocol.Block
appendStringTo, compareTo, filename2id, getBlockId, getBlockId, getBlockName, getGenerationStamp, getGenerationStamp, getNumBytes, isBlockFilename, isMetaFilename, matchingIdAndGenStamp, metaToBlockFile, readFields, readId, set, setBlockId, setGenerationStamp, setNumBytes, toString, write, writeIdMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.hadoop.hdfs.server.datanode.Replica
getBlockId, getGenerationStamp, getNumBytes, getStorageUuid, getVolume, isOnTransientStorageMethods inherited from interface org.apache.hadoop.hdfs.server.datanode.ReplicaInPipeline
setNumBytes
-
Constructor Details
-
LocalReplicaInPipeline
public LocalReplicaInPipeline(long blockId, long genStamp, FsVolumeSpi vol, File dir, long bytesToReserve) Constructor for a zero length replica.- Parameters:
blockId- block idgenStamp- replica generation stampvol- volume where replica is locateddir- directory path where block and meta files are locatedbytesToReserve- disk space to reserve for this replica, based on the estimated maximum block length.
-
LocalReplicaInPipeline
Copy constructor.- Parameters:
from- where to copy from
-
-
Method Details
-
getVisibleLength
public long getVisibleLength()Description copied from interface:ReplicaGet the number of bytes that are visible to readers- Specified by:
getVisibleLengthin interfaceReplica- Returns:
- the number of bytes that are visible to readers
-
getState
Description copied from interface:ReplicaGet the replica state -
getBytesAcked
public long getBytesAcked()Description copied from interface:ReplicaInPipelineGet the number of bytes acked- Specified by:
getBytesAckedin interfaceReplicaInPipeline- Returns:
- the number of bytes acked
-
setBytesAcked
public void setBytesAcked(long bytesAcked) Description copied from interface:ReplicaInPipelineSet the number bytes that have acked- Specified by:
setBytesAckedin interfaceReplicaInPipeline- Parameters:
bytesAcked- number bytes acked
-
getBytesOnDisk
public long getBytesOnDisk()Description copied from interface:ReplicaGet the number of bytes that have written to disk- Specified by:
getBytesOnDiskin interfaceReplica- Returns:
- the number of bytes that have written to disk
-
getBytesReserved
public long getBytesReserved()Description copied from class:ReplicaInfoNumber of bytes reserved for this replica on disk.- Overrides:
getBytesReservedin classReplicaInfo
-
getOriginalBytesReserved
public long getOriginalBytesReserved()Description copied from class:ReplicaInfoNumber of bytes originally reserved for this replica. The actual reservation is adjusted as data is written to disk.- Overrides:
getOriginalBytesReservedin classReplicaInfo- Returns:
- the number of bytes originally reserved for this replica.
-
releaseAllBytesReserved
public void releaseAllBytesReserved()Description copied from interface:ReplicaInPipelineRelease any disk space reserved for this replica.- Specified by:
releaseAllBytesReservedin interfaceReplicaInPipeline
-
releaseReplicaInfoBytesReserved
public void releaseReplicaInfoBytesReserved()Description copied from interface:ReplicaInPipelineRelease the reserved space from the ReplicaInfo.- Specified by:
releaseReplicaInfoBytesReservedin interfaceReplicaInPipeline
-
setLastChecksumAndDataLen
public void setLastChecksumAndDataLen(long dataLength, byte[] checksum) Description copied from interface:ReplicaInPipelinestore the checksum for the last chunk along with the data length- Specified by:
setLastChecksumAndDataLenin interfaceReplicaInPipeline- Parameters:
dataLength- number of bytes on diskchecksum- - checksum bytes for the last chunk
-
getLastChecksumAndDataLen
Description copied from interface:ReplicaInPipelinegets the last chunk checksum and the length of the block corresponding to that checksum- Specified by:
getLastChecksumAndDataLenin interfaceReplicaInPipeline
-
waitForMinLength
Description copied from interface:ReplicaInPipelineCauses the current thread to wait until a minimum length is reached, the thread is interrupted, or the specified waiting time elapses.- Specified by:
waitForMinLengthin interfaceReplicaInPipeline- Parameters:
minLength- The minimum length to achievetime- the maximum time to waitunit- 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
Description copied from interface:ReplicaInPipelineSet the thread that is writing to this replica- Specified by:
setWriterin interfaceReplicaInPipeline- Parameters:
writer- a thread writing to this replica
-
interruptThread
public void interruptThread()- Specified by:
interruptThreadin interfaceReplicaInPipeline
-
equals
- Overrides:
equalsin classorg.apache.hadoop.hdfs.protocol.Block
-
attemptToSetWriter
Attempt to set the writer to a new value.- Specified by:
attemptToSetWriterin interfaceReplicaInPipeline
-
stopWriter
Interrupt the writing thread and wait until it dies.- Specified by:
stopWriterin interfaceReplicaInPipeline- Throws:
IOException- the waiting is interrupted
-
hashCode
public int hashCode()- Overrides:
hashCodein classorg.apache.hadoop.hdfs.protocol.Block
-
createStreams
public ReplicaOutputStreams createStreams(boolean isCreate, org.apache.hadoop.util.DataChecksum requestedChecksum) throws IOException Description copied from interface:ReplicaInPipelineCreate output streams for writing to this replica, one for block file and one for CRC file- Specified by:
createStreamsin interfaceReplicaInPipeline- Parameters:
isCreate- if it is for creationrequestedChecksum- the checksum the writer would prefer to use- Returns:
- output streams for writing
- Throws:
IOException- if any error occurs
-
createRestartMetaStream
Description copied from interface:ReplicaInPipelineCreate an output stream to write restart metadata in case of datanode shutting down for quick restart.- Specified by:
createRestartMetaStreamin interfaceReplicaInPipeline- Returns:
- output stream for writing.
- Throws:
IOException- if any error occurs
-
toString
- Overrides:
toStringin classReplicaInfo
-
getOriginalReplica
- Specified by:
getOriginalReplicain classReplicaInfo
-
getRecoveryID
public long getRecoveryID()Description copied from class:ReplicaInfoGet the recovery id.- Specified by:
getRecoveryIDin classReplicaInfo- Returns:
- the generation stamp that the replica will be bumped to
-
setRecoveryID
public void setRecoveryID(long recoveryId) Description copied from class:ReplicaInfoSet the recovery id.- Specified by:
setRecoveryIDin classReplicaInfo- Parameters:
recoveryId- the new recoveryId
-
createInfo
- Specified by:
createInfoin classReplicaInfo
-
moveReplicaFrom
- Throws:
IOException
-
getReplicaInfo
- Specified by:
getReplicaInfoin interfaceReplicaInPipeline
-