【问题标题】:How to append to created file on HDFS如何附加到 HDFS 上创建的文件
【发布时间】:2014-09-03 08:25:38
【问题描述】:

我在附加到我创建的文件时遇到问题。我对手动上传到 HDFS 的文件没有这样的问题。文件上传和创建有什么区别?

要追加和创建我使用下面的代码

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class Test {
    public static final String hdfs = "hdfs://192.168.15.62:8020";
    public static final String hpath = "/user/horton/wko/test.log";
    public static void main(String[] args) throws IOException {
            Configuration conf = new Configuration();
            conf.set("fs.defaultFS", hdfs);
            conf.set("hadoop.job.ugi", "hdfs");
            FileSystem fs = FileSystem.get(conf);
            Path filenamePath = new Path(hpath);
            //FSDataOutputStream out = fs.create(filenamePath);
            FSDataOutputStream out = fs.append(filenamePath);
            out.writeUTF("TEST\n");
            out.close();
        }
}

如果追加,我遇到了这样的异常:

Exception in thread "main" java.io.IOException: Failed to replace a bad datanode on   the existing pipeline due to no more good datanodes being available to try. (Nodes: current=[192.168.15.62:50010], original=[192.168.15.62:50010]). The current failed datanode replacement policy is DEFAULT, and a client may configure this via 'dfs.client.block.write.replace-datanode-on-failure.policy' in its configuration.

【问题讨论】:

  • 您是否在 hdfs-site.xml 中将 dfs.support.append 设置为 true ?另外,你有多少个数据节点,复制因子是多少?

标签: hadoop hdfs


【解决方案1】:

我有一个类似的问题,修复了添加conf.set("dfs.replication", "1")

就我而言,集群中只有一个节点,即使dfs.replicationhdfs-site.xml 中设置为1,它仍然使用默认值3

请注意,一旦文件的块被写入第一个节点,Hadoop 将尝试复制它们,并且由于复制的默认值为3,如果您只有一个节点,它将无法访问其他节点节点集群。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 2022-10-15
    • 2016-12-26
    • 2016-09-23
    • 2010-11-12
    相关资源
    最近更新 更多