This time, I will elaborate on the internal principles of NameNode and SecondaryNameNode.
HOW NameNode WORK?
First, we need to consider where the metadata is stored in the NameNode.
If the metadata is stored in the disk of the NameNode node, it must be too inefficient because random access is often required, and it is necessary to respond to customer requests. Therefore, metadata needs to be kept in memory. But if it only exists in memory, once the power is turned off, the metadata is lost, and the entire cluster cannot work. So there is a FsImage that backs up the metadata on disk.
But this will bring new problems. When the metadata in the memory is updated, if the FsImage is updated simultaneously,, the efficiency will be too low, but if it is not updated, a consistency problem will occur. Once the NameNode node is powered off, Data loss will occur. Therefore, the Edits file is introduced (append-only, which is very efficient). Whenever metadata is updated or metadata is added, the metadata in memory is modified and appended to Edits. In this way, once the NameNode node is powered off, the metadata can be synthesized by merging FsImage and Edits.
The definitions of the two are summarized as follows.
- Fsimage: A permanent checkpoint of the HDFS file system metadata, containing serialization information for all directories and file inodes of the HDFS file system.
- Edits: The path where all update operations of the HDFS file system are stored. All write operations performed by the file system client will first be recorded in the Edits file.
Every time the NameNode starts, the Fsimage file will be read into the memory.Then load the update operation in Edits to ensure the metadata information in the memory is up-to-date and synchronized. It can be simply seen that when the NameNode starts, the Fsimage and Edits files will be merged.
Now we can get a preliminary understanding of the data update process of NameNode through this pic.
Step 1: After starting the NameNode format for the first time, create the Fsimage and Edits files. If it is not the first startup, directly load the edit log and image files into memory.
Step 2: A request from a client to add, delete, or modify metadata.
Step 3: Record the operation log and update the rolling log.
Step 4: Operates on metadata in memory.
HOW SecondaryNameNode WORK?
In my blog HDFS’s intro, it has been emphasized that 2NN is not a backup node of NN, but assists the work of NN. Here I will explain in detail how 2NN shares the work of NN.
In NameNode work, if data is added to Edits for a long time, the file data will be too large, the efficiency will be reduced, and once the power is cut off, it will take too long to restore the metadata. Therefore, it is necessary to periodically merge FsImage and Edits. If this operation is done by the NameNode node, it will be too inefficient. Therefore, a new node SecondaryNamenode is introduced, dedicated to the merging of FsImage and Edits.
Step 1: 2NN asks NN if CheckPoint is needed and brings back the result.
Step 2: 2NN requests the execution of CheckPoint.
Step 3: NN scrolls the Edits log that is being written.
Step 4: Copy the edit log and image files before rolling to 2NN.
Step 5: 2NN loads the edit log and image files into memory and merges them.
Step 6: Generate the new image file fsimage.chkpoint.
Step 7: Copy fsimage.chkpoint to NameNode.
Step 8: NN renames fsimage.chkpoint to fsimage.
Summary
The working principle of NameNode is very cleverly designed. It not only realizes the storage of metadata and logs but also combines the advantages of memory and hard disk storage, and improves the stability of HDFS.
12 comments
2025年10月新盘 做第一批吃螃蟹的人coinsrore.com
新车新盘 嘎嘎稳 嘎嘎靠谱coinsrore.com
新车首发,新的一年,只带想赚米的人coinsrore.com
新盘 上车集合 留下 我要发发 立马进裙coinsrore.com
做了几十年的项目 我总结了最好的一个盘(纯干货)coinsrore.com
新车上路,只带前10个人coinsrore.com
新盘首开 新盘首开 征召客户!!!coinsrore.com
新项目准备上线,寻找志同道合 的合作伙伴coinsrore.com
新车即将上线 真正的项目,期待你的参与coinsrore.com
新盘新项目,不再等待,现在就是最佳上车机会!coinsrore.com
新盘新盘 这个月刚上新盘 新车第一个吃螃蟹!coinsrore.com
2025年10月新盘 做第一批吃螃蟹的人coinsrore.com
新车新盘 嘎嘎稳 嘎嘎靠谱coinsrore.com
新车首发,新的一年,只带想赚米的人coinsrore.com
新盘 上车集合 留下 我要发发 立马进裙coinsrore.com
做了几十年的项目 我总结了最好的一个盘(纯干货)coinsrore.com
新车上路,只带前10个人coinsrore.com
新盘首开 新盘首开 征召客户!!!coinsrore.com
新项目准备上线,寻找志同道合 的合作伙伴coinsrore.com
新车即将上线 真正的项目,期待你的参与coinsrore.com
新盘新项目,不再等待,现在就是最佳上车机会!coinsrore.com
新盘新盘 这个月刚上新盘 新车第一个吃螃蟹!coinsrore.com
2025年10月新盘 做第一批吃螃蟹的人coinsrore.com
新车新盘 嘎嘎稳 嘎嘎靠谱coinsrore.com
新车首发,新的一年,只带想赚米的人coinsrore.com
新盘 上车集合 留下 我要发发 立马进裙coinsrore.com
做了几十年的项目 我总结了最好的一个盘(纯干货)coinsrore.com
新车上路,只带前10个人coinsrore.com
新盘首开 新盘首开 征召客户!!!coinsrore.com
新项目准备上线,寻找志同道合的合作伙伴coinsrore.com
新车即将上线 真正的项目,期待你的参与coinsrore.com
新盘新项目,不再等待,现在就是最佳上车机会!coinsrore.com
新盘新盘 这个月刚上新盘 新车第一个吃螃蟹!coinsrore.com
做了几十年的项目 我总结了最好的一个盘(纯干货)
新盘首开 新盘首开 征召客户!!!coinsrore.com
新项目准备上线,寻找志同道合的合作伙伴coinsrore.com
这是一篇佳作,无论是从内容、语言还是结构上,都堪称完美。
字里行间流露出真挚的情感,让人感同身受,共鸣不已。
对传统与现代的融合思考颇具启发性。
哈哈哈,写的太好了https://www.cscnn.com/
想想你的文章写的特别好www.jiwenlaw.com
想想你的文章写的特别好https://www.ea55.com/