wanghiu 发表于 2018-6-4 09:52:37

HDFS文件数据丢失重写,校验失败

hadoop2.6.0,写数据用的是java的文件追加,就是所有的数据都写到一个文件里:
IOUtils.copyBytes(in, fo, 4096, true);
读数据用的是pyspark:
SparkContext.textFile("");
目前的现象是:用java读写都没有问题,但是用spark读数据,当文件大小到一定的数量时,就报错:
18/06/02 09:36:10 ERROR Executor: Exception in task 1.0 in stage 4094.0 (TID 8189)
org.apache.hadoop.fs.ChecksumException: Checksum error: /es/alertResult.txt at 29831168 exp: 1752925544 got: -1744680078

hadoop使用默认选项,文件达到21万行左右,就报这个错误,修改了dfs.blocksize和io.file.buffer.size后,文件达到55万行左右就报错。

在此诚心请教各位大牛,有没有遇到过类似问题的?请赐教!

wanghiu 发表于 2018-6-4 10:01:53

@pig2 @howtodown 有没有空帮忙看看

wanghiu 发表于 2018-6-4 10:18:59

具体的错误信息:
18/06/02 09:36:10 ERROR Executor: Exception in task 1.0 in stage 4094.0 (TID 8189)
org.apache.hadoop.fs.ChecksumException: Checksum error: /es/alertResult.txt at 29831168 exp: 1752925544 got: -1744680078
        at org.apache.hadoop.util.DataChecksum.verifyChunkedSums(DataChecksum.java:325)
        at org.apache.hadoop.hdfs.RemoteBlockReader2.readNextPacket(RemoteBlockReader2.java:216)
        at org.apache.hadoop.hdfs.RemoteBlockReader2.read(RemoteBlockReader2.java:146)
        at org.apache.hadoop.hdfs.DFSInputStream$ByteArrayStrategy.doRead(DFSInputStream.java:693)
        at org.apache.hadoop.hdfs.DFSInputStream.readBuffer(DFSInputStream.java:749)
        at org.apache.hadoop.hdfs.DFSInputStream.readWithStrategy(DFSInputStream.java:806)
        at org.apache.hadoop.hdfs.DFSInputStream.read(DFSInputStream.java:847)
        at java.io.DataInputStream.read(DataInputStream.java:100)
        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.mapred.LineRecordReader.next(LineRecordReader.java:246)
        at org.apache.hadoop.mapred.LineRecordReader.next(LineRecordReader.java:47)
        at org.apache.spark.rdd.HadoopRDD$$anon$1.getNext(HadoopRDD.scala:246)
        at org.apache.spark.rdd.HadoopRDD$$anon$1.getNext(HadoopRDD.scala:208)
        at org.apache.spark.util.NextIterator.hasNext(NextIterator.scala:73)
        at org.apache.spark.InterruptibleIterator.hasNext(InterruptibleIterator.scala:39)
        at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327)
        at scala.collection.Iterator$class.foreach(Iterator.scala:727)
        at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
        at org.apache.spark.api.python.PythonRDD$.writeIteratorToStream(PythonRDD.scala:452)
        at org.apache.spark.api.python.PythonRunner$WriterThread$$anonfun$run$3.apply(PythonRDD.scala:280)
        at org.apache.spark.util.Utils$.logUncaughtExceptions(Utils.scala:1801)
        at org.apache.spark.api.python.PythonRunner$WriterThread.run(PythonRDD.scala:239)
18/06/02 09:36:10 WARN TaskSetManager: Lost task 1.0 in stage 4094.0 (TID 8189, localhost): org.apache.hadoop.fs.ChecksumException: Checksum error: /es/alertResult.txt at 29831168 exp: 1752925544 got: -1744680078
        at org.apache.hadoop.util.DataChecksum.verifyChunkedSums(DataChecksum.java:325)
        at org.apache.hadoop.hdfs.RemoteBlockReader2.readNextPacket(RemoteBlockReader2.java:216)
        at org.apache.hadoop.hdfs.RemoteBlockReader2.read(RemoteBlockReader2.java:146)
        at org.apache.hadoop.hdfs.DFSInputStream$ByteArrayStrategy.doRead(DFSInputStream.java:693)
        at org.apache.hadoop.hdfs.DFSInputStream.readBuffer(DFSInputStream.java:749)
        at org.apache.hadoop.hdfs.DFSInputStream.readWithStrategy(DFSInputStream.java:806)
        at org.apache.hadoop.hdfs.DFSInputStream.read(DFSInputStream.java:847)
        at java.io.DataInputStream.read(DataInputStream.java:100)
        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.mapred.LineRecordReader.next(LineRecordReader.java:246)
        at org.apache.hadoop.mapred.LineRecordReader.next(LineRecordReader.java:47)
        at org.apache.spark.rdd.HadoopRDD$$anon$1.getNext(HadoopRDD.scala:246)
        at org.apache.spark.rdd.HadoopRDD$$anon$1.getNext(HadoopRDD.scala:208)
        at org.apache.spark.util.NextIterator.hasNext(NextIterator.scala:73)
        at org.apache.spark.InterruptibleIterator.hasNext(InterruptibleIterator.scala:39)
        at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327)
        at scala.collection.Iterator$class.foreach(Iterator.scala:727)
        at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
        at org.apache.spark.api.python.PythonRDD$.writeIteratorToStream(PythonRDD.scala:452)
        at org.apache.spark.api.python.PythonRunner$WriterThread$$anonfun$run$3.apply(PythonRDD.scala:280)
        at org.apache.spark.util.Utils$.logUncaughtExceptions(Utils.scala:1801)
        at org.apache.spark.api.python.PythonRunner$WriterThread.run(PythonRDD.scala:239)

