程序如:
1.报错类似下面的信息:
org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException): Failed to create file [/user/hive/warehouse/test.db/incr_iot_report_gsh_1/odq_changedate=2017-10-19/incr_000000_Meter_0] for [DFSClient_NONMAPREDUCE_1573234124_13] for client [10.2.65.201], because this file is already being created by [DFSClient_NONMAPREDUCE_-1394763282_13] on [10.2.65.201]
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.recoverLeaseInternal(FSNamesystem.java:3187)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.appendFileInternal(FSNamesystem.java:2968)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.appendFileInt(FSNamesystem.java:3252)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.appendFile(FSNamesystem.java:3216)
at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.append(NameNodeRpcServer.java:618)
at org.apache.hadoop.hdfs.server.namenode.AuthorizationProviderProxyClientProtocol.append(AuthorizationProviderProxyClientProtocol.java:126)
at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.append(ClientNamenodeProtocolServerSideTranslatorPB.java:422)
at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)
分析:一般性是多线程造成的文件锁问题,说白点就是一个程序已经打开了这个目录下的这个文件,突然又有一个程序去打开这个文件,才会报如上错误
2.提示文件已经被一个client创建,try again 。。。也是因为文件被多个程序使用,如下错误
org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException): Failed to create file [/user/hive/warehouse/test.db/incr_iot_report_gsh_1/odq_changedate=2017-10-19/incr_000000_Meter_0] for [DFSClient_NONMAPREDUCE_76714100_13] for client [10.2.65.201], because this file is already being created by [DFSClient_NONMAPREDUCE_1322133037_13] on [10.2.65.201]
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.recoverLeaseInternal(FSNamesystem.java:3187)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.appendFileInternal(FSNamesystem.java:2968)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.appendFileInt(FSNamesystem.java:3252)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.appendFile(FSNamesystem.java:3216)
at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.append(NameNodeRpcServer.java:618)
at org.apache.hadoop.hdfs.server.namenode.AuthorizationProviderProxyClientProtocol.append(AuthorizationProviderProxyClientProtocol.java:126)
at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.append(ClientNamenodeProtocolServerSideTranslatorPB.java:422)
at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)
at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:617)
at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:1073)
处理如上错误可以使用hdfs参数进项控制:代码如下
重新初始化hdfs的句柄
1、从HDFS中读取数据
2、写HDFS
3、遍历目录 获取文件 全路径
4、追加数据 append
***********************************************************************************************************************************************
***********************************************************************************************************************************************
异常信息
1、Exception in thread "main" java.lang.IllegalArgumentException: java.net.UnknownHostException: ns6
原因是没有加载hdfs的配置信息,需要添加下面的代码:
如果配置了环境变量可以在不同的机器上使用: