org.apache.hadoop.ipc.RemoteException错误

时间:2015-06-24 05:54:59

标签: java hadoop

我想将一些文件从Windows机器复制到在SingleNode上运行在ubuntu 14.04.02上的hadoop。这是用于此目的的代码;

Configuration configuration = new Configuration();
configuration.addResource(new Path("/core-site.xml"));
configuration.addResource(new Path("/mapred-site.xml"));
FileSystem hdfs = FileSystem.get(configuration);

Path homeDirectory = hdfs.getHomeDirectory();
System.out.println("Home directory\t\t: " + homeDirectory);
Path workingDirectory = hdfs.getWorkingDirectory();
System.out.println("Working directory\t: " + workingDirectory);
Path dataFolderPath = new Path("/ali");
dataFolderPath = Path.mergePaths(workingDirectory, dataFolderPath);
System.out.println("Data Folder Path\t: " + dataFolderPath);

if(hdfs.exists(dataFolderPath)){
    System.out.println("Data Folder Path exists.\nExisting path deleting...");
    hdfs.delete(dataFolderPath, true);
}
System.out.println("Data Folder Path creating...");

Path localFilePath = new Path("D:\\text.txt");
Path hdfsFilePath = new Path(dataFolderPath + "/text.txt");

System.out.println("Copying \'" + localFilePath + "\' to \'" + hdfsFilePath + "\'...");

hdfs.copyFromLocalFile(localFilePath, hdfsFilePath);

System.out.println("All completed");

这是我得到的控制台日志;

Home directory      : hdfs://10.0.0.14:9000/user/ademir
Working directory   : hdfs://10.0.0.14:9000/user/ademir
Data Folder Path    : hdfs://10.0.0.14:9000/user/ademir/ali
Data Folder Path exists.
Existing path deleting...
Data Folder Path creating...
Copying 'D:/text.txt' to 'hdfs://10.0.0.14:9000/user/ademir/ali/text.txt'...
org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /user/ademir/ali/text.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.chooseTarget4NewBlock(BlockManager.java:1549)
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:3200)
    at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock(NameNodeRpcServer.java:641)
    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock(ClientNamenodeProtocolServerSideTranslatorPB.java:482)
    at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)
    at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:619)
    at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:962)
    at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2039)
    at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2035)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:415)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1628)
    at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2033)

    at org.apache.hadoop.ipc.Client.call(Client.java:1468)
    at org.apache.hadoop.ipc.Client.call(Client.java:1399)
    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:232)
    at com.sun.proxy.$Proxy14.addBlock(Unknown Source)
    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.addBlock(ClientNamenodeProtocolTranslatorPB.java:399)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:187)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102)
    at com.sun.proxy.$Proxy15.addBlock(Unknown Source)
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.locateFollowingBlock(DFSOutputStream.java:1532)
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.nextBlockOutputStream(DFSOutputStream.java:1349)
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.run(DFSOutputStream.java:588)

当我在Hadoop运行的机器上执行此操作时,它完成没有任何问题,但在本地网络中的Windows机器上,这是我得到的结果。

此实现有什么问题或者这个问题的根源是什么?如何解决呢?

感谢您的帮助。

注意:Hadoop版本是2.6.0。我也是Hadoop的初学者。

2 个答案:

答案 0 :(得分:1)

这提供了链接提供更多可能的答案 HDFS error: could only be replicated to 0 nodes, instead of 1

特别是这个答案: 这是您的问题 - 客户端无法与Datanode通信。因为客户端为Datanode接收的IP是内部IP而不是公共IP。看看这个 ... 这是您的问题 - 客户端无法与Datanode通信。因为客户端为Datanode接收的IP是内部IP而不是公共IP。看看这个

您可以看到您的datanode也标记为已排除

答案 1 :(得分:0)

类似的问题:HDFS error: could only be replicated to 0 nodes, instead of 1。看看它是否有帮助。

同时检查您的hosts文件,看看您的Windows机器是否可以访问您的datanode和namenode。即IP:PORT是可访问的。请注意,hadoop不是通过名称节点直接复制到数据节点