Class NNStorage
java.lang.Object
org.apache.hadoop.hdfs.server.common.StorageInfo
org.apache.hadoop.hdfs.server.common.Storage
org.apache.hadoop.hdfs.server.namenode.NNStorage
- All Implemented Interfaces:
Closeable,AutoCloseable,StorageErrorReporter
NNStorage is responsible for management of the StorageDirectories used by
the NameNode.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumImplementation of StorageDirType specific to namenode storage A Storage directory could be of type IMAGE which stores only fsimage, or of type EDITS which stores edits or of type IMAGE_AND_EDITS which stores both fsimage and edits.static enumThe filenames used for storing the images.Nested classes/interfaces inherited from class org.apache.hadoop.hdfs.server.common.Storage
Storage.FormatConfirmable, Storage.StorageDirectory, Storage.StorageDirType, Storage.StorageState -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected longTxId of the last transaction that was included in the most recent fsimage file.protected final List<Storage.StorageDirectory>List of failed (and thus removed) storages.Fields inherited from class org.apache.hadoop.hdfs.server.common.Storage
LAST_PRE_UPGRADE_LAYOUT_VERSION, LAST_UPGRADABLE_HADOOP_VERSION, LAST_UPGRADABLE_LAYOUT_VERSION, LAYOUT_VERSIONS_203, LOG, STORAGE_1_BBW, STORAGE_DIR_CURRENT, STORAGE_DIR_PREVIOUS, STORAGE_FILE_LOCK, STORAGE_PREVIOUS_CKPT, STORAGE_TMP_FINALIZED, STORAGE_TMP_LAST_CKPT, STORAGE_TMP_PREVIOUS, STORAGE_TMP_REMOVEDFields inherited from class org.apache.hadoop.hdfs.server.common.StorageInfo
clusterID, cTime, layoutVersion, namespaceID, STORAGE_FILE_VERSION, storageType -
Constructor Summary
ConstructorsConstructorDescriptionNNStorage(org.apache.hadoop.conf.Configuration conf, Collection<URI> imageDirs, Collection<URI> editsDirs) Construct the NNStorage. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Try to find current cluster id in the VERSION files.voidformat()voidformat(NamespaceInfo nsInfo) Format all available storage directories.voidformat(NamespaceInfo nsInfo, boolean isRollingUpgrade) Format all available storage directories.static StringgetCheckpointImageFileName(long txid) static FilegetFinalizedEditsFile(Storage.StorageDirectory sd, long startTxId, long endTxId) static StringgetFinalizedEditsFileName(long startTxId, long endTxId) getFsImage(long txid, EnumSet<NNStorage.NameNodeFile> nnfs) getFsImageName(long txid) getFsImageName(long txid, NNStorage.NameNodeFile nnf) File[]getFsImageNameCheckpoint(long txid) Return the name of the image file that is uploaded by periodic checkpointing.static StringgetImageFileName(long txid) static StringgetInProgressEditsFileName(long startTxId) static StringgetLegacyOIVImageFileName(long txid) longlongstatic StringgetRollbackImageFileName(long txid) getStorageDirectory(URI uri) Return the storage directory corresponding to the passed URI.static FilegetTemporaryEditsFile(Storage.StorageDirectory sd, long startTxId, long endTxId, long timestamp) static StringgetTemporaryEditsFileName(long startTxId, long endTxId, long timestamp) 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.static StringGenerate new clusterID.static NamespaceInfovoidReport that an IOE has occurred on some file which may or may not be within one of the NN image storage directories.voidsetBlockPoolID(String bpid) Validate and set block pool ID.protected voidGet common storage fields.protected voidWrite version file into the storage directory.voidvoidwriteAll()Write all data storage files.voidwriteTransactionIdFileToStorage(long txid) Write a small file in all available storage directories that indicates that the namespace has reached some given transaction ID.voidwriteTransactionIdFileToStorage(long txid, NNStorage.NameNodeDirType type) Write a small file in all available storage directories that indicates that the namespace has reached some given transaction ID.Methods inherited from class org.apache.hadoop.hdfs.server.common.Storage
addStorageDir, checkVersionUpgradable, confirmFormat, containsStorageDir, containsStorageDir, containsStorageDir, deleteDir, dirIterable, dirIterator, dirIterator, dirIterator, dirIterator, getBuildVersion, getFiles, getNumStorageDirs, getRegistrationID, getSingularStorageDir, getStorageDir, getStorageDirs, is203LayoutVersion, listStorageDirectories, nativeCopyFileUnbuffered, rename, unlockAll, writeProperties, writeProperties, writePropertiesMethods 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, setLayoutVersion, setNamespaceID, setServiceLayoutVersion, setStorageInfo, toColonSeparatedString, toMapString, toString, versionSupportsFederation
-
Field Details
-
blockpoolID
-
mostRecentCheckpointTxId
protected volatile long mostRecentCheckpointTxIdTxId of the last transaction that was included in the most recent fsimage file. This does not include any transactions that have since been written to the edit log. -
removedStorageDirs
List of failed (and thus removed) storages.
-
-
Constructor Details
-
NNStorage
public NNStorage(org.apache.hadoop.conf.Configuration conf, Collection<URI> imageDirs, Collection<URI> editsDirs) throws IOException Construct the NNStorage.- Parameters:
conf- Namenode configuration.imageDirs- Directories the image can be stored in.editsDirs- Directories the editlog can be stored in.- Throws:
IOException- if any directories are inaccessible.
-
-
Method Details
-
isPreUpgradableLayout
Description copied from class:StorageReturn 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.- Specified by:
isPreUpgradableLayoutin classStorage- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getStorageDirectory
Return the storage directory corresponding to the passed URI.- Parameters:
uri- URI of a storage directory- Returns:
- The matching storage directory or null if none found
-
getMostRecentCheckpointTxId
public long getMostRecentCheckpointTxId()- Returns:
- the transaction ID of the last checkpoint.
-
getMostRecentCheckpointTime
public long getMostRecentCheckpointTime()- Returns:
- the time of the most recent checkpoint in millis since the epoch.
-
writeTransactionIdFileToStorage
public void writeTransactionIdFileToStorage(long txid) Write a small file in all available storage directories that indicates that the namespace has reached some given transaction ID. This is used when the image is loaded to avoid accidental rollbacks in the case where an edit log is fully deleted but there is no checkpoint. See TestNameEditsConfigs.testNameEditsConfigsFailure()- Parameters:
txid- the txid that has been reached
-
writeTransactionIdFileToStorage
Write a small file in all available storage directories that indicates that the namespace has reached some given transaction ID. This is used when the image is loaded to avoid accidental rollbacks in the case where an edit log is fully deleted but there is no checkpoint. See TestNameEditsConfigs.testNameEditsConfigsFailure()- Parameters:
txid- the txid that has been reachedtype- the type of directory
-
getFsImageNameCheckpoint
Return the name of the image file that is uploaded by periodic checkpointing.- Returns:
- List of filenames to save checkpoints to.
-
getFsImageName
- Returns:
- The first image file with the given txid and image type.
-
getFsImage
- Returns:
- The first image file whose txid is the same with the given txid and image type is one of the given types.
-
getFsImageName
-
getHighestFsImageName
-
format
Format all available storage directories.- Throws:
IOException
-
format
Format all available storage directories.- Throws:
IOException
-
newNamespaceInfo
- Throws:
UnknownHostException
-
format
- Throws:
IOException
-
setFieldsFromProperties
protected void setFieldsFromProperties(Properties props, Storage.StorageDirectory sd) throws IOException Description copied from class:StorageInfoGet common storage fields. Should be overloaded if additional fields need to be get.- Overrides:
setFieldsFromPropertiesin classStorageInfo- Parameters:
props- properties- Throws:
IOException- on error
-
setPropertiesFromFields
protected void setPropertiesFromFields(Properties props, Storage.StorageDirectory sd) throws IOException Write version file into the storage directory. The version file should always be written last. Missing or corrupted version file indicates that the checkpoint is not valid.- Overrides:
setPropertiesFromFieldsin classStorage- Parameters:
sd- storage directoryprops- the Properties object to write into- Throws:
IOException
-
getCheckpointImageFileName
-
getImageFileName
-
getRollbackImageFileName
-
getLegacyOIVImageFileName
-
getInProgressEditsFileName
-
getFinalizedEditsFile
-
getTemporaryEditsFile
public static File getTemporaryEditsFile(Storage.StorageDirectory sd, long startTxId, long endTxId, long timestamp) -
getFinalizedEditsFileName
-
getTemporaryEditsFileName
-
reportErrorOnFile
Report that an IOE has occurred on some file which may or may not be within one of the NN image storage directories.- Specified by:
reportErrorOnFilein interfaceStorageErrorReporter- Parameters:
f- the file which had an error.
-
newClusterID
Generate new clusterID. clusterID is a persistent attribute of the cluster. It is generated when the cluster is created and remains the same during the life cycle of the cluster. When a new name node is formated, if this is a new cluster, a new clusterID is geneated and stored. Subsequent name node must be given the same ClusterID during its format to be in the same cluster. When a datanode register it receive the clusterID and stick with it. If at any point, name node or data node tries to join another cluster, it will be rejected.- Returns:
- new clusterID
-
determineClusterId
Try to find current cluster id in the VERSION files. returns first cluster id found in any VERSION file null in case none found- Returns:
- clusterId or null in case no cluster id found
-
setBlockPoolID
Validate and set block pool ID. -
getBlockPoolID
-
getNamespaceInfo
- Overrides:
getNamespaceInfoin classStorage
-
getNNDirectorySize
-
updateNameDirSize
public void updateNameDirSize() -
writeAll
Write all data storage files.- Overrides:
writeAllin classStorage- Throws:
IOException- When all the storage directory fails to write VERSION file
-