Hadoop - HDFS Namenode 元数据 - FSImage

Posted

技术标签:

【中文标题】Hadoop - HDFS Namenode 元数据 - FSImage【英文标题】:Hadoop - HDFS Namenode metadata - FSImage 【发布时间】:2014-09-30 13:04:39 【问题描述】:

我知道在主节点中,我们有名称节点,它在两个文件中维护元数据。一个是 FSImage,另一个是编辑日志。 所以这个 FSImage 是在 hadoop 系统启动时初始加载的,这个 FSImage 包含了集群的目录结构和存储的数据。然后,对于每一个发生的事务,编辑日志文件都会更新。

我的问题如下:

    这些只是包含所有信息(FSImage 和 EditLogs)的文件还是还有更多? 这是否意味着 FSImage 文件只会被写入一次? 如果是,那么为什么总是复制到辅助名称节点?不是增加了要完成的任务吗? 假设我在 hdfs 中添加或删除了一个新文件;那么这个 FSImage 不会更新吗?

【问题讨论】:

我认为***.com/questions/24288942/… 本身回答了你的一些问题。 【参考方案1】:

要理解这一点,我们必须在 Hadoop 运行时,一步一步详细了解它

    加载 FSImage 后的 Namenode 拥有数据在内存中存储位置的完整快照。

    有交易进来,信息存储在编辑日志中。

    定期,默认每小时检查点节点/辅助名称节点检索日志,并将它们与最新的 fsimage 合并,并将数据保留为检查点。 此时nn内存中有图片,清空编辑日志并将最新的checkpoint作为图片存储在snn/cn上。

回答你的问题。

    是的,只有两个文件

    SNN/CN 上的 fsimage 会定期更新。当检查点被导入时,NN 上的 fsimage 将被更新。至少在重新启动时应该会发生这种情况。

    将editlog 合并到fsimage 是一项代价高昂的操作。它需要在名称节点中进入安全模式才能合并数据。在这样的环境下这是不可能的

    删除和写入一样是日志,所以它会存储在编辑日志中

【讨论】:

【参考方案2】:
    1) Yes only these two files are there .

    2) This is true for name node .

    3) It is copied to secondary name node for persistent storage , things would work fine un till name node is up ,lets say you have done so many changes like creating directories ,files ,putting the data to hdfs and so on so during run time this information is directly loaded into the memory but what if  namenode goes down so what ever new meta information was there which is not embedded  current fsimage  ,it would get lost permanently because when ever your system would come up it would load the fsimage into memory since its the old fsimage it won't have new changes . With this secondary name node we are preserving this changes in edit.log and finally edit.log file used for fsimage and new fsimage can be replaced with old one .
    4) process is when ever meta data gets changes ,this event gets written in edit.log file and after some specified interval these logs copied to secondary name node when their size gets too big then edit.log information is flushed into the form of fsimage. 
 current fsimage  would not get updated with addition or deletion of file ,these changes will directly cater in memory.

【讨论】:

【参考方案3】:

    是的,只有这两个文件包含集群文件系统信息

    没有。每次重新启动 Name 节点时,FSImage 都会写入磁盘,并且在每个检查点 SNN 都会将 FSImage 写入磁盘

    在繁忙的集群上,EditLog 会增长得非常快。如果编辑日志非常大,那么下次重新启动 NN 将需要更长的时间。 SNN 会定期合并 EDITlog 和 FSImage。 SNN 还将作为 FSImage 的备份,以防您的 NN 磁盘出现故障。

    是的。 FSImage 将在主内存中而不是在磁盘中进行更新。当时 EDITlog 将使用新事务在磁盘上更新

【讨论】:

以上是关于Hadoop - HDFS Namenode 元数据 - FSImage的主要内容,如果未能解决你的问题,请参考以下文章

如何配置hdfs namenode的内存

ERROR org.apache.hadoop.hdfs.server.namenode.NameNode: Failed to start namenode.

无法找到或加载主类 org.apache.hadoop.hdfs.server.namenode.Namenode

hadoop中HDFS的NameNode原理

hadoop错误FATAL org.apache.hadoop.hdfs.server.namenode.NameNode Exception in namenode join java.io.IOE

Hadoop之联邦HDFS