Class ProvidedReplica
java.lang.Object
org.apache.hadoop.hdfs.protocol.Block
org.apache.hadoop.hdfs.server.datanode.ReplicaInfo
org.apache.hadoop.hdfs.server.datanode.ProvidedReplica
- 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:
FinalizedProvidedReplica
This abstract class is used as a base class for provided replicas.
-
Field Summary
FieldsFields inherited from class org.apache.hadoop.hdfs.protocol.Block
BLOCK_FILE_PREFIX, blockFilePattern, METADATA_EXTENSION, metaFilePattern, metaOrBlockFilePattern -
Constructor Summary
ConstructorsConstructorDescriptionProvidedReplica(long blockId, URI fileURI, long fileOffset, long blockLen, long genStamp, org.apache.hadoop.fs.PathHandle pathHandle, FsVolumeSpi volume, org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem remoteFS) Constructor.ProvidedReplica(long blockId, org.apache.hadoop.fs.Path pathPrefix, String pathSuffix, long fileOffset, long blockLen, long genStamp, org.apache.hadoop.fs.PathHandle pathHandle, FsVolumeSpi volume, org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem remoteFS) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanvoidbumpReplicaGS(long newGS) Bump a replica's generation stamp to a new one.intvoidcopyBlockdata(URI destination) voidcopyMetadata(URI destination) booleanUsed to deletes the replica's block data.booleanUsed to deletes the replica's metadata.longGet theURIfor where the data of this replica is stored.getDataInputStream(long seekOffset) Returns anInputStreamto the replica's data.getDataOutputStream(boolean append) Returns anOutputStreamto the replica's data.getMetadataInputStream(long offset) Returns anInputStreamto the replica's metadata.longgetMetadataOutputStream(boolean append) Returns anOutputStreamto the replica's metadata.Get theURIfor where the metadata of this replica is stored.org.apache.hadoop.fs.PathbooleangetPinning(org.apache.hadoop.fs.LocalFileSystem localFS) Check whether the block was pinned.booleanbooleanrenameData(URI destURI) Rename the dataURIto that referenced bydestURI.booleanrenameMeta(URI destURI) Rename the metadataURIto that referenced bydestURI.voidsetPathHandle(org.apache.hadoop.fs.PathHandle pathHandle) 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.voidtruncateBlock(long newLength) voidupdateWithReplica(StorageLocation replicaLocation) Update this replica with theStorageLocationfound.Methods inherited from class org.apache.hadoop.hdfs.server.datanode.ReplicaInfo
getBytesReserved, getFileIoProvider, getNext, getOriginalBytesReserved, getOriginalReplica, getRecoveryID, getStorageUuid, getVolume, isOnTransientStorage, setNext, setRecoveryID, toStringMethods 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
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG
-
-
Constructor Details
-
ProvidedReplica
public ProvidedReplica(long blockId, URI fileURI, long fileOffset, long blockLen, long genStamp, org.apache.hadoop.fs.PathHandle pathHandle, FsVolumeSpi volume, org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem remoteFS) Constructor.- Parameters:
blockId- block idfileURI- remote URI this block is to be read fromfileOffset- the offset in the remote URIblockLen- the length of the blockgenStamp- the generation stamp of the blockvolume- the volume this block belongs toconf- the configurationremoteFS- reference to the remote filesystem to use for this replica.
-
ProvidedReplica
public ProvidedReplica(long blockId, org.apache.hadoop.fs.Path pathPrefix, String pathSuffix, long fileOffset, long blockLen, long genStamp, org.apache.hadoop.fs.PathHandle pathHandle, FsVolumeSpi volume, org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem remoteFS) Constructor.- Parameters:
blockId- block idpathPrefix- A prefix of thePathassociated with this replica on the remoteFileSystem.pathSuffix- A suffix of thePathassociated with this replica on the remoteFileSystem. Resolving thepathSuffixagainst thepathPrefixshould provide the exactPathof the data associated with this replica on the remoteFileSystem.fileOffset- the offset in the remote URIblockLen- the length of the blockgenStamp- the generation stamp of the blockvolume- the volume this block belongs toconf- the configurationremoteFS- reference to the remote filesystem to use for this replica.
-
ProvidedReplica
-
-
Method Details
-
getBlockURI
Description copied from class:ReplicaInfoGet theURIfor where the data of this replica is stored.- Specified by:
getBlockURIin classReplicaInfo- Returns:
URIfor the location of replica data.
-
getPathSuffix
-
getPathPrefix
@VisibleForTesting public org.apache.hadoop.fs.Path getPathPrefix() -
getDataInputStream
Description copied from class:ReplicaInfoReturns anInputStreamto the replica's data.- Specified by:
getDataInputStreamin classReplicaInfo- 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
Description copied from class:ReplicaInfoReturns anOutputStreamto the replica's data.- Specified by:
getDataOutputStreamin classReplicaInfo- 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.
-
getMetadataURI
Description copied from class:ReplicaInfoGet theURIfor where the metadata of this replica is stored.- Specified by:
getMetadataURIin classReplicaInfo- Returns:
URIfor the location of replica metadata.
-
getMetadataOutputStream
Description copied from class:ReplicaInfoReturns anOutputStreamto the replica's metadata.- Specified by:
getMetadataOutputStreamin classReplicaInfo- 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.
-
blockDataExists
public boolean blockDataExists()- Specified by:
blockDataExistsin classReplicaInfo- Returns:
- true if the replica's data exists.
-
deleteBlockData
public boolean deleteBlockData()Description copied from class:ReplicaInfoUsed to deletes the replica's block data.- Specified by:
deleteBlockDatain classReplicaInfo- Returns:
- true if the replica's data is successfully deleted.
-
getBlockDataLength
public long getBlockDataLength()- Specified by:
getBlockDataLengthin classReplicaInfo- Returns:
- the length of the block on storage.
-
getMetadataInputStream
Description copied from class:ReplicaInfoReturns anInputStreamto the replica's metadata.- Specified by:
getMetadataInputStreamin classReplicaInfo- Parameters:
offset- the offset at which the read is started from.- Returns:
- the
LengthInputStreamto read the replica metadata. - Throws:
IOException
-
metadataExists
public boolean metadataExists()- Specified by:
metadataExistsin classReplicaInfo- Returns:
- true if the replica's metadata exists.
-
deleteMetadata
public boolean deleteMetadata()Description copied from class:ReplicaInfoUsed to deletes the replica's metadata.- Specified by:
deleteMetadatain classReplicaInfo- Returns:
- true if the replica's metadata is successfully deleted.
-
getMetadataLength
public long getMetadataLength()- Specified by:
getMetadataLengthin classReplicaInfo- Returns:
- the length of the metadata on storage.
-
renameMeta
Description copied from class:ReplicaInfoRename the metadataURIto that referenced bydestURI.- Specified by:
renameMetain classReplicaInfo- Parameters:
destURI- the targetURI.- Returns:
- true if the rename is successful.
- Throws:
IOException- if an exception occurs in the rename.
-
renameData
Description copied from class:ReplicaInfoRename the dataURIto that referenced bydestURI.- Specified by:
renameDatain classReplicaInfo- Parameters:
destURI- the targetURI.- Returns:
- true if the rename is successful.
- Throws:
IOException- if an exception occurs in the rename.
-
getPinning
Description copied from class:ReplicaInfoCheck whether the block was pinned.- Specified by:
getPinningin classReplicaInfo- Parameters:
localFS- the local filesystem to use.- Returns:
- true if the block is pinned.
- Throws:
IOException
-
setPinning
Description copied from class:ReplicaInfoSet a block to be pinned on this datanode so that it cannot be moved by Balancer/Mover.- Specified by:
setPinningin classReplicaInfo- Parameters:
localFS- the local filesystem to use.- Throws:
IOException- if there is an exception in the pinning.
-
bumpReplicaGS
Description copied from class:ReplicaInfoBump a replica's generation stamp to a new one. Its on-disk meta file name is renamed to be the new one too.- Specified by:
bumpReplicaGSin classReplicaInfo- Parameters:
newGS- new generation stamp- Throws:
IOException- if the change fails
-
breakHardLinksIfNeeded
- Specified by:
breakHardLinksIfNeededin classReplicaInfo- Throws:
IOException
-
createInfo
- Specified by:
createInfoin classReplicaInfo- Throws:
UnsupportedOperationException
-
compareWith
- Specified by:
compareWithin classReplicaInfo
-
truncateBlock
- Specified by:
truncateBlockin classReplicaInfo- Throws:
IOException
-
updateWithReplica
Description copied from class:ReplicaInfoUpdate this replica with theStorageLocationfound.- Specified by:
updateWithReplicain classReplicaInfo- Parameters:
replicaLocation- theStorageLocationfound for this replica.
-
copyMetadata
- Specified by:
copyMetadatain classReplicaInfo- Throws:
IOException
-
copyBlockdata
- Specified by:
copyBlockdatain classReplicaInfo- Throws:
IOException
-
setPathHandle
@VisibleForTesting public void setPathHandle(org.apache.hadoop.fs.PathHandle pathHandle)
-