Class Storage.StorageDirectory
java.lang.Object
org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory
- All Implemented Interfaces:
Storage.FormatConfirmable
- Enclosing class:
- Storage
@Private
public static class Storage.StorageDirectory
extends Object
implements Storage.FormatConfirmable
One of the storage directories.
-
Constructor Summary
ConstructorsConstructorDescriptionStorageDirectory(File dir) StorageDirectory(File dir, Storage.StorageDirType dirType) StorageDirectory(File dir, Storage.StorageDirType dirType, boolean isShared) ConstructorStorageDirectory(File dir, Storage.StorageDirType dirType, boolean isShared, org.apache.hadoop.fs.permission.FsPermission permission) StorageDirectory(String bpid, Storage.StorageDirType dirType, boolean isShared, StorageLocation location) ConstructorStorageDirectory(Storage.StorageDirType dirType, boolean isShared, StorageLocation location) ConstructorStorageDirectory(StorageLocation location) -
Method Summary
Modifier and TypeMethodDescriptionanalyzeStorage(HdfsServerConstants.StartupOption startOpt, Storage storage) Check consistency of the storage directory.analyzeStorage(HdfsServerConstants.StartupOption startOpt, Storage storage, boolean checkCurrentIsEmpty) Check consistency of the storage directory.voidClear and re-create storage directory.voiddoRecover(Storage.StorageState curState) Complete or recover storage state from previously failed transition.Directorycurrentcontains latest files defining the file system meta-data.longGet storage directory size.finalized.tmpis a transient directory, which holds thepreviousfile system state while it is being removed in response to the finalize request.lastcheckpoint.tmpis a transient directory, which holds current file system state while the new state is saved into the newcurrentduring regular namespace updates.previous.checkpointis a directory, which holds the previous (before the last save) state of the storage directory.Directorypreviouscontains the previous file system state, which the system can be rolled back to.previous.tmpis a transient directory, which holds current file system state while the new state is saved into the newcurrentduring upgrade.FileVERSIONfrom thepreviousdirectory.removed.tmpis a transient directory, which holds current file system state while the previous state is moved intocurrentduring rollback.getRoot()Get root directory of this storageGet storage directory typeFileVERSIONcontains the following fields: node type layout version namespaceID fs state creation time other fields specific for this node type The version file is always written last during storage directory updates.booleanbooleanCheck whether underlying file system supports file locking.booleanisShared()voidlock()Lock storage to provide exclusive access.voidvoidsetStorageUuid(String storageUuid) toString()voidunlock()Unlock storage.
-
Constructor Details
-
StorageDirectory
-
StorageDirectory
-
StorageDirectory
-
StorageDirectory
Constructor- Parameters:
dir- directory corresponding to the storagedirType- storage directory typeisShared- whether or not this dir is shared between two NNs. true disables locking on the storage directory, false enables locking
-
StorageDirectory
public StorageDirectory(File dir, Storage.StorageDirType dirType, boolean isShared, org.apache.hadoop.fs.permission.FsPermission permission) -
StorageDirectory
Constructor- Parameters:
dirType- storage directory typeisShared- whether or not this dir is shared between two NNs. true disables locking on the storage directory, false enables lockinglocation- theStorageLocationfor this directory
-
StorageDirectory
public StorageDirectory(String bpid, Storage.StorageDirType dirType, boolean isShared, StorageLocation location) Constructor- Parameters:
bpid- the block pool iddirType- storage directory typeisShared- whether or not this dir is shared between two NNs. true disables locking on the storage directory, false enables lockinglocation- theStorageLocationfor this directory
-
-
Method Details
-
setStorageUuid
-
getStorageUuid
-
getRoot
Get root directory of this storage -
getStorageDirType
Get storage directory type -
getDirecorySize
public long getDirecorySize()Get storage directory size. -
read
- Throws:
IOException
-
clearDirectory
Clear and re-create storage directory.Removes contents of the current directory and creates an empty directory. This does not fully format storage directory. It cannot write the version file since it should be written last after all other storage type dependent files are written. Derived storage is responsible for setting specific storage values and writing the version file to disk.
- Throws:
IOException
-
getCurrentDir
Directorycurrentcontains latest files defining the file system meta-data.- Returns:
- the directory path
-
getVersionFile
FileVERSIONcontains the following fields:- node type
- layout version
- namespaceID
- fs state creation time
- other fields specific for this node type
- Returns:
- the version file path
-
getPreviousVersionFile
FileVERSIONfrom thepreviousdirectory.- Returns:
- the previous version file path
-
getPreviousDir
Directorypreviouscontains the previous file system state, which the system can be rolled back to.- Returns:
- the directory path
-
getPreviousTmp
previous.tmpis a transient directory, which holds current file system state while the new state is saved into the newcurrentduring upgrade. If the saving succeedsprevious.tmpwill be moved toprevious, otherwise it will be renamed back tocurrentby the recovery procedure during startup.- Returns:
- the directory path
-
getRemovedTmp
removed.tmpis a transient directory, which holds current file system state while the previous state is moved intocurrentduring rollback. If the moving succeedsremoved.tmpwill be removed, otherwise it will be renamed back tocurrentby the recovery procedure during startup.- Returns:
- the directory path
-
getFinalizedTmp
finalized.tmpis a transient directory, which holds thepreviousfile system state while it is being removed in response to the finalize request. Finalize operation will removefinalized.tmpwhen completed, otherwise the removal will resume upon the system startup.- Returns:
- the directory path
-
getLastCheckpointTmp
lastcheckpoint.tmpis a transient directory, which holds current file system state while the new state is saved into the newcurrentduring regular namespace updates. If the saving succeedslastcheckpoint.tmpwill be moved toprevious.checkpoint, otherwise it will be renamed back tocurrentby the recovery procedure during startup.- Returns:
- the directory path
-
getPreviousCheckpoint
previous.checkpointis a directory, which holds the previous (before the last save) state of the storage directory. The directory is created as a reference only, it does not play role in state recovery procedures, and is recycled automatically, but it may be useful for manual recovery of a stale state of the system.- Returns:
- the directory path
-
analyzeStorage
public Storage.StorageState analyzeStorage(HdfsServerConstants.StartupOption startOpt, Storage storage) throws IOException Check consistency of the storage directory.- Parameters:
startOpt- a startup option.storage- The Storage object that manages this StorageDirectory.- Returns:
- state
Storage.StorageStateof the storage directory - Throws:
InconsistentFSStateException- if directory state is not consistent and cannot be recovered.IOException
-
analyzeStorage
public Storage.StorageState analyzeStorage(HdfsServerConstants.StartupOption startOpt, Storage storage, boolean checkCurrentIsEmpty) throws IOException Check consistency of the storage directory.- Parameters:
startOpt- a startup option.storage- The Storage object that manages this StorageDirectory.checkCurrentIsEmpty- if true, make sure current/ directory is empty before determining to format it.- Returns:
- state
Storage.StorageStateof the storage directory - Throws:
InconsistentFSStateException- if directory state is not consistent and cannot be recovered.IOException
-
doRecover
Complete or recover storage state from previously failed transition.- Parameters:
curState- specifies what/how the state should be recovered- Throws:
IOException
-
hasSomeData
- Specified by:
hasSomeDatain interfaceStorage.FormatConfirmable- Returns:
- true if the storage directory should prompt the user prior to formatting (i.e if the directory appears to contain some data)
- Throws:
IOException- if the SD cannot be accessed due to an IO error
-
lock
Lock storage to provide exclusive access.Locking is not supported by all file systems. E.g., NFS does not consistently support exclusive locks.
If locking is supported we guarantee exclusive access to the storage directory. Otherwise, no guarantee is given.
- Throws:
IOException- if locking fails
-
unlock
Unlock storage.- Throws:
IOException
-
toString
- Specified by:
toStringin interfaceStorage.FormatConfirmable- Overrides:
toStringin classObject- Returns:
- a string representation of the formattable item, suitable for display to the user inside a prompt
-
isLockSupported
Check whether underlying file system supports file locking.- Returns:
trueif exclusive locks are supported orfalseotherwise.- Throws:
IOException- See Also:
-
getStorageLocation
-