18/06/02 09:36:10 ERROR TaskSetManager: Task 1 in stage 4094.0 failed 1 times; aborting job
Traceback (most recent call last):
File "/home/spark/test/hdfsCount.py", line 11, in <module>
    print splits.count()
File "/opt/monitoring_software/spark-1.6.2-bin-hadoop2.6/python/lib/pyspark.zip/pyspark/rdd.py", line 1004, in count
File "/opt/monitoring_software/spark-1.6.2-bin-hadoop2.6/python/lib/pyspark.zip/pyspark/rdd.py", line 995, in sum
File "/opt/monitoring_software/spark-1.6.2-bin-hadoop2.6/python/lib/pyspark.zip/pyspark/rdd.py", line 869, in fold
File "/opt/monitoring_software/spark-1.6.2-bin-hadoop2.6/python/lib/pyspark.zip/pyspark/rdd.py", line 771, in collect
File "/opt/monitoring_software/spark-1.6.2-bin-hadoop2.6/python/lib/py4j-0.9-src.zip/py4j/java_gateway.py", line 813, in __call__
File "/opt/monitoring_software/spark-1.6.2-bin-hadoop2.6/python/lib/py4j-0.9-src.zip/py4j/protocol.py", line 308, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.api.python.PythonRDD.collectAndServe.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 4094.0 failed 1 times, most recent failure: Lost task 1.0 in stage 4094.0 (TID 8189, localhost): org.apache.hadoop.fs.ChecksumException: Checksum error: /es/alertResult.txt at 29831168 exp: 1752925544 got: -1744680078
        at org.apache.hadoop.util.DataChecksum.verifyChunkedSums(DataChecksum.java:325)
        at org.apache.hadoop.hdfs.RemoteBlockReader2.readNextPacket(RemoteBlockReader2.java:216)
        at org.apache.hadoop.hdfs.RemoteBlockReader2.read(RemoteBlockReader2.java:146)
        at org.apache.hadoop.hdfs.DFSInputStream$ByteArrayStrategy.doRead(DFSInputStream.java:693)
        at org.apache.hadoop.hdfs.DFSInputStream.readBuffer(DFSInputStream.java:749)
        at org.apache.hadoop.hdfs.DFSInputStream.readWithStrategy(DFSInputStream.java:806)
        at org.apache.hadoop.hdfs.DFSInputStream.read(DFSInputStream.java:847)
        at java.io.DataInputStream.read(DataInputStream.java:100)
        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.mapred.LineRecordReader.next(LineRecordReader.java:246)
        at org.apache.hadoop.mapred.LineRecordReader.next(LineRecordReader.java:47)
        at org.apache.spark.rdd.HadoopRDD$$anon$1.getNext(HadoopRDD.scala:246)
        at org.apache.spark.rdd.HadoopRDD$$anon$1.getNext(HadoopRDD.scala:208)
        at org.apache.spark.util.NextIterator.hasNext(NextIterator.scala:73)
        at org.apache.spark.InterruptibleIterator.hasNext(InterruptibleIterator.scala:39)
        at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327)
        at scala.collection.Iterator$class.foreach(Iterator.scala:727)
        at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
        at org.apache.spark.api.python.PythonRDD$.writeIteratorToStream(PythonRDD.scala:452)
        at org.apache.spark.api.python.PythonRunner$WriterThread$$anonfun$run$3.apply(PythonRDD.scala:280)
        at org.apache.spark.util.Utils$.logUncaughtExceptions(Utils.scala:1801)
        at org.apache.spark.api.python.PythonRunner$WriterThread.run(PythonRDD.scala:239)

