Interface FsDatasetSpi<V extends FsVolumeSpi>
- All Superinterfaces:
FSDatasetMBean,org.apache.hadoop.metrics2.MetricsSource
This is a service provider interface for the underlying storage that
stores replicas for a data node.
The default implementation stores replicas on local drives.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classFsDatasetSpi.Factory<D extends FsDatasetSpi<?>>A factory for creatingFsDatasetSpiobjects.static classIt behaviors as an unmodifiable list of FsVolume. -
Method Summary
Modifier and TypeMethodDescriptionDataNodeLockManager<? extends AutoCloseDataSetLock>Acquire lock Manager for the data set.voidaddBlockPool(String bpid, org.apache.hadoop.conf.Configuration conf) add new block pool IDvoidaddVolume(StorageLocation location, List<NamespaceInfo> nsInfos) Add a new volume to the FsDataset.voidadjustCrcChannelPosition(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, ReplicaOutputStreams outs, int checksumSize) Sets the file pointer of the checksum stream so that the last checksum will be overwrittenappend(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, long newGS, long expectedBlockLen) Append to a finalized replica and returns the meta info of the replica.voidCaches the specified blockvoidcheckAndUpdate(String bpid, FsVolumeSpi.ScanInfo info) Check whether the in-memory block record matches the block on the disk, and, in case that they are not matched, update the record or mark it as corrupted.voidcheckBlock(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, long minLength, HdfsServerConstants.ReplicaState state) Check if a block is valid.voidDelete the rolling upgrade marker file if it exists.voidclearTrash(String bpid) Clear trashbooleancontains(org.apache.hadoop.hdfs.protocol.ExtendedBlock block) Does the dataset contain the block?convertTemporaryToRbw(org.apache.hadoop.hdfs.protocol.ExtendedBlock temporary) Covert a temporary replica to a RBW.createRbw(org.apache.hadoop.fs.StorageType storageType, String storageId, org.apache.hadoop.hdfs.protocol.ExtendedBlock b, boolean allowLazyPersist) Creates a RBW replica and returns the meta info of the replicacreateRbw(org.apache.hadoop.fs.StorageType storageType, String storageId, org.apache.hadoop.hdfs.protocol.ExtendedBlock b, boolean allowLazyPersist, long newGS) Creates a RBW replica and returns the meta info of the replicacreateTemporary(org.apache.hadoop.fs.StorageType storageType, String storageId, org.apache.hadoop.hdfs.protocol.ExtendedBlock b, boolean isTransfer) Creates a temporary replica and returns the meta information of the replica .deepCopyReplica(String bpid) Deep copy the replica info belonging to given block pool.voiddeleteBlockPool(String bpid, boolean force) Deletes the block pool directories.voidenableTrash(String bpid) Enable 'trash' for the given dataset.voidfinalizeBlock(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, boolean fsyncDir) Finalizes the block previously opened for writing using writeToBlock.getBlockInputStream(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, long seekOffset) Returns an input stream at specified offset of the specified block.org.apache.hadoop.hdfs.protocol.BlockLocalPathInfogetBlockLocalPathInfo(org.apache.hadoop.hdfs.protocol.ExtendedBlock b) GetBlockLocalPathInfofor the given block.Map<org.apache.hadoop.hdfs.server.protocol.DatanodeStorage,BlockListAsLongs> getBlockReports(String bpid) Returns one block report per volume.getCacheReport(String bpid) Returns the cache report - the full list of cached block IDs of a block pool.getFinalizedBlocks(String bpid) Gets a list of references to the finalized blocks for the given block pool.Returns a list of FsVolumes that hold reference counts.longgetLength(org.apache.hadoop.hdfs.protocol.ExtendedBlock b) Returns the specified block's on-disk length (excluding metadata).getMetaDataInputStream(org.apache.hadoop.hdfs.protocol.ExtendedBlock b) Get relationship between disk mount and FsVolume.booleangetPinning(org.apache.hadoop.hdfs.protocol.ExtendedBlock block) Check whether the block was pinnedgetReplica(String bpid, long blockId) Deprecated.getReplicaString(String bpid, long blockId) longgetReplicaVisibleLength(org.apache.hadoop.hdfs.protocol.ExtendedBlock block) Get visible length of the specified replica.org.apache.hadoop.hdfs.server.protocol.DatanodeStoragegetStorage(String storageUuid) org.apache.hadoop.hdfs.server.protocol.StorageReport[]getStorageReports(String bpid) org.apache.hadoop.hdfs.protocol.BlockgetStoredBlock(String bpid, long blkid) getTmpInputStreams(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, long blkoff, long ckoff) Returns an input stream at specified offset of the specified block.getVolume(org.apache.hadoop.hdfs.protocol.ExtendedBlock b) Returns info about volume failures.Get the volume list.voidhandleVolumeFailures(Set<FsVolumeSpi> failedVolumes) Check if all the data directories are healthybooleanChecks how many valid storage volumes there are in the DataNode.Initialize a replica recovery.voidinvalidate(String bpid, org.apache.hadoop.hdfs.protocol.Block[] invalidBlks) Invalidates the specified blocks.voidinvalidateMissingBlock(String bpid, org.apache.hadoop.hdfs.protocol.Block block) Invalidate a block which is not found on disk.booleanDetermine if the specified block is cached.booleanisDeletingBlock(String bpid, long blockId) Confirm whether the block is deletingbooleanisValidBlock(org.apache.hadoop.hdfs.protocol.ExtendedBlock b) Is the block valid?booleanisValidRbw(org.apache.hadoop.hdfs.protocol.ExtendedBlock b) Is the block a valid RBW?moveBlockAcrossStorage(org.apache.hadoop.hdfs.protocol.ExtendedBlock block, org.apache.hadoop.fs.StorageType targetStorageType, String storageId) Move block from one storage to another storagemoveBlockAcrossVolumes(org.apache.hadoop.hdfs.protocol.ExtendedBlock block, FsVolumeSpi destination) Moves a given block from one volume to another volume.voidonCompleteLazyPersist(String bpId, long blockId, long creationTime, File[] savedFiles, V targetVolume) Callback from RamDiskAsyncLazyPersistService upon async lazy persist task endvoidonFailLazyPersist(String bpId, long blockId) Callback from RamDiskAsyncLazyPersistService upon async lazy persist task failrecoverAppend(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, long newGS, long expectedBlockLen) Recover a failed append to a finalized replica and returns the meta info of the replica.recoverClose(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, long newGS, long expectedBlockLen) Recover a failed pipeline close.recoverRbw(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, long newGS, long minBytesRcvd, long maxBytesRcvd) Recovers a RBW replica and returns the meta info of the replica.voidremoveVolumes(Collection<StorageLocation> volumes, boolean clearFailure) Removes a collection of volumes from FsDataset.default voidsetLastDirScannerFinishTime(long time) Set the last time in milliseconds when the directory scanner successfully ran.voidsetPinning(org.apache.hadoop.hdfs.protocol.ExtendedBlock block) Set a block to be pinned on this datanode so that it cannot be moved by Balancer/Mover.voidCreate a marker file indicating that a rolling upgrade is in progress.voidshutdown()Shutdown the FSDatasetvoidshutdownBlockPool(String bpid) Shutdown and remove the block pool from underlying storage.voidsubmitBackgroundSyncFileRangeRequest(org.apache.hadoop.hdfs.protocol.ExtendedBlock block, ReplicaOutputStreams outs, long offset, long nbytes, int flags) submit a sync_file_range request to AsyncDiskService.booleantrashEnabled(String bpid) voidUncaches the specified blocksvoidunfinalizeBlock(org.apache.hadoop.hdfs.protocol.ExtendedBlock b) Unfinalizes the block previously opened for writing using writeToBlock.updateReplicaUnderRecovery(org.apache.hadoop.hdfs.protocol.ExtendedBlock oldBlock, long recoveryId, long newBlockId, long newLength) Update replica's generation stamp and length and finalize it.Methods inherited from interface org.apache.hadoop.hdfs.server.datanode.metrics.FSDatasetMBean
getBlockPoolUsed, getCacheCapacity, getCacheUsed, getCapacity, getDfsUsed, getEstimatedCapacityLostTotal, getFailedStorageLocations, getLastDirScannerFinishTime, getLastVolumeFailureDate, getNumBlocksCached, getNumBlocksFailedToCache, getNumBlocksFailedToUncache, getNumFailedVolumes, getPendingAsyncDeletions, getRemaining, getStorageInfoMethods inherited from interface org.apache.hadoop.metrics2.MetricsSource
getMetrics
-
Method Details
-
getFsVolumeReferences
FsDatasetSpi.FsVolumeReferences getFsVolumeReferences()Returns a list of FsVolumes that hold reference counts. The caller must release the reference of each volume by callingFsDatasetSpi.FsVolumeReferences.close(). -
addVolume
Add a new volume to the FsDataset. If the FSDataset supports block scanning, this function registers the new volume with the block scanner.- Parameters:
location- The storage location for the new volume.nsInfos- Namespace information for the new volume.- Throws:
IOException
-
removeVolumes
Removes a collection of volumes from FsDataset. If the FSDataset supports block scanning, this function removes the volumes from the block scanner.- Parameters:
volumes- The paths of the volumes to be removed.clearFailure- set true to clear the failure information about the volumes.
-
getStorage
- Returns:
- a storage with the given storage ID
-
getStorageReports
org.apache.hadoop.hdfs.server.protocol.StorageReport[] getStorageReports(String bpid) throws IOException - Returns:
- one or more storage reports for attached volumes.
- Throws:
IOException
-
getVolume
- Returns:
- the volume that contains a replica of the block.
-
getVolumeInfoMap
- Returns:
- a volume information map (name => info).
-
getVolumeFailureSummary
VolumeFailureSummary getVolumeFailureSummary()Returns info about volume failures.- Returns:
- info about volume failures, possibly null
-
getFinalizedBlocks
Gets a list of references to the finalized blocks for the given block pool.Callers of this function should call
acquireDatasetLockManager()to avoid blocks' status being changed during list iteration.- Returns:
- a list of references to the finalized blocks for the given block pool.
-
checkAndUpdate
Check whether the in-memory block record matches the block on the disk, and, in case that they are not matched, update the record or mark it as corrupted.- Throws:
IOException
-
getMetaDataInputStream
LengthInputStream getMetaDataInputStream(org.apache.hadoop.hdfs.protocol.ExtendedBlock b) throws IOException - Parameters:
b- - the block- Returns:
- a stream if the meta-data of the block exists; otherwise, return null.
- Throws:
IOException
-
getLength
Returns the specified block's on-disk length (excluding metadata).- Returns:
- the specified block's on-disk length (excluding metadta)
- Throws:
IOException- on error
-
getReplica
Deprecated.Get reference to the replica meta info in the replicasMap. To be called from methods that are synchronized on implementations ofFsDatasetSpi- Returns:
- replica from the replicas map
-
getReplicaString
- Returns:
- replica meta information
-
getStoredBlock
- Returns:
- the generation stamp stored with the block.
- Throws:
IOException
-
getBlockInputStream
InputStream getBlockInputStream(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, long seekOffset) throws IOException Returns an input stream at specified offset of the specified block.- Parameters:
b- blockseekOffset- offset with in the block to seek to- Returns:
- an input stream to read the contents of the specified block, starting at the offset
- Throws:
IOException
-
getTmpInputStreams
ReplicaInputStreams getTmpInputStreams(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, long blkoff, long ckoff) throws IOException Returns an input stream at specified offset of the specified block. The block is still in the tmp directory and is not finalized- Returns:
- an input stream to read the contents of the specified block, starting at the offset
- Throws:
IOException
-
createTemporary
ReplicaHandler createTemporary(org.apache.hadoop.fs.StorageType storageType, String storageId, org.apache.hadoop.hdfs.protocol.ExtendedBlock b, boolean isTransfer) throws IOException Creates a temporary replica and returns the meta information of the replica .- Parameters:
b- block- Returns:
- the meta info of the replica which is being written to
- Throws:
IOException- if an error occurs
-
createRbw
ReplicaHandler createRbw(org.apache.hadoop.fs.StorageType storageType, String storageId, org.apache.hadoop.hdfs.protocol.ExtendedBlock b, boolean allowLazyPersist) throws IOException Creates a RBW replica and returns the meta info of the replica- Parameters:
b- block- Returns:
- the meta info of the replica which is being written to
- Throws:
IOException- if an error occurs
-
createRbw
ReplicaHandler createRbw(org.apache.hadoop.fs.StorageType storageType, String storageId, org.apache.hadoop.hdfs.protocol.ExtendedBlock b, boolean allowLazyPersist, long newGS) throws IOException Creates a RBW replica and returns the meta info of the replica- Parameters:
b- block- Returns:
- the meta info of the replica which is being written to
- Throws:
IOException- if an error occurs
-
recoverRbw
ReplicaHandler recoverRbw(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, long newGS, long minBytesRcvd, long maxBytesRcvd) throws IOException Recovers a RBW replica and returns the meta info of the replica.- Parameters:
b- blocknewGS- the new generation stamp for the replicaminBytesRcvd- the minimum number of bytes that the replica could havemaxBytesRcvd- the maximum number of bytes that the replica could have- Returns:
- the meta info of the replica which is being written to
- Throws:
IOException- if an error occurs
-
convertTemporaryToRbw
ReplicaInPipeline convertTemporaryToRbw(org.apache.hadoop.hdfs.protocol.ExtendedBlock temporary) throws IOException Covert a temporary replica to a RBW.- Parameters:
temporary- the temporary replica being converted- Returns:
- the result RBW
- Throws:
IOException
-
append
ReplicaHandler append(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, long newGS, long expectedBlockLen) throws IOException Append to a finalized replica and returns the meta info of the replica.- Parameters:
b- blocknewGS- the new generation stamp for the replicaexpectedBlockLen- the number of bytes the replica is expected to have- Returns:
- the meata info of the replica which is being written to
- Throws:
IOException
-
recoverAppend
ReplicaHandler recoverAppend(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, long newGS, long expectedBlockLen) throws IOException Recover a failed append to a finalized replica and returns the meta info of the replica.- Parameters:
b- blocknewGS- the new generation stamp for the replicaexpectedBlockLen- the number of bytes the replica is expected to have- Returns:
- the meta info of the replica which is being written to
- Throws:
IOException
-
recoverClose
Replica recoverClose(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, long newGS, long expectedBlockLen) throws IOException Recover a failed pipeline close. It bumps the replica's generation stamp and finalize it if RBW replica- Parameters:
b- blocknewGS- the new generation stamp for the replicaexpectedBlockLen- the number of bytes the replica is expected to have- Returns:
- the storage uuid of the replica.
- Throws:
IOException
-
finalizeBlock
void finalizeBlock(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, boolean fsyncDir) throws IOException Finalizes the block previously opened for writing using writeToBlock. The block size is what is in the parameter b and it must match the amount of data written- Parameters:
b- Block to be finalizedfsyncDir- whether to sync the directory changes to durable device.- Throws:
IOExceptionorg.apache.hadoop.hdfs.server.datanode.ReplicaNotFoundException- if the replica can not be found when the block is been finalized. For instance, the block resides on an HDFS volume that has been removed.
-
unfinalizeBlock
Unfinalizes the block previously opened for writing using writeToBlock. The temporary file associated with this block is deleted.- Throws:
IOException
-
getBlockReports
Map<org.apache.hadoop.hdfs.server.protocol.DatanodeStorage,BlockListAsLongs> getBlockReports(String bpid) Returns one block report per volume.- Parameters:
bpid- Block Pool Id- Returns:
- - a map of DatanodeStorage to block report for the volume.
-
getCacheReport
Returns the cache report - the full list of cached block IDs of a block pool.- Parameters:
bpid- Block Pool Id- Returns:
- the cache report - the full list of cached block IDs.
-
contains
boolean contains(org.apache.hadoop.hdfs.protocol.ExtendedBlock block) Does the dataset contain the block? -
checkBlock
void checkBlock(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, long minLength, HdfsServerConstants.ReplicaState state) throws org.apache.hadoop.hdfs.server.datanode.ReplicaNotFoundException, UnexpectedReplicaStateException, FileNotFoundException, EOFException, IOException Check if a block is valid.- Parameters:
b- The block to check.minLength- The minimum length that the block must have. May be 0.state- If this is null, it is ignored. If it is non-null, we will check that the replica has this state.- Throws:
org.apache.hadoop.hdfs.server.datanode.ReplicaNotFoundException- If the replica is not foundUnexpectedReplicaStateException- If the replica is not in the expected state.FileNotFoundException- If the block file is not found or there was an error locating it.EOFException- If the replica length is too short.IOException- May be thrown from the methods called.
-
isValidBlock
boolean isValidBlock(org.apache.hadoop.hdfs.protocol.ExtendedBlock b) Is the block valid?- Returns:
- - true if the specified block is valid
-
isValidRbw
boolean isValidRbw(org.apache.hadoop.hdfs.protocol.ExtendedBlock b) Is the block a valid RBW?- Returns:
- - true if the specified block is a valid RBW
-
invalidate
void invalidate(String bpid, org.apache.hadoop.hdfs.protocol.Block[] invalidBlks) throws IOException Invalidates the specified blocks.- Parameters:
bpid- Block pool IdinvalidBlks- - the blocks to be invalidated- Throws:
IOException
-
invalidateMissingBlock
void invalidateMissingBlock(String bpid, org.apache.hadoop.hdfs.protocol.Block block) throws IOException Invalidate a block which is not found on disk.- Parameters:
bpid- the block pool ID.block- The block to be invalidated.- Throws:
IOException
-
cache
Caches the specified block- Parameters:
bpid- Block pool idblockIds- - block ids to cache
-
uncache
Uncaches the specified blocks- Parameters:
bpid- Block pool idblockIds- - blocks ids to uncache
-
isCached
Determine if the specified block is cached.- Parameters:
bpid- Block pool idblockId- - block id- Returns:
- true if the block is cached
-
handleVolumeFailures
Check if all the data directories are healthy- Parameters:
failedVolumes-
-
shutdown
void shutdown()Shutdown the FSDataset -
adjustCrcChannelPosition
void adjustCrcChannelPosition(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, ReplicaOutputStreams outs, int checksumSize) throws IOException Sets the file pointer of the checksum stream so that the last checksum will be overwritten- Parameters:
b- blockouts- The streams for the data file and checksum filechecksumSize- number of bytes each checksum has- Throws:
IOException
-
hasEnoughResource
boolean hasEnoughResource()Checks how many valid storage volumes there are in the DataNode.- Returns:
- true if more than the minimum number of valid volumes are left in the FSDataSet.
-
getReplicaVisibleLength
long getReplicaVisibleLength(org.apache.hadoop.hdfs.protocol.ExtendedBlock block) throws IOException Get visible length of the specified replica.- Throws:
IOException
-
initReplicaRecovery
ReplicaRecoveryInfo initReplicaRecovery(BlockRecoveryCommand.RecoveringBlock rBlock) throws IOException Initialize a replica recovery.- Returns:
- actual state of the replica on this data-node or null if data-node does not have the replica.
- Throws:
IOException
-
updateReplicaUnderRecovery
Replica updateReplicaUnderRecovery(org.apache.hadoop.hdfs.protocol.ExtendedBlock oldBlock, long recoveryId, long newBlockId, long newLength) throws IOException Update replica's generation stamp and length and finalize it.- Returns:
- the ID of storage that stores the block
- Throws:
IOException
-
addBlockPool
add new block pool ID- Parameters:
bpid- Block pool Idconf- Configuration- Throws:
IOException
-
shutdownBlockPool
Shutdown and remove the block pool from underlying storage.- Parameters:
bpid- Block pool Id to be removed
-
deleteBlockPool
Deletes the block pool directories. If force is false, directories are deleted only if no block files exist for the block pool. If force is true entire directory for the blockpool is deleted along with its contents.- Parameters:
bpid- BlockPool Id to be deleted.force- If force is false, directories are deleted only if no block files exist for the block pool, otherwise entire directory for the blockpool is deleted along with its contents.- Throws:
IOException
-
getBlockLocalPathInfo
org.apache.hadoop.hdfs.protocol.BlockLocalPathInfo getBlockLocalPathInfo(org.apache.hadoop.hdfs.protocol.ExtendedBlock b) throws IOException GetBlockLocalPathInfofor the given block.- Throws:
IOException
-
enableTrash
Enable 'trash' for the given dataset. When trash is enabled, files are moved to a separate trash directory instead of being deleted immediately. This can be useful for example during rolling upgrades. -
clearTrash
Clear trash -
trashEnabled
- Returns:
- true when trash is enabled
-
setRollingUpgradeMarker
Create a marker file indicating that a rolling upgrade is in progress.- Throws:
IOException
-
clearRollingUpgradeMarker
Delete the rolling upgrade marker file if it exists.- Parameters:
bpid-- Throws:
IOException
-
submitBackgroundSyncFileRangeRequest
void submitBackgroundSyncFileRangeRequest(org.apache.hadoop.hdfs.protocol.ExtendedBlock block, ReplicaOutputStreams outs, long offset, long nbytes, int flags) submit a sync_file_range request to AsyncDiskService. -
onCompleteLazyPersist
void onCompleteLazyPersist(String bpId, long blockId, long creationTime, File[] savedFiles, V targetVolume) Callback from RamDiskAsyncLazyPersistService upon async lazy persist task end -
onFailLazyPersist
Callback from RamDiskAsyncLazyPersistService upon async lazy persist task fail -
moveBlockAcrossStorage
ReplicaInfo moveBlockAcrossStorage(org.apache.hadoop.hdfs.protocol.ExtendedBlock block, org.apache.hadoop.fs.StorageType targetStorageType, String storageId) throws IOException Move block from one storage to another storage- Throws:
IOException
-
setPinning
Set a block to be pinned on this datanode so that it cannot be moved by Balancer/Mover. It is a no-op when dfs.datanode.block-pinning.enabled is set to false.- Throws:
IOException
-
getPinning
Check whether the block was pinned- Throws:
IOException
-
isDeletingBlock
Confirm whether the block is deleting -
moveBlockAcrossVolumes
ReplicaInfo moveBlockAcrossVolumes(org.apache.hadoop.hdfs.protocol.ExtendedBlock block, FsVolumeSpi destination) throws IOException Moves a given block from one volume to another volume. This is used by disk balancer.- Parameters:
block- - ExtendedBlockdestination- - Destination volume- Returns:
- Old replica info
- Throws:
IOException
-
acquireDatasetLockManager
DataNodeLockManager<? extends AutoCloseDataSetLock> acquireDatasetLockManager()Acquire lock Manager for the data set. This prevents other threads from modifying the volume map structure inside the datanode.- Returns:
- The AutoClosable read lock instance.
-
deepCopyReplica
Deep copy the replica info belonging to given block pool.- Parameters:
bpid- Specified block pool id.- Returns:
- A set of replica info.
- Throws:
IOException
-
getMountVolumeMap
Get relationship between disk mount and FsVolume.- Returns:
- Disk mount and FsVolume relationship.
- Throws:
IOException
-
getVolumeList
List<FsVolumeImpl> getVolumeList()Get the volume list. -
setLastDirScannerFinishTime
default void setLastDirScannerFinishTime(long time) Set the last time in milliseconds when the directory scanner successfully ran.- Parameters:
time- the last time in milliseconds when the directory scanner successfully ran.
-