Hadoop_HDFS_API 参数的优先级

在上传操作后,发现上传的副本数量为 \(3\)​​​​ ,这是因为在 hdfs-default.xml 中默认的dfs.replication\(3\)​​

image
这其中涉及到参数的优先级

优先级hdfs-default.xml \(<\)​​​​​​​ hdfs-site.xml \(<\)​​​​​ 在项目资源目录下的配置文件 \(<\)​​ 代码里面的配置​​

修改副本数的方法:

resources 目录下创建 hdfs-site.xml 并在其中写入下面代码以修改副本数

<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<configuration>
    <property>
        <name>dfs.replication</name>>
        <value>1</value><!-- 修改副本数 -->
    </property>
</configuration>

这时,再上传一个文件就可以看到副本数变成了我们设置的数得出了 hdfs-default.xml < hdfs-site.xml的结论
image
或者在 HdfsClient.java 中的 @Before

Configuration configuration = new Configuration();

的下一行添加

configuration.set("dfs.replication","2"/*设置副本数*/);

来设置副本数,在上传一个文件测试一下
image

所以代码里面的配置优先级最高

posted @ 2021-08-05 18:27  莳曳  阅读(130)  评论(0)    收藏  举报