如何附加到极小群集(3 个节点或更少)上的 hdfs 文件
我正在尝试附加到单节点集群上的hdfs上的文件。我也在2节点群集上尝试过,但得到了相同的异常。
在 hdfs-site 中,我已设置为 1。如果我设置为“我得到以下异常”dfs.replication
dfs.client.block.write.replace-datanode-on-failure.policy
DEFAULT
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=[10.10.37.16:50010], original=[10.10.37.16: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-default中进行配置.xml对于极小的集群(3个或更少),并设置为“我得到以下异常:dfs.client.block.write.replace-datanode-on-failure.policy
NEVER
org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hdfs.server.namenode.SafeModeException): Cannot append to file/user/hadoop/test. Name node is in safe mode.
The reported blocks 1277 has reached the threshold 1.0000 of total blocks 1277. The number of live datanodes 1 has reached the minimum number 0. In safe mode extension. Safe mode will be turned off automatically in 3 seconds.
以下是我尝试追加的方法:
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://MY-MACHINE:8020/user/hadoop");
conf.set("hadoop.job.ugi", "hadoop");
FileSystem fs = FileSystem.get(conf);
OutputStream out = fs.append(new Path("/user/hadoop/test"));
PrintWriter writer = new PrintWriter(out);
writer.print("hello world");
writer.close();
代码中是否有我做错了什么?也许,配置中缺少某些内容?任何帮助将不胜感激!
编辑
即使它设置为 ,当我检查文件的状态通过dfs.replication
1
FileStatus[] status = fs.listStatus(new Path("/user/hadoop"));
我发现 设置为 。我不认为这是问题所在,因为当我将值更改为时,我得到了一个相关的异常。因此,显然它确实服从了值,但为了安全起见,有没有办法更改每个文件的值?status[i].block_replication
3
dfs.replication
0
dfs.replication
block_replication