从Java写入HDFS时,“只能复制到0个节点而不是minReplication” [英] Writing to HDFS from Java, getting "could only be replicated to 0 nodes instead of minReplication"

查看:105
本文介绍了从Java写入HDFS时,“只能复制到0个节点而不是minReplication”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载并启动了用于CDH4的Cloudera Hadoop演示VM(运行Hadoop 2.0.0)。我正在尝试编写一个Java程序,该程序将从我的Windows 7计算机(与运行VM的机器/操作系统相同)运行。我有一个示例程序,如:

  public static void main(String [] args){
try {
Configuration conf = new Configuration();
conf.addResource(config.xml);
FileSystem fs = FileSystem.get(conf);
FSDataOutputStream fdos = fs.create(new Path(/ testing / file01.txt),true);
fdos.writeBytes(为txt文件测试文本);
fdos.flush();
fdos.close();
fs.close();
} catch(Exception e){
e.printStackTrace();
}

}

我的config.xml文件只有on property defined:fs.default.name = hdfs:// CDH4_IP:8020。



当我运行它时,出现以下异常:

  org.apache.hadoop.ipc.RemoteException(java.io.IOException):文件/testing/file01.txt只能复制到0节点而不是minReplication(= 1)。此操作中有1个数据节点正在运行,1个节点不在此范围内。 
at org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget(BlockManager.java:1322)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem。 Java的:2170)在org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock(NameNodeRpcServer.java:471

在org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock( ClientNamenodeProtocolServerSideTranslatorPB.java:297)
at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos $ ClientNamenodeProtocol $ 2.callBlockingMethod(ClientNamenodeProtocolProtos.java:44080)
at org.apache.hadoop.ipc.ProtobufRpcEngine $ Server $ ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:453)
at org.apache.hadoop.ipc.RPC $ Server.call(RPC.java:898)
at org.apache.hadoop.ipc .Server $ Handler $ 1.run(Server.java:1693)
at org.apache.hadoop.ipc.Server $ Handler $ 1.run(Server.java:1689)$ b $ at java.security.AccessControl ler.doPrivileged(Native方法)
位于javax.security.auth.Subject.doAs(Subject.java:396)
位于org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1332 )
在org.apache.hadoop.ipc.Server $ Handler.run(Server.java:1687)
在org.apache.hadoop.ipc.Client.call(Client.java:1160)
at org.apache.hadoop.ipc.ProtobufRpcEngine $ Invoker.invoke(ProtobufRpcEngine.java:202)
at $ Proxy9.addBlock(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(本地方法)
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
处的java.lang sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
。在org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:164)
处org.apache.hadoop.io反映.Method.invoke(Method.java:597)
。 retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:83)
。在$ Proxy9.addBlock(来源不明)
在org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.addBlock(ClientNamenodeProtocolTranslatorPB.java:290)
。在org.apache.hadoop.hdfs.DFSOutputStream $ DataStreamer.locateFollowingBlock(DFSOutputStream.java:1150)
在org.apache.hadoop.hdfs.DFSOutputStream $ DataStreamer.nextBlockOutputStream(DFSOutputStream.java:1003)
。在org.apache.hadoop.hdfs.DFSOutputStream $ DataStreamer.run(DFSOutputStream.java:463)

我浏览过互联网,这发生在磁盘空间不足的情况下,但当我运行hdfs dfsadmin -report时,情况并非如此。我收到以下内容:

 已配置的容量:25197727744(23.47 GB)
目前容量:21771988992(20.28 GB)
剩余的DFS:21770715136(20.28 GB)
使用的DFS:1273856(1.21 MB)
已使用DFS%:0.01%
在复制块下:0
具有损坏副本的块:0
Missi ng blocks:0

-------------------------------------- -----------
Datanodes可用:1(总共1个,死了0个)

实时datanodes:
名称:127.0.0.1:50010(localhost .localdomain)
主机名:localhost.localdomain
停用状态:正常
已配置容量:25197727744(23.47 GB)
已用DFS:1273856(1.21 MB)
非DFS使用:3425738752(3.19 GB)
剩余的DFS:21770715136(20.28 GB)
使用的DFS百分比:0.01%
剩余的DFS百分比:86.4%
最后一次联系:Fri Jan 11 17 :30:56 EST 201323 EST 2013