Driver stacktrace:
        at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1431)
        at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1419)
        at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1418)
        at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
        at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
        at org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1418)
        at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:799)
        at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:799)
        at scala.Option.foreach(Option.scala:236)
        at org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:799)
        at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.doOnReceive(DAGScheduler.scala:1640)
        at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1599)
        at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1588)
        at org.apache.spark.util.EventLoop$$anon$1.run(EventLoop.scala:48)
        at org.apache.spark.scheduler.DAGScheduler.runJob(DAGScheduler.scala:620)
        at org.apache.spark.SparkContext.runJob(SparkContext.scala:1832)
        at org.apache.spark.SparkContext.runJob(SparkContext.scala:1845)
        at org.apache.spark.SparkContext.runJob(SparkContext.scala:1858)
        at org.apache.spark.SparkContext.runJob(SparkContext.scala:1929)
        at org.apache.spark.rdd.RDD$$anonfun$collect$1.apply(RDD.scala:927)
        at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:150)
        at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:111)
        at org.apache.spark.rdd.RDD.withScope(RDD.scala:316)
        at org.apache.spark.rdd.RDD.collect(RDD.scala:926)
        at org.apache.spark.api.python.PythonRDD$.collectAndServe(PythonRDD.scala:405)
        at org.apache.spark.api.python.PythonRDD.collectAndServe(PythonRDD.scala)
        at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)
        at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:381)
        at py4j.Gateway.invoke(Gateway.java:259)
        at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
        at py4j.commands.CallCommand.execute(CallCommand.java:79)
        at py4j.GatewayConnection.run(GatewayConnection.java:209)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.hadoop.fs.ChecksumException: Checksum error: /es/alertResult.txt at 29831168 exp: 1752925544 got: -1744680078
        at org.apache.hadoop.util.DataChecksum.verifyChunkedSums(DataChecksum.java:325)
        at org.apache.hadoop.hdfs.RemoteBlockReader2.readNextPacket(RemoteBlockReader2.java:216)

hello2018 发表于 2018-6-4 19:22:44

wanghiu 发表于 2018-6-4 10:18
具体的错误信息:
18/06/02 09:36:10 ERROR Executor: Exception in task 1.0 in stage 4094.0 (TID 8189) ...

Hadoop客户端将本地文件上传到hdfs上时,hadoop会通过fs.FSInputChecker判断需要上传的文件是否存在.crc校验文件。如果存在.crc校验文件,则会进行校验。如果校验失败,不会上传该文件。
由于楼主是追加的,所以在追加的时候,通过shell首先检测是否存在crc,如果存在则删除。

wanghiu 发表于 2018-6-6 10:42:53

hello2018 发表于 2018-6-4 19:22
Hadoop客户端将本地文件上传到hdfs上时,hadoop会通过fs.FSInputChecker判断需要上传的文件是否存在.crc ...

首先,谢谢您的回复。现在的问题,是出在读数据的时候,没有上传文件的情况。我在追加文件的时候,没有报错,而且是在hdfs文件的内容达到一定的大小的时候,才会出错。通过修改hdfs的配置参数 dfs.blocksize,现在能撑到60万行左右。然后还会报上边的这个错误。

wanghiu 发表于 2018-6-6 10:46:58

hello2018 发表于 2018-6-4 19:22
Hadoop客户端将本地文件上传到hdfs上时,hadoop会通过fs.FSInputChecker判断需要上传的文件是否存在.crc ...

追加文件,是通过java api写的,这个.crc文件是在hdfs文件的同级目录下么?在追加数据的时候,请问如何通过api来执行shell的查看和删除crc文件操作。多谢赐教!!!

arsenduan 发表于 2018-6-6 12:01:07

wanghiu 发表于 2018-6-6 10:46
追加文件,是通过java api写的,这个.crc文件是在hdfs文件的同级目录下么?在追加数据的时候,请问如何通 ...

Java api也可以实现,这个文件是在本地目录下跟源文件是同一个目录下。通过Java api循环查找一样,找到通过Java api删除。
当然首先确保是这个原因造成的。在产生错误的时候,看看是否有这个crc文件,如果有的话,删除掉是否可以继续上传了。如果可以。那么楼主就可以去编程实现了。



wanghiu 发表于 2018-6-6 13:24:05

arsenduan 发表于 2018-6-6 12:01
Java api也可以实现,这个文件是在本地目录下跟源文件是同一个目录下。通过Java api循环查找一样,找到通 ...

谢谢回复!本地目录是指应用程序所在目录,还是指hdfs文件在hadoop所在服务器的目录?比如读文件的应用程序部署在192.168.192.100,hadoop安装在192.168.192.111,
要读取的文件路径是: hdfs://192.168.192.111:9000/log/a.txt。如果产生了crc文件,这个crc文件是hdfs://192.168.192.111:9300/log/a.txt.crc 么?还是在192.168.192.100上?

arsenduan 发表于 2018-6-6 13:36:20

wanghiu 发表于 2018-6-6 13:24
谢谢回复!本地目录是指应用程序所在目录,还是指hdfs文件在hadoop所在服务器的目录?比如读文件的应用程 ...

读取的源文件a.txt所在的路径。比如下面
hdfs://192.168.192.111:9000/log/a.txt。这个crc文件是hdfs://192.168.192.111:9300/log/a.txt.crc

wanghiu 发表于 2018-6-6 13:43:11

arsenduan 发表于 2018-6-6 13:36
读取的源文件a.txt所在的路径。比如下面
hdfs://192.168.192.111:9000/log/a.txt。这个crc文件是hdfs:// ...

谢谢回复!我先试试
页: [1] 2
查看完整版本: HDFS文件数据丢失重写,校验失败