hadoop异常: java.io.EOFException: Unexpected end of input stream

执行hadoop任务时报错:

2019-06-05 03:23:36,173 INFO [main] org.apache.hadoop.mapred.MapTask: Processing split: Paths:/flume/nginx/app1/2019-06-05/00/app1@flume23_10003_4.1559665890953.gz:0+0,/flume/nginx/app2/2019-06-05/00/app2@flume174_10003_9.1559665804394.gz:0+307548
2019-06-05 03:23:36,257 WARN [main] org.apache.hadoop.security.UserGroupInformation: PriviledgedActionException as:kwang (auth:SIMPLE) cause:java.io.EOFException: Unexpected end of input stream
2019-06-05 03:23:36,258 WARN [main] org.apache.hadoop.mapred.YarnChild: Exception running child : java.io.EOFException: Unexpected end of input stream 
    at org.apache.hadoop.io.compress.DecompressorStream.decompress(DecompressorStream.java:165)
    at org.apache.hadoop.io.compress.DecompressorStream.read(DecompressorStream.java:105)
    at java.io.InputStream.read(InputStream.java:101)
    at org.apache.hadoop.util.LineReader.fillBuffer(LineReader.java:180)
    at org.apache.hadoop.util.LineReader.readDefaultLine(LineReader.java:216)
    at org.apache.hadoop.util.LineReader.readLine(LineReader.java:174)
    at org.apache.hadoop.mapreduce.lib.input.LineRecordReader.skipUtfByteOrderMark(LineRecordReader.java:144)
    at org.apache.hadoop.mapreduce.lib.input.LineRecordReader.nextKeyValue(LineRecordReader.java:184)
    at org.apache.hadoop.mapreduce.lib.input.CombineFileRecordReaderWrapper.nextKeyValue(CombineFileRecordReaderWrapper.java:90)
    at org.apache.hadoop.mapreduce.lib.input.CombineFileRecordReader.nextKeyValue(CombineFileRecordReader.java:69)
    at org.apache.hadoop.mapred.MapTask$NewTrackingRecordReader.nextKeyValue(MapTask.java:562)
    at org.apache.hadoop.mapreduce.task.MapContextImpl.nextKeyValue(MapContextImpl.java:80)
    at org.apache.hadoop.mapreduce.lib.map.WrappedMapper$Context.nextKeyValue(WrappedMapper.java:91)
    at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:144)
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:793)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
    at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)
    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:1924)
    at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)

产生原因:

以上报错原因基本都是由于HDFS上的文件异常结束导致的,通过查看log,发现/flume/nginx/app1/2019-06-05/00/app1@flume23_10003_4.1559665890953.gz:0+0 这个文件的大小为0字节。要理解空文件的产生,先需要清楚集群flume采集日志的逻辑,集群中采用flume采集到日志写入到HDFS,采集过程中flume会先新建一个*.gz.tmp文件,flume持续的向*.gz.tmp文件中追加数据,在写周期到达时将*.gz.tmp重命名为*.gz,而空文件产生的原因是flume新建了*.gz.tmp文件后,没有新数据产生,重命名后文件大小为空。

解决办法:
将空gz文件删除后重新运行任务即可。

 

还有另一种原因,当设置了如下参数对文件进行分割切片时,导致部分文件为空文件,从而解析过程中出现异常。当然,这种原因取决于文件的原始格式是否可压缩,像gz、snappy、lzo文件是不可分割的,设置如下参数就不会出现以上报错,像orc文件是可分割的,设置如下参数可能会出现以上异常。

-Dmapreduce.input.fileinputformat.split.minsize=134217728 -Dmapreduce.input.fileinputformat.split.maxsize=512000000

 

【参考资料】

[1]. 菜菜光, hadoop Unexpected end of input stream 错误.

上一篇:python-unexpected content storage modification出错


下一篇:python报"IndentationError: unexpected indent"