我也可以在VM中运行此代码。我不确定问题是什么或如何解决问题。这是我第一次使用hadoop,所以我可能错过了一些基本的东西。任何想法?

更新



我在日志中看到的唯一一个异常类似于获取客户端:

  java.io.IOException:文件/testing/file01.txt只能复制到0个节点上minReplication(= 1)。此操作中有1个数据节点正在运行,1个节点不在此范围内。 
at org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget(BlockManager.java:1322)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem。 Java的:2170)在org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock(NameNodeRpcServer.java:471

在org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock( ClientNamenodeProtocolServerSideTranslatorPB.java:297)
at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos $ ClientNamenodeProtocol $ 2.callBlockingMethod(ClientNamenodeProtocolProtos.java:44080)
at org.apache.hadoop.ipc.ProtobufRpcEngine $ Server $ ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:453)
at org.apache.hadoop.ipc.RPC $ Server.call(RPC.java:898)
at org.apache.hadoop.ipc .Server $ Handler $ 1.run(Server.java:1693)
at org.apache.hadoop.ipc.Server $ Handler $ 1.run(Server.java:1689)$ b $ at java.security.AccessControl ler.doPrivileged(Native方法)
位于javax.security.auth.Subject.doAs(Subject.java:396)
位于org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1332 )
at org.apache.hadoop.ipc.Server $ Handler.run(Server.java:1687)

我试着改变数据目录(/ var / lib / hadoop-hdfs / cache / hdfs / dfs / data)的权限,但没有修复它(我竟然给了所有人完全访问权限)。

我注意到,当我通过HUE web应用程序浏览HDFS时,我发现文件夹结构已经创建,并且该文件确实存在,但它是空的。我尝试通过使用

  FSDataOutputStream fdos = fs.create(new Path(testing / file04 .txt),true); 

而不是

  FSDataOutputStream fdos = fs.create(new Path(/ testing / file04.txt),true); 

这使得文件路径成为/user/dharris/testing/file04.txt('dharris '是我的Windows用户)。但是,这给了我同样的错误。

解决方案

我得到了同样的问题。在这种情况下,问题的关键是出现错误消息。

在此操作中,有1个数据节点正在运行,1个节点不在此列。



这意味着您的hdfs-client无法使用50010端口连接到您的datanode。
在连接到hdfs namenode时,您可以获得datanode的状态。但是,您的hdfs客户端无法连接到您的datanode。


$ b (在hdfs中,名称节点管理文件目录和datanode,如果hdfs-client连接到namnenode ,它会找到一个包含数据的datanode的目标文件路径和地址,然后hdfs-client将和datanode进行通信(你可以使用netstat来检查这些数据节点的uri,因为hdfs-client将尝试使用datanode通过地址通知namenode)



I 通过以下方式解决了问题:


  1. 在防火墙中打开50010端口。

  2. 添加房产dfs.client.use.datanode.hostname,true

  3. 将主机名添加到我的客户端PC中的hostfile中。

对不起我的英语不好。


I’ve downloaded and started up Cloudera's Hadoop Demo VM for CDH4 (running Hadoop 2.0.0). I’m trying to write a Java program that will run from my windows 7 machine (The same machine/OS that the VM is running in). I have a sample program like:

public static void main(String[] args) {
    try{
        Configuration conf = new Configuration();
        conf.addResource("config.xml");
        FileSystem fs = FileSystem.get(conf);
        FSDataOutputStream fdos=fs.create(new Path("/testing/file01.txt"), true);
        fdos.writeBytes("Test text for the txt file");
        fdos.flush();
        fdos.close();
        fs.close();
    }catch(Exception e){
        e.printStackTrace();
    }

}

My config.xml file only has on property defined: fs.default.name=hdfs://CDH4_IP:8020.

When I run it I’m getting the following exception:

org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /testing/file01.txt could only be replicated to 0 nodes instead of minReplication (=1).  There are 1 datanode(s) running and 1 node(s) are excluded in this operation.
    at org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget(BlockManager.java:1322)
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:2170)
    at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock(NameNodeRpcServer.java:471)
    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock(ClientNamenodeProtocolServerSideTranslatorPB.java:297)
    at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java:44080)
    at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:453)
    at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:898)
    at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1693)
    at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1689)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:396)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1332)
    at org.apache.hadoop.ipc.Server$Handler.run(Server.java:1687)
    at org.apache.hadoop.ipc.Client.call(Client.java:1160)
    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:202)
    at $Proxy9.addBlock(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:164)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:83)
    at $Proxy9.addBlock(Unknown Source)
    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.addBlock(ClientNamenodeProtocolTranslatorPB.java:290)
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.locateFollowingBlock(DFSOutputStream.java:1150)
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.nextBlockOutputStream(DFSOutputStream.java:1003)
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.run(DFSOutputStream.java:463)

