Class Storage
- Direct Known Subclasses:
BlockPoolSliceStorage,DataStorage,NNStorage
Local storage information is stored in a separate file VERSION. It contains type of the node, the storage layout version, the namespace id, and the fs state creation time.
Local storage can reside in multiple directories. Each directory should contain the same VERSION file as the others. During startup Hadoop servers (name-node and data-nodes) read their local storage information from them.
The servers hold a lock for each storage directory while they run so that other nodes were not able to startup sharing the same storage. The locks are released when the servers stop (normally or abnormally).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for classes which need to have the user confirm their formatting during NameNode -format and other similar operations.static classOne of the storage directories.static interfaceAn interface to denote storage directory type Implementations can define a type for storage directory by implementing this interface.static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intprotected static final Stringstatic final intstatic final int[]Layout versions of 0.20.203 releasestatic final org.slf4j.Loggerstatic final StringThe blocksBeingWritten directory which was used in some 1.x and earlier releases.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class org.apache.hadoop.hdfs.server.common.StorageInfo
clusterID, cTime, layoutVersion, namespaceID, STORAGE_FILE_VERSION, storageType -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreate empty storage info of the specified typeprotectedStorage(StorageInfo storageInfo) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidstatic voidcheckVersionUpgradable(int oldVersion) Checks if the upgrade fromoldVersionis supported.static booleanconfirmFormat(Iterable<? extends Storage.FormatConfirmable> items, boolean force, boolean interactive) Iterate over each of theStorage.FormatConfirmableobjects, potentially checking with the user whether it should be formatted.protected booleancontainsStorageDir(File root) Returns true if the storage directory on the given directory is already loaded.protected booleancontainsStorageDir(StorageLocation location) Returns true if the storage directory on the given directory is already loaded.protected booleancontainsStorageDir(StorageLocation location, String bpid) Returns true if the storage directory on the given location is already loaded.static voidRecursively delete all the content of the directory first and then the directory itself from the local filesystem.dirIterable(Storage.StorageDirType dirType) Return default iterator This iterator returns all entries in storageDirsdirIterator(boolean includeShared) Return all entries in storageDirs, potentially excluding shared dirs.dirIterator(Storage.StorageDirType dirType) Return iterator based on Storage Directory Type This iterator selects entries in storageDirs of type dirType and returns them via the IteratordirIterator(Storage.StorageDirType dirType, boolean includeShared) static StringgetFiles(Storage.StorageDirType dirType, String fileName) intstatic StringgetRegistrationID(StorageInfo storage) getStorageDir(int idx) static booleanis203LayoutVersion(int layoutVersion) abstract booleanReturn true if the layout of the given storage directory is from a version of Hadoop prior to the introduction of the "current" and "previous" directories which allow upgrade and rollback.generate storage list (debug line)static voidnativeCopyFileUnbuffered(File srcFile, File destFile, boolean preserveFileDate) Copies a file (usually large) to a new location using native unbuffered IO.static voidprotected voidSet common storage fields into the given properties object.voidUnlock all storage directories.voidwriteAll()Write all data storage files.static voidwriteProperties(File to, Properties props) voidvoidWrite properties to the VERSION file in the given storage directory.Methods inherited from class org.apache.hadoop.hdfs.server.common.StorageInfo
checkStorageType, getClusterID, getClusterIdFromColonSeparatedString, getCTime, getLayoutVersion, getNamespaceID, getNsIdFromColonSeparatedString, getProperty, getServiceLayoutFeatureMap, getServiceLayoutVersion, readPreviousVersionProperties, readProperties, readPropertiesFile, setClusterId, setcTime, setFieldsFromProperties, setLayoutVersion, setNamespaceID, setServiceLayoutVersion, setStorageInfo, toColonSeparatedString, toMapString, toString, versionSupportsFederation
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG -
LAST_PRE_UPGRADE_LAYOUT_VERSION
public static final int LAST_PRE_UPGRADE_LAYOUT_VERSION- See Also:
-
LAST_UPGRADABLE_LAYOUT_VERSION
public static final int LAST_UPGRADABLE_LAYOUT_VERSION- See Also:
-
LAST_UPGRADABLE_HADOOP_VERSION
- See Also:
-
LAYOUT_VERSIONS_203
public static final int[] LAYOUT_VERSIONS_203Layout versions of 0.20.203 release -
STORAGE_FILE_LOCK
- See Also:
-
STORAGE_DIR_CURRENT
- See Also:
-
STORAGE_DIR_PREVIOUS
- See Also:
-
STORAGE_TMP_REMOVED
- See Also:
-
STORAGE_TMP_PREVIOUS
- See Also:
-
STORAGE_TMP_FINALIZED
- See Also:
-
STORAGE_TMP_LAST_CKPT
- See Also:
-
STORAGE_PREVIOUS_CKPT
- See Also:
-
STORAGE_1_BBW
The blocksBeingWritten directory which was used in some 1.x and earlier releases.- See Also:
-
-
Constructor Details
-
Storage
Create empty storage info of the specified type -
Storage
-
-
Method Details
-
getFiles
- Returns:
- A list of the given File in every available storage directory, regardless of whether it might exist.
-
dirIterator
Return default iterator This iterator returns all entries in storageDirs -
dirIterator
Return iterator based on Storage Directory Type This iterator selects entries in storageDirs of type dirType and returns them via the Iterator -
dirIterator
Return all entries in storageDirs, potentially excluding shared dirs.- Parameters:
includeShared- whether or not to include shared dirs.- Returns:
- an iterator over the configured storage dirs.
-
dirIterator
public Iterator<Storage.StorageDirectory> dirIterator(Storage.StorageDirType dirType, boolean includeShared) - Parameters:
dirType- all entries will be of this type of dirincludeShared- true to include any shared directories, false otherwise- Returns:
- an iterator over the configured storage dirs.
-
dirIterable
-
listStorageDirectories
generate storage list (debug line) -
getNumStorageDirs
public int getNumStorageDirs() -
getStorageDirs
-
getStorageDir
-
getSingularStorageDir
- Returns:
- the storage directory, with the precondition that this storage has exactly one storage directory
-
addStorageDir
-
containsStorageDir
Returns true if the storage directory on the given directory is already loaded.- Parameters:
root- the root directory of aStorage.StorageDirectory- Throws:
IOException- if failed to get canonical path.
-
containsStorageDir
Returns true if the storage directory on the given directory is already loaded.- Parameters:
location- theStorageLocation- Throws:
IOException- if failed to get canonical path.
-
containsStorageDir
Returns true if the storage directory on the given location is already loaded.- Parameters:
location- theStorageLocationbpid- the block pool id- Returns:
- true if the location matches to any existing storage directories
- Throws:
IOException- IOException if failed to read location or storage directory path
-
getNamespaceInfo
-
isPreUpgradableLayout
Return true if the layout of the given storage directory is from a version of Hadoop prior to the introduction of the "current" and "previous" directories which allow upgrade and rollback.- Throws:
IOException
-
checkVersionUpgradable
Checks if the upgrade fromoldVersionis supported.- Parameters:
oldVersion- the version of the metadata to check with the current version- Throws:
IOException- if upgrade is not supported
-
confirmFormat
public static boolean confirmFormat(Iterable<? extends Storage.FormatConfirmable> items, boolean force, boolean interactive) throws IOException Iterate over each of theStorage.FormatConfirmableobjects, potentially checking with the user whether it should be formatted. If running in interactive mode, will prompt the user for each directory to allow them to format anyway. Otherwise, returns false, unless 'force' is specified.- Parameters:
force- format regardless of whether dirs existinteractive- prompt the user when a dir exists- Returns:
- true if formatting should proceed
- Throws:
IOException- if some storage cannot be accessed
-
setPropertiesFromFields
protected void setPropertiesFromFields(Properties props, Storage.StorageDirectory sd) throws IOException Set common storage fields into the given properties object. Should be overloaded if additional fields need to be set.- Parameters:
props- the Properties object to write into- Throws:
IOException
-
writeProperties
Write properties to the VERSION file in the given storage directory.- Throws:
IOException
-
writeProperties
- Throws:
IOException
-
writeProperties
- Throws:
IOException
-
rename
- Throws:
IOException
-
nativeCopyFileUnbuffered
public static void nativeCopyFileUnbuffered(File srcFile, File destFile, boolean preserveFileDate) throws IOException Copies a file (usually large) to a new location using native unbuffered IO.This method copies the contents of the specified source file to the specified destination file using OS specific unbuffered IO. The goal is to avoid churning the file system buffer cache when copying large files. We can't use FileUtils#copyFile from apache-commons-io because it is a buffered IO based on FileChannel#transferFrom, which uses MmapByteBuffer internally. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will delete it first.
Note: Setting
preserveFileDatetotruetries to preserve the file's last modified date/times usingFile.setLastModified(long), however it is not guaranteed that the operation will succeed. If the modification operation fails, no indication is provided.- Parameters:
srcFile- an existing file to copy, must not benulldestFile- the new file, must not benullpreserveFileDate- true if the file date of the copy should be the same as the original- Throws:
NullPointerException- if source or destination isnullIOException- if source or destination is invalidIOException- if an IO error occurs during copying
-
deleteDir
Recursively delete all the content of the directory first and then the directory itself from the local filesystem.- Parameters:
dir- The directory to delete- Throws:
IOException
-
writeAll
Write all data storage files.- Throws:
IOException
-
unlockAll
Unlock all storage directories.- Throws:
IOException
-
getBuildVersion
-
getRegistrationID
-
is203LayoutVersion
public static boolean is203LayoutVersion(int layoutVersion)
-