BlockPoolSliceStorage, DataStorage, NNStorage@Private public abstract class Storage extends StorageInfo
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).
| Modifier and Type | Class | Description |
|---|---|---|
static interface |
Storage.FormatConfirmable |
Interface for classes which need to have the user confirm their
formatting during NameNode -format and other similar operations.
|
static class |
Storage.StorageDirectory |
One of the storage directories.
|
static interface |
Storage.StorageDirType |
An interface to denote storage directory type
Implementations can define a type for storage directory by implementing
this interface.
|
static class |
Storage.StorageState |
| Modifier and Type | Field | Description |
|---|---|---|
static int |
LAST_PRE_UPGRADE_LAYOUT_VERSION |
|
protected static java.lang.String |
LAST_UPGRADABLE_HADOOP_VERSION |
|
static int |
LAST_UPGRADABLE_LAYOUT_VERSION |
|
static int[] |
LAYOUT_VERSIONS_203 |
Layout versions of 0.20.203 release
|
static org.slf4j.Logger |
LOG |
|
static java.lang.String |
STORAGE_1_BBW |
The blocksBeingWritten directory which was used in some 1.x and earlier
releases.
|
static java.lang.String |
STORAGE_DIR_CURRENT |
|
static java.lang.String |
STORAGE_DIR_PREVIOUS |
|
static java.lang.String |
STORAGE_FILE_LOCK |
|
static java.lang.String |
STORAGE_PREVIOUS_CKPT |
|
static java.lang.String |
STORAGE_TMP_FINALIZED |
|
static java.lang.String |
STORAGE_TMP_LAST_CKPT |
|
static java.lang.String |
STORAGE_TMP_PREVIOUS |
|
static java.lang.String |
STORAGE_TMP_REMOVED |
clusterID, cTime, layoutVersion, namespaceID, STORAGE_FILE_VERSION, storageType| Modifier | Constructor | Description |
|---|---|---|
protected |
Storage(HdfsServerConstants.NodeType type) |
Create empty storage info of the specified type
|
protected |
Storage(StorageInfo storageInfo) |
| Modifier and Type | Method | Description |
|---|---|---|
protected void |
addStorageDir(Storage.StorageDirectory sd) |
|
static void |
checkVersionUpgradable(int oldVersion) |
Checks if the upgrade from
oldVersion is supported. |
static boolean |
confirmFormat(java.lang.Iterable<? extends Storage.FormatConfirmable> items,
boolean force,
boolean interactive) |
Iterate over each of the
Storage.FormatConfirmable objects,
potentially checking with the user whether it should be formatted. |
protected boolean |
containsStorageDir(java.io.File root) |
Returns true if the storage directory on the given directory is already
loaded.
|
protected boolean |
containsStorageDir(StorageLocation location) |
Returns true if the storage directory on the given directory is already
loaded.
|
protected boolean |
containsStorageDir(StorageLocation location,
java.lang.String bpid) |
Returns true if the storage directory on the given location is already
loaded.
|
static void |
deleteDir(java.io.File dir) |
Recursively delete all the content of the directory first and then
the directory itself from the local filesystem.
|
java.lang.Iterable<Storage.StorageDirectory> |
dirIterable(Storage.StorageDirType dirType) |
|
java.util.Iterator<Storage.StorageDirectory> |
dirIterator() |
Return default iterator
This iterator returns all entries in storageDirs
|
java.util.Iterator<Storage.StorageDirectory> |
dirIterator(boolean includeShared) |
Return all entries in storageDirs, potentially excluding shared dirs.
|
java.util.Iterator<Storage.StorageDirectory> |
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 Iterator
|
java.util.Iterator<Storage.StorageDirectory> |
dirIterator(Storage.StorageDirType dirType,
boolean includeShared) |
|
static java.lang.String |
getBuildVersion() |
|
java.util.List<java.io.File> |
getFiles(Storage.StorageDirType dirType,
java.lang.String fileName) |
|
NamespaceInfo |
getNamespaceInfo() |
|
int |
getNumStorageDirs() |
|
static java.lang.String |
getRegistrationID(StorageInfo storage) |
|
Storage.StorageDirectory |
getSingularStorageDir() |
|
Storage.StorageDirectory |
getStorageDir(int idx) |
|
java.util.List<Storage.StorageDirectory> |
getStorageDirs() |
|
static boolean |
is203LayoutVersion(int layoutVersion) |
|
abstract boolean |
isPreUpgradableLayout(Storage.StorageDirectory sd) |
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.
|
java.lang.String |
listStorageDirectories() |
generate storage list (debug line)
|
static void |
nativeCopyFileUnbuffered(java.io.File srcFile,
java.io.File destFile,
boolean preserveFileDate) |
Copies a file (usually large) to a new location using native unbuffered IO.
|
static void |
rename(java.io.File from,
java.io.File to) |
|
protected void |
setPropertiesFromFields(java.util.Properties props,
Storage.StorageDirectory sd) |
Set common storage fields into the given properties object.
|
void |
unlockAll() |
Unlock all storage directories.
|
void |
writeAll() |
Write all data storage files.
|
static void |
writeProperties(java.io.File to,
java.util.Properties props) |
|
void |
writeProperties(java.io.File to,
Storage.StorageDirectory sd) |
|
void |
writeProperties(Storage.StorageDirectory sd) |
Write properties to the VERSION file in the given storage directory.
|
checkStorageType, getClusterID, getClusterIdFromColonSeparatedString, getCTime, getLayoutVersion, getNamespaceID, getNsIdFromColonSeparatedString, getProperty, getServiceLayoutFeatureMap, getServiceLayoutVersion, readPreviousVersionProperties, readProperties, readPropertiesFile, setClusterId, setcTime, setFieldsFromProperties, setLayoutVersion, setNamespaceID, setServiceLayoutVersion, setStorageInfo, toColonSeparatedString, toMapString, toString, versionSupportsFederationpublic static final org.slf4j.Logger LOG
public static final int LAST_PRE_UPGRADE_LAYOUT_VERSION
public static final int LAST_UPGRADABLE_LAYOUT_VERSION
protected static final java.lang.String LAST_UPGRADABLE_HADOOP_VERSION
public static final int[] LAYOUT_VERSIONS_203
public static final java.lang.String STORAGE_FILE_LOCK
public static final java.lang.String STORAGE_DIR_CURRENT
public static final java.lang.String STORAGE_DIR_PREVIOUS
public static final java.lang.String STORAGE_TMP_REMOVED
public static final java.lang.String STORAGE_TMP_PREVIOUS
public static final java.lang.String STORAGE_TMP_FINALIZED
public static final java.lang.String STORAGE_TMP_LAST_CKPT
public static final java.lang.String STORAGE_PREVIOUS_CKPT
public static final java.lang.String STORAGE_1_BBW
protected Storage(HdfsServerConstants.NodeType type)
protected Storage(StorageInfo storageInfo)
public java.util.List<java.io.File> getFiles(Storage.StorageDirType dirType, java.lang.String fileName)
public java.util.Iterator<Storage.StorageDirectory> dirIterator()
public java.util.Iterator<Storage.StorageDirectory> dirIterator(Storage.StorageDirType dirType)
public java.util.Iterator<Storage.StorageDirectory> dirIterator(boolean includeShared)
includeShared - whether or not to include shared dirs.public java.util.Iterator<Storage.StorageDirectory> dirIterator(Storage.StorageDirType dirType, boolean includeShared)
dirType - all entries will be of this type of dirincludeShared - true to include any shared directories,
false otherwisepublic java.lang.Iterable<Storage.StorageDirectory> dirIterable(Storage.StorageDirType dirType)
public java.lang.String listStorageDirectories()
public int getNumStorageDirs()
public java.util.List<Storage.StorageDirectory> getStorageDirs()
public Storage.StorageDirectory getStorageDir(int idx)
public Storage.StorageDirectory getSingularStorageDir()
protected void addStorageDir(Storage.StorageDirectory sd)
protected boolean containsStorageDir(java.io.File root)
throws java.io.IOException
root - the root directory of a Storage.StorageDirectoryjava.io.IOException - if failed to get canonical path.protected boolean containsStorageDir(StorageLocation location) throws java.io.IOException
location - the StorageLocationjava.io.IOException - if failed to get canonical path.protected boolean containsStorageDir(StorageLocation location, java.lang.String bpid) throws java.io.IOException
location - the StorageLocationbpid - the block pool idjava.io.IOException - IOException if failed to read location
or storage directory pathpublic NamespaceInfo getNamespaceInfo()
public abstract boolean isPreUpgradableLayout(Storage.StorageDirectory sd) throws java.io.IOException
java.io.IOExceptionpublic static void checkVersionUpgradable(int oldVersion)
throws java.io.IOException
oldVersion is supported.oldVersion - the version of the metadata to check with the current
versionjava.io.IOException - if upgrade is not supportedpublic static boolean confirmFormat(java.lang.Iterable<? extends Storage.FormatConfirmable> items, boolean force, boolean interactive) throws java.io.IOException
Storage.FormatConfirmable objects,
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.force - format regardless of whether dirs existinteractive - prompt the user when a dir existsjava.io.IOException - if some storage cannot be accessedprotected void setPropertiesFromFields(java.util.Properties props,
Storage.StorageDirectory sd)
throws java.io.IOException
props - the Properties object to write intojava.io.IOExceptionpublic void writeProperties(Storage.StorageDirectory sd) throws java.io.IOException
java.io.IOExceptionpublic void writeProperties(java.io.File to,
Storage.StorageDirectory sd)
throws java.io.IOException
java.io.IOExceptionpublic static void writeProperties(java.io.File to,
java.util.Properties props)
throws java.io.IOException
java.io.IOExceptionpublic static void rename(java.io.File from,
java.io.File to)
throws java.io.IOException
java.io.IOExceptionpublic static void nativeCopyFileUnbuffered(java.io.File srcFile,
java.io.File destFile,
boolean preserveFileDate)
throws java.io.IOException
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 preserveFileDate to
true tries to preserve the file's last modified
date/times using File.setLastModified(long), however it is
not guaranteed that the operation will succeed.
If the modification operation fails, no indication is provided.
srcFile - an existing file to copy, must not be nulldestFile - the new file, must not be nullpreserveFileDate - true if the file date of the copy
should be the same as the originaljava.lang.NullPointerException - if source or destination is nulljava.io.IOException - if source or destination is invalidjava.io.IOException - if an IO error occurs during copyingpublic static void deleteDir(java.io.File dir)
throws java.io.IOException
dir - The directory to deletejava.io.IOExceptionpublic void writeAll()
throws java.io.IOException
java.io.IOExceptionpublic void unlockAll()
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String getBuildVersion()
public static java.lang.String getRegistrationID(StorageInfo storage)
public static boolean is203LayoutVersion(int layoutVersion)
Copyright © 2008–2025 Apache Software Foundation. All rights reserved.