I’ve looked around the internet and it seem that this happens when disk space is low but that’s not the case for me when I run "hdfs dfsadmin -report" I get the following:

Configured Capacity: 25197727744 (23.47 GB)
Present Capacity: 21771988992 (20.28 GB)
DFS Remaining: 21770715136 (20.28 GB)
DFS Used: 1273856 (1.21 MB)
DFS Used%: 0.01%
Under replicated blocks: 0
Blocks with corrupt replicas: 0
Missing blocks: 0

-------------------------------------------------
Datanodes available: 1 (1 total, 0 dead)

Live datanodes:
Name: 127.0.0.1:50010 (localhost.localdomain)
Hostname: localhost.localdomain
Decommission Status : Normal
Configured Capacity: 25197727744 (23.47 GB)
DFS Used: 1273856 (1.21 MB)
Non DFS Used: 3425738752 (3.19 GB)
DFS Remaining: 21770715136 (20.28 GB)
DFS Used%: 0.01%
DFS Remaining%: 86.4%
Last contact: Fri Jan 11 17:30:56 EST 201323 EST 2013

I can also run this code just fine from with in the VM. I’m not sure what the problem is or how to fix it. This is my first time using hadoop so I’m probably missing something basic. Any ideas?

Update

The only thing I see in the logs is an exception similar to the one on get on the client:

java.io.IOException: File /testing/file01.txt could only be replicated to 0 nodes instead of minReplication (=1).  There are 1 datanode(s) running and 1 node(s) are excluded in this operation.
    at org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget(BlockManager.java:1322)
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:2170)
    at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock(NameNodeRpcServer.java:471)
    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock(ClientNamenodeProtocolServerSideTranslatorPB.java:297)
    at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java:44080)
    at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:453)
    at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:898)
    at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1693)
    at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1689)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:396)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1332)
    at org.apache.hadoop.ipc.Server$Handler.run(Server.java:1687)

I tried changing the permissions on the data directory (/var/lib/hadoop-hdfs/cache/hdfs/dfs/data) and that didn't fix it (I went so far as giving full access to everyone).

I notice that when I'm browsing the HDFS via the HUE web app I see that the folder structure was created and that the file does exist but it is empty. I tried putting the file under the default user directory by using

FSDataOutputStream fdos=fs.create(new Path("testing/file04.txt"), true); 

instead of

FSDataOutputStream fdos=fs.create(new Path("/testing/file04.txt"), true);

Which makes the file path become "/user/dharris/testing/file04.txt" ('dharris' is my windows user). But that gave me the same kind of error.

解决方案

I got a same problem.
In my case, a key of the problem was following error message.
There are 1 datanode(s) running and 1 node(s) are excluded in this operation.

It means that your hdfs-client couldn't connect to your datanode with 50010 port. As you connected to hdfs namenode, you could got a datanode's status. But, your hdfs-client would failed to connect to your datanode.

(In hdfs, a namenode manages file directories, and datanodes. If hdfs-client connect to a namnenode, it will find a target file path and address of datanode that have the data. Then hdfs-client will communicate with datanode. (You can check those datanode uri by using netstat. because, hdfs-client will be trying to communicate with datanodes using by address informed by namenode)

I solved that problem by:

  1. opening 50010 port in a firewall.
  2. adding propertiy "dfs.client.use.datanode.hostname", "true"
  3. adding hostname to hostfile in my client PC.

I'm sorry for my poor English skill.

这篇关于从Java写入HDFS时,“只能复制到0个节点而不是minReplication”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