hdfs 追加写入文件报错
- 问题描述 :
当通过 java api 向hdfs追加写入文件时如果重复调用FileSystem 的append()方法获取输出流,可能会报下面的错误,类似错误如下:
Failed to APPEND_FILE /data/realtime-file for DFSClient_NONMAPREDUCE_-61362846_34 on 192.168.70.200 because lease recovery is in progress. Try again later.
- 解决方法在新建Configuration 中加入如下配置(主要是dfs.client.block.write.replace-datanode-on-failure.policy和dfs.client.block.write.replace-datanode-on-failure.enable)
Configuration conf = new Configuration();
conf.set("fs.defaultFS", HDFS_PATH);
conf.set("fs.hdfs.impl", DistributedFileSystem.class.getName());
conf.set("dfs.client.block.write.replace-datanode-on-failure.policy", "NEVER");
conf.set("dfs.client.block.write.replace-datanode-on-failure.enable", "true");
如果以上配置不行,可能还需要在部署端的hdfs-site.xml 中加入配置
<property>
<name>dfs.client.block.write.replace-datanode-on-failure.enable</name>
<value>true</value>
</property>
<property>
<name>dfs.client.block.write.replace-datanode-on-failure.policy</name>
<value>NEVER</value>
</property>
备注: 如果部署相关写入jar包到服务器,需要在对应的服务上配置hadoop环境(不需要安装)

浙公网安备 33010602011771号