Class LocalReplica
java.lang.Object
org.apache.hadoop.hdfs.protocol.Block
org.apache.hadoop.hdfs.server.datanode.ReplicaInfo
org.apache.hadoop.hdfs.server.datanode.LocalReplica
- 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:
FinalizedReplica,LocalReplicaInPipeline,ReplicaUnderRecovery,ReplicaWaitingToBeRecovered
This class is used for all replicas which are on local storage media
and hence, are backed by files.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.apache.hadoop.hdfs.protocol.Block
BLOCK_FILE_PREFIX, blockFilePattern, METADATA_EXTENSION, metaFilePattern, metaOrBlockFilePattern -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanThis function "breaks hardlinks" to the current replica file.voidbumpReplicaGS(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.voidSync the parent directory changes to durable device.longGet the full path of this replica's data file.Get 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.protected FilegetDir()Return the parent directory path where this replica is located.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.Get the full path of this replica's meta file.booleangetPinning(org.apache.hadoop.fs.LocalFileSystem localFS) Check whether the block was pinned.booleangetPinning(org.apache.hadoop.fs.LocalFileSystem localFS, org.apache.hadoop.fs.Path path) Get pin status of a file by checking the sticky bit.booleanstatic LocalReplica.ReplicaDirInfoparseBaseDir(File dir, long blockId) booleanrenameData(URI destURI) Rename the dataURIto that referenced bydestURI.booleanrenameMeta(URI destURI) Rename the metadataURIto that referenced bydestURI.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.voidsetPinning(org.apache.hadoop.fs.LocalFileSystem localFS, org.apache.hadoop.fs.Path path) Set sticky bit on path to pin file.voidtruncateBlock(long newLength) static voidtruncateBlock(FsVolumeSpi volume, File blockFile, File metaFile, long oldlen, long newlen, FileIoProvider fileIoProvider) voidupdateWithReplica(StorageLocation replicaLocation) Update this replica with theStorageLocationfound.Methods inherited from class org.apache.hadoop.hdfs.server.datanode.ReplicaInfo
createInfo, 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
-
Method Details
-
getBlockFile
Get the full path of this replica's data file.- Returns:
- the full path of this replica's data file
-
getMetaFile
Get the full path of this replica's meta file.- Returns:
- the full path of this replica's meta file
-
getDir
Return the parent directory path where this replica is located.- Returns:
- the parent directory path where this replica is located
-
parseBaseDir
-
breakHardLinksIfNeeded
This function "breaks hardlinks" to the current replica file. When doing a DataNode upgrade, we create a bunch of hardlinks to each block file. This cleverly ensures that both the old and the new storage directories can contain the same block file, without using additional space for the data. However, when we want to append to the replica file, we need to "break" the hardlink to ensure that the old snapshot continues to contain the old data length. If we failed to do that, we could roll back to the previous/ directory during a downgrade, and find that the block contents were longer than they were at the time of upgrade.- Specified by:
breakHardLinksIfNeededin classReplicaInfo- Returns:
- true only if data was copied.
- Throws:
IOException
-
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.
-
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.
-
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.
-
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.
-
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
-
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.
-
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.
-
updateWithReplica
Description copied from class:ReplicaInfoUpdate this replica with theStorageLocationfound.- Specified by:
updateWithReplicain classReplicaInfo- Parameters:
replicaLocation- theStorageLocationfound for this replica.
-
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
-
truncateBlock
- Specified by:
truncateBlockin classReplicaInfo- Throws:
IOException
-
compareWith
- Specified by:
compareWithin classReplicaInfo
-
copyMetadata
- Specified by:
copyMetadatain classReplicaInfo- Throws:
IOException
-
copyBlockdata
- Specified by:
copyBlockdatain classReplicaInfo- Throws:
IOException
-
getPinning
public boolean getPinning(org.apache.hadoop.fs.LocalFileSystem localFS, org.apache.hadoop.fs.Path path) throws IOException Get pin status of a file by checking the sticky bit.- Parameters:
localFS- local file systempath- path to be checked- Returns:
- true if the file is pinned with sticky bit
- Throws:
IOException
-
setPinning
public void setPinning(org.apache.hadoop.fs.LocalFileSystem localFS, org.apache.hadoop.fs.Path path) throws IOException Set sticky bit on path to pin file.- Parameters:
localFS- local file systempath- path to be pinned with sticky bit- Throws:
IOException
-
truncateBlock
public static void truncateBlock(FsVolumeSpi volume, File blockFile, File metaFile, long oldlen, long newlen, FileIoProvider fileIoProvider) throws IOException - Throws:
IOException
-
fsyncDirectory
Sync the parent directory changes to durable device.- Throws:
IOException
-