hdfs中的NameNode,SecondaryNameNode,BackupNode

来源:互联网 发布:java无损压缩图片 编辑:程序博客网 时间:2024/05/16 11:04

NameNode:暂且叫它为元数据结点。

它实现了NamenodeProtocols中的接口,而该接口分别有三个父类:

ClientProtocol,与客户端的通信。

DatanodeProtocol,DN的通信。

NamenodeProtocol,BNSNN的通信。

主要有二大功能:

1.   文件元信息的管理,由FSNamesystem类完成,主要提供了文件的相关操作,将文件信息保存到内存中,同时将操作日志保存到日志文件中。

2.   数据块的管理,由BlockManager类完成,负责保存数据块的相关信息,以及对数据块的复制,监测工作等。

SecondaryNameNode第二个数据结点,主要是备份主结点的文件信息,不备份数据块的信息,另外,它还会将fsimageedits日志合并成一个新的fsimage,再将新的fsimage上传给NN,这样使得NN中的edits不会一直是递增的,可以使得当NN挂了后,能够快速的恢复起来

它的主要工作在这个doCheckpoint()方法中,每隔一段时间会启动检查点一次,是由两个配置参数来控制的:

fs.checkpoint.period,指定连续两次检查点的最大时间间隔, 默认值是1小时。

fs.checkpoint.size定义了edits日志文件的最大值,一旦超过这个值会导致强制执行检查点(即使没到检查点的最大时间间隔)。默认值是64MB

void doCheckpoint() throws IOException {

    //Do the required initialization of the merge work area.

    startCheckpoint();

    // Tell the namenode to start loggingtransactions in a new edit file

    //Returns a token that would be used to upload the merged image.

    CheckpointSignature sig = namenode.rollEditLog();

    //error simulation code for junit test

    if (ErrorSimulator.getErrorSimulation(0)){

      throw new IOException("Simulating error0 " +

                            "after creating edits.new");

    }

    downloadCheckpointFiles(sig);   //Fetch fsimage and edits

    doMerge(sig);                   // Do the merge

    //

    //Upload the new image into the NameNode. Then tell the Namenode

    //to make this new uploaded image as the most current image.

    //

    putFSImage(sig);

    //error simulation code for junit test

    if (ErrorSimulator.getErrorSimulation(1)){

      throw new IOException("Simulating error1 " +

                            "after uploading new image toNameNode");

    }

    namenode.rollFsImage();

    checkpointImage.endCheckpoint();

    LOG.warn("Checkpoint done. New Image Size:"

             + checkpointImage.getFsImageName().length());

  }

BackupNode备份结点。这个结点的模式有点像mysql中的主从结点复制功能,NN可以实时的将日志传送给BN,而SNN是每隔一段时间去NN下载fsimageedits文件,而BN是实时的得到操作日志,然后将操作合并到fsimage里。

NN里提供了二个日志流接口:EditLogOutputStreamEditLogInputStream。即当NN有日志时,不仅会写一份到本地edits的日志文件,同时会向BN的网络流中写一份,当流缓冲达到阀值时,将会写入到BN结点上,BN收到后就会进行合并操作,这样来完成低延迟的日志复制功能。

总结:

当前的备份结点都是冷备份,所以还需要实现热备份,使得NN挂了后,从结点自动的升为主结点来提供服务。

NN的效率问题:NN的文件过多导致内存消耗问题,NN中文件锁问题,NN的启动时间。

 

参考资料:

http://jiajun.javaeye.com/blog/809125

http://blog.csdn.net/shirdrn/archive/2009/10/07/4639345.aspx

http://hadoop.apache.org/common/docs/r0.18.2/cn/hdfs_user_guide.html#Secondary+NameNode

https://issues.apache.org/jira/browse/HADOOP-4539

http://datasearch.ruc.edu.cn/~boliangfeng/blog/?p=551