HDFS 拷贝本地文件至HDFS时的异常[INFO fs.FSInputChecker: Found checksum error]处理方法

来源:互联网 发布:还珠格格小燕子知乎 编辑:程序博客网 时间:2024/06/08 17:37


                boolean deleteSource = false;boolean overwrite = true;boolean returnValue = false;Configuration hdfsconf = new Configuration();hdfsconf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));FileSystem hdfs = FileSystem.get(hdfsconf);Configuration localconf = new Configuration();//Copy the index files to HDFSFileSystem.getLocal(localconf).setVerifyChecksum(true);returnValue = FileUtil.copy(FileSystem.getLocal(localconf),solrDataDir, hdfs, hdfsDataDir, deleteSource, overwrite,hdfsconf);System.out.println("Upload all index files in local Solr dir to "+ hdfsconf.get("fs.default.name"));

在执行以上代码时报错,在上传的文件中有一文件(segment.gen)的校验码出错,无法完成上传。


打开要上传的本地目录,使用ls -all查看隐藏文件,发现有隐藏的crc文件,无法上传的segment.gen也有对应的crc文件。


这时有两种解决方案:

FileSystem.getLocal(localconf).setVerifyChecksum(false);
这样让本地文件无法校验,但是上传至HDFS的文件也会有错

2

在本地目录中删除这一.crc文件,代码在下次执行copy时会重新生成新的.crc文件,这样上传文件会根据新的校验文件校验从而不会出错。

原创粉丝点击