我在附加到由我创建的文件时遇到问题。我没有这样的文件是手动上传到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.
1条答案
按热度按时间qpgpyjmq1#
我有一个类似的问题,修复添加
conf.set("dfs.replication", "1")
.在我的例子中,集群中只有一个节点
dfs.replication
已设置为1
在hdfs-site.xml
,它仍然使用默认值3
.注意,hadoop将尝试在第一个节点中写入文件块后立即复制这些块,因为复制的默认值是
3
,如果您只有一个节点群集,它将无法访问其他节点。