关于Hadoop中replication factor解惑

    我们在向hadoop写入文件时,这个文件的“replication”个数到底该如何控制?

    在hadoop server端,core-site.xml中有个参数为“file.replication”,同时在hdfs-site.xml中也有个“dfs.replication”,这两个参数到底谁可以决定文件的“replication”个数?

    在hadoop开发时,我们还可以在Client端配置core-site.xml和hdfs-site.xml,那么上述两个参数是否会生效呢?

    在hbase中,该如何决定replication个数?

    我最近在部署和开发时就被这么几个参数给迷惑了,hdfs-site.xml(或者hdfs-default.xml)中“dfs.replication”默认为3,core-site.xml(或者core-default.xml)中“file.replication”默认为1;对于hadoop server而言,hdfs进程将会首先加载“hdfs-default.xml”然后加载“hdfs-site.xml”,如果在hdfs-site.xml中指定了“dfs.replication”,那么此值将作为server端默认值;在此处需要提醒,“file.replication”参数值将不会发挥效果,从源码中可以看出hadoop并没有使用core-site.xml(core-default.xml)中“file.replication”参数值,因此尝试修改此值来改变hdfs的replication个数是徒劳的。

    对于hadoop Client开发而言,如果开发者没有引入自己的hdfs-site.xml文件,那么在创建文件时所使用的Configuration对象只是加载了默认配置(hdfs-default.xml,core-default.xml),因此“dfs.replication”仍然为3,基于“Client端配置优先”的策略,那么hadoop server端将会使用Client端hdfs-site.xml中的“dfs.replication”值。因此,如果开发者希望调整replication factor,唯一的方式,就是在Client端引入自己的hdfs-site.xml且调整此值,或者在FileSystem.create方法中手动指定replication个数。

    hbase从架构模式上,它在存储层面只是一个hadoop Client端;如果你希望调整hbase中数据的replication个数,我们还需要在hbase server端引入hdfs-site.xml文件,然后把这个文件放入${hbase}/conf目录下,否则hbase数据的replication将始终为3。

    此外需要提醒,在hbase开发时,在hbase Client端尝试引入“core-site.xml”和“hdfs-site.xml”来修改hdfs相关属性的方式是徒劳的,hbase Client只有引入的“hbase-site.xml”文件是有效的;如果希望在hbase中修改部分hadoop的属性,只能在hbase server端的“hbase-site.xml”中修改,或者额外的引入“core-site.xml”和“hdfs-site.xml”。

//core-default.xml
//core-site.xml
Configuration conf = new Configuration();

//ConfigUtil中将会加载:
//mapred-default.xml,mapred-site.xml
//yarn-defaut.xml,yarn-site.xml
//在初始化DistributedFileSystem时,将会加载:
//hdfs-default.xml,hdfs-site.xml
 FileSystem fs = FileSystem.get(conf);

     开发者new Configuration()操作只会导致加载“core-default.xml”和“core-site.xml”,其他的配置文件将不会加载。

    当开发者使用DistributedFileSystem API时将会导致加载“hdfs-default.xml”和“hdfs-core.xml”。其中FileSystem.get(conf)方法内部使用了ConfigUtil类额外的加载了“mapred”和“yarn”相关的配置文件,我们在开发mapreduce程序时经常使用ConfigUtil来加载其配置信息。请开发者注意。

猜你喜欢

转载自shift-alt-ctrl.iteye.com/blog/2077548