我正在尝试使用scala文件系统Api将文件写入HDFS,在客户端上获取以下错误以及在hadoop日志上也是如此:
文件/user/testuser/test.txt只能复制到0个节点 而不是minReplication(= 1)。有1个datanode正在运行,1个 此操作中不包括节点。
testuser具有读取,写入和执行权限。我检查了ambari上的hdfs并启动并运行,不确定为什么会出现此错误
在谷歌出错后我已经尝试停止所有服务,格式化名称节点并启动所有服务等,如下面的链接所示
Writing to HDFS could only be replicated to 0 nodes instead of minReplication (=1)
我仍然有同样的错误。任何建议我做错了什么,我是hadoop的新手,所以任何建议都将受到赞赏。
以下是我使用的scala代码
def write(uri: String, filePath: String, data: Array[Byte]) = {
System.setProperty("HADOOP_USER_NAME", "usernamehere")
val path = new Path(filePath)
val conf = new Configuration()
conf.set("fs.defaultFS", uri)
conf.set("dfs.client.use.datanode.hostname", "true");
conf.addResource(new Path("/path/core-site.xml"));
conf.addResource(new Path("/path/hdfs-site.xml"));
val fs = FileSystem.get(conf)
val os = fs.create(path)
fs.setPermission(path,FsPermission.getDefault)
val out = new BufferedOutputStream(os)
println(data.length)
out.write(data)
out.flush()
out.close()
fs.close()
}
由于
答案 0 :(得分:0)
要将任何文件写入HDFS,您只需使用'use strict'
等hdfs
命令。
假设您使用带scala的Spark,那么您需要使用Spark文件编写命令。
copyFromLocal
HDFS可以理解上述命令,以根据复制因子复制数据。但是,如果在HDFS中使用scala文件系统api,则会导致问题,因为scala无法理解复制,数据块,分区等hdfs功能。