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.
-
Field Summary
Fields inherited from class org.apache.hadoop.hdfs.protocol.Block
BLOCK_FILE_PREFIX, blockFilePattern, METADATA_EXTENSION, metaFilePattern, metaOrBlockFilePattern -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanabstract booleanabstract voidbumpReplicaGS(long newGS) Bump a replica's generation stamp to a new one.abstract intabstract voidcopyBlockdata(URI destination) abstract voidcopyMetadata(URI destination) abstract ReplicaRecoveryInfoabstract booleanUsed to deletes the replica's block data.abstract booleanUsed to deletes the replica's metadata.abstract longabstract URIGet theURIfor where the data of this replica is stored.longNumber of bytes reserved for this replica on disk.abstract InputStreamgetDataInputStream(long seekOffset) Returns anInputStreamto the replica's data.abstract OutputStreamgetDataOutputStream(boolean append) Returns anOutputStreamto the replica's data.Get theFileIoProviderfor disk IO operations.abstract LengthInputStreamgetMetadataInputStream(long offset) Returns anInputStreamto the replica's metadata.abstract longabstract OutputStreamgetMetadataOutputStream(boolean append) Returns anOutputStreamto the replica's metadata.abstract URIGet theURIfor where the metadata of this replica is stored.org.apache.hadoop.util.LightWeightGSet.LinkedElementgetNext()longNumber of bytes originally reserved for this replica.abstract ReplicaInfoabstract booleangetPinning(org.apache.hadoop.fs.LocalFileSystem localFS) Check whether the block was pinned.abstract longGet the recovery id.Get the storageUuid of the volume that stores this replica.Get the volume of replica.booleanReturn true if the target volume is backed by RAM.abstract booleanabstract booleanrenameData(URI destURI) Rename the dataURIto that referenced bydestURI.abstract booleanrenameMeta(URI destURI) Rename the metadataURIto that referenced bydestURI.voidsetNext(org.apache.hadoop.util.LightWeightGSet.LinkedElement next) abstract voidsetPinning(org.apache.hadoop.fs.LocalFileSystem localFS) Set a block to be pinned on this datanode so that it cannot be moved by Balancer/Mover.abstract voidsetRecoveryID(long recoveryId) Set the recovery id.toString()abstract voidtruncateBlock(long newLength) abstract voidupdateWithReplica(StorageLocation replicaLocation) Update this replica with theStorageLocationfound.Methods inherited from class org.apache.hadoop.hdfs.protocol.Block
appendStringTo, compareTo, equals, filename2id, getBlockId, getBlockId, getBlockName, getGenerationStamp, getGenerationStamp, getNumBytes, hashCode, 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, getBytesOnDisk, getGenerationStamp, getNumBytes, getState, getVisibleLength
-
Method Details
-
getVolume
Description copied from interface:ReplicaGet the volume of replica. -
getFileIoProvider
Get theFileIoProviderfor disk IO operations. -
getStorageUuid
Get the storageUuid of the volume that stores this replica.- Specified by:
getStorageUuidin interfaceReplica
-
getBytesReserved
public long getBytesReserved()Number of bytes reserved for this replica on disk. -
getBlockURI
Get theURIfor where the data of this replica is stored.- Returns:
URIfor the location of replica data.
-
getDataInputStream
Returns anInputStreamto the replica's data.- Parameters:
seekOffset- the offset at which the read is started from.- Returns:
- the
InputStreamto read the replica data. - Throws:
IOException- if an error occurs in opening a stream to the data.
-
getDataOutputStream
Returns anOutputStreamto the replica's data.- Parameters:
append- indicates if the block should be opened for append.- Returns:
- the
OutputStreamto write to the replica. - Throws:
IOException- if an error occurs in creating anOutputStream.
-
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
Get theURIfor where the metadata of this replica is stored.- Returns:
URIfor the location of replica metadata.
-
getMetadataInputStream
Returns anInputStreamto the replica's metadata.- Parameters:
offset- the offset at which the read is started from.- Returns:
- the
LengthInputStreamto read the replica metadata. - Throws:
IOException
-
getMetadataOutputStream
Returns anOutputStreamto the replica's metadata.- Parameters:
append- indicates if the block metadata should be opened for append.- Returns:
- the
OutputStreamto write to the replica's metadata. - Throws:
IOException- if an error occurs in creating anOutputStream.
-
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
Rename the metadataURIto that referenced bydestURI.- Parameters:
destURI- the targetURI.- Returns:
- true if the rename is successful.
- Throws:
IOException- if an exception occurs in the rename.
-
renameData
Rename the dataURIto that referenced bydestURI.- Parameters:
destURI- the targetURI.- Returns:
- true if the rename is successful.
- Throws:
IOException- if an exception occurs in the rename.
-
updateWithReplica
Update this replica with theStorageLocationfound.- Parameters:
replicaLocation- theStorageLocationfound for this replica.
-
getPinning
Check whether the block was pinned.- Parameters:
localFS- the local filesystem to use.- Returns:
- true if the block is pinned.
- Throws:
IOException
-
setPinning
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
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
-
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
- Throws:
IOException
-
createInfo
-
compareWith
-
truncateBlock
- Throws:
IOException
-
copyMetadata
- Throws:
IOException
-
copyBlockdata
- 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
- Overrides:
toStringin classorg.apache.hadoop.hdfs.protocol.Block
-
isOnTransientStorage
public boolean isOnTransientStorage()Description copied from interface:ReplicaReturn true if the target volume is backed by RAM.- Specified by:
isOnTransientStoragein interfaceReplica
-
getNext
public org.apache.hadoop.util.LightWeightGSet.LinkedElement getNext()- Specified by:
getNextin interfaceorg.apache.hadoop.util.LightWeightGSet.LinkedElement
-
setNext
public void setNext(org.apache.hadoop.util.LightWeightGSet.LinkedElement next) - Specified by:
setNextin interfaceorg.apache.hadoop.util.LightWeightGSet.LinkedElement
-