Secondary NameNode in HDFS
Secondary NameNode in Hadoop is more of a helper to NameNode, it is not a backup NameNode server which can quickly take over in case of NameNode failure.
Before going into details about Secondary NameNode in HDFS let’s go back to the two files which were mentioned while discussing NameNode in Hadoop– FsImage and EditLog.
- EditLog– All the file write operations done by client applications are first recorded in the EditLog.
- FsImage– This file has the complete information about the file system metadata when the NameNode starts. All the operations after that are recorded in EditLog.
When the NameNode is restarted it first takes metadata information from the FsImage and then apply all the transactions recorded in EditLog. NameNode restart doesn’t happen that frequently so EditLog grows quite large. That means merging of EditLog to FsImage at the time of startup takes a lot of time keeping the whole file system offline during that process.
Now you may be thinking only if there is some entity which could take over this job of merging FsImage and EditLog and keep the FsImage current that will save a lot of time. That’s exactly what Secondary NameNode does in Hadoop. Its main function is to check point the file system metadata stored on NameNode.
The process followed by Secondary NameNode to periodically merge the fsimage and the edits log files is as follows-
- Secondary NameNode gets the latest FsImage and EditLog files from the primary NameNode.
- Secondary NameNode applies each transaction from EditLog file to FsImage to create a new merged FsImage file.
- Merged FsImage file is transferred back to primary NameNode.
The start of the checkpoint process on the secondary NameNode is controlled by two configuration parameters which are to be configured in hdfs-site.xml.
- dfs.namenode.checkpoint.period - This property specifies the maximum delay between two consecutive checkpoints. Set to 1 hour by default.
- dfs.namenode.checkpoint.txns - This property defines the number of uncheckpointed transactions on the NameNode which will force an urgent checkpoint, even if the checkpoint period has not been reached. Set to 1 million by default.
Following image shows the HDFS architecture with communication among NameNode, Secondary NameNode, DataNode and client application.