BUG:在往目录中copy大文件时,没有复制完,flume就开始读-->导致报错

在代码中体现为:
org.apache.flume.client.avro.ReliableSpoolingFileEventReader.retireCurrentFile()方法内

解决方案:
等文件完全拷贝完成,再开始读这个文件

1.5版本:

  1. private Optional<FileInfo> getNextFile() {
  2. 7 /* Filter to exclude finished or hidden files */
  3. 8 FileFilter filter = new FileFilter() {
  4. 9 public boolean accept(File candidate) {
  5. 10 String fileName = candidate.getName();
  6. 11 if ((candidate.isDirectory()) ||
  7. 12 (fileName.endsWith(completedSuffix)) ||
  8. 13 (fileName.startsWith(".")) ||
  9. 14 ignorePattern.matcher(fileName).matches()) {
  10. 15 return false;
  11. 16 }
  12. 17 return true;
  13. 18 }
  14. 19 };
  15. 20 List<File> candidateFiles = Arrays.asList(spoolDirectory.listFiles(filter)); //获取spoolDirectory下满足条件的文件
  16. 21 if (candidateFiles.isEmpty()) {
  17. 22 return Optional.absent();
  18. 23 } else {
  19. 24 Collections.sort(candidateFiles, new Comparator<File>() { //按最后修改时间排序文件
  20. 25 public int compare(File a, File b) {
  21. 26 int timeComparison = new Long(a.lastModified()).compareTo(
  22. 27 new Long(b.lastModified()));
  23. 28 if (timeComparison != 0) {
  24. 29 return timeComparison;
  25. 30 }
  26. 31 else {
  27. 32 return a.getName().compareTo(b.getName());
  28. 33 }
  29. 34 }
  30. 35 });
  31. 36 File nextFile = candidateFiles.get(0); //因为每次获取到的文件处理完都会被标记为已完成,所以直接取拍完序的第一个
  32. 37 //修复传输大文件报错文件被修改的BUG
  33. 38 this.checkFileCpIsOver(nextFile);//此处被阻塞,直到文件拷贝文件或者超过20秒
  34. 39
  35. 40 try {
  36. 41 // roll the meta file, if needed
  37. 42 String nextPath = nextFile.getPath()

1.7版本 :

  1. private Optional<FileInfo> getNextFile() {
  2. List<File> candidateFiles = Collections.emptyList();
  3.  
  4. if (consumeOrder != ConsumeOrder.RANDOM ||
  5. candidateFileIter == null ||
  6. !candidateFileIter.hasNext()) {
  7. candidateFiles = getCandidateFiles(spoolDirectory.toPath());
  8. listFilesCount++;
  9. candidateFileIter = candidateFiles.iterator();
  10. }
  11.  
  12. if (!candidateFileIter.hasNext()) { // No matching file in spooling directory.
  13. return Optional.absent();
  14. }
  15.  
  16. File selectedFile = candidateFileIter.next();
  17. if (consumeOrder == ConsumeOrder.RANDOM) { // Selected file is random.
  18. return openFile(selectedFile);
  19. } else if (consumeOrder == ConsumeOrder.YOUNGEST) {
  20. for (File candidateFile : candidateFiles) {
  21. long compare = selectedFile.lastModified() -
  22. candidateFile.lastModified();
  23. if (compare == 0) { // ts is same pick smallest lexicographically.
  24. selectedFile = smallerLexicographical(selectedFile, candidateFile);
  25. } else if (compare < 0) { // candidate is younger (cand-ts > selec-ts)
  26. selectedFile = candidateFile;
  27. }
  28. }
  29. } else { // default order is OLDEST
  30. for (File candidateFile : candidateFiles) {
  31. long compare = selectedFile.lastModified() -
  32. candidateFile.lastModified();
  33. if (compare == 0) { // ts is same pick smallest lexicographically.
  34. selectedFile = smallerLexicographical(selectedFile, candidateFile);
  35. } else if (compare > 0) { // candidate is older (cand-ts < selec-ts).
  36. selectedFile = candidateFile;
  37. }
  38. }
  39. }
  40.  
  41. firstTimeRead = true;
  42.  
  43. //修复传输大文件报错文件被修改的BUG
  44. this.checkFileCpIsOver(selectedFile);//此处被阻塞,直到文件拷贝文件或者超过20秒
  45. return openFile(selectedFile);
  46. }

解决代码:

  1. /**
  2. *
  3. * @Title: checkFileCpIsOver
  4. * @Description: TODO(用来检查文件拷贝是否完成)
  5. * @param @param currentFile 设定文件
  6. * @return void 返回类型
  7. * @throws
  8. */
  9. private void checkFileCpIsOver(File file) {
  10. long modified = file.lastModified();//目前文件的修改时间
  11. long length = file.length();//目前文件的大小
  12. try {
  13. Thread.sleep(1000);//等待1秒钟
  14. } catch (InterruptedException e) {
  15. // TODO Auto-generated catch block
  16. e.printStackTrace();
  17. }
  18. File currentFile = new File(file.getAbsolutePath());
  19. int count = 0;//记录循环次数,超过20次,也就是10秒后抛出异常
  20. while(currentFile.lastModified() != modified || currentFile.length() != length) {
  21. if(count > 20) {
  22. String message = "File Copy time too long. please check copy whether exception!" + "\n"
  23. + "File at :" + file.getAbsolutePath() + "\n"
  24. + "File current length is:" + currentFile.lastModified();
  25. new IllegalStateException(message);
  26. }
  27. count++;
  28. modified = currentFile.lastModified();
  29. length = currentFile.length();
  30. try {
  31. Thread.sleep(500);//等待500毫秒
  32. } catch (InterruptedException e) {
  33. // TODO Auto-generated catch block
  34. e.printStackTrace();
  35. }
  36. currentFile = new File(file.getAbsolutePath());
  37.  
  38. }
  39. //一直到文件传输完成就可以退出
  40. }

flume spooldir bug修复的更多相关文章

  1. Flume Spooldir 源的一些问题

    Flume Spooldir 源的一些问题 来自:http://blog.xlvector.net/2014-01/flume-spooldir-source-problem/ ( 自己写的插件,数据 ...

  2. 仿酷狗音乐播放器开发日志十九——CTreeNodeUI的bug修复二(附源码)

    转载请说明原出处,谢谢 今天本来打算把仿酷狗播放列表的子控件拖动插入功能做一下,但是仔细使用播放列表控件时发现了几个逻辑错误,由于我的播放 列表控件是基于CTreeViewUI和CTreeNodeUI ...

  3. OJ2.0userInfo页面Modify逻辑bug修复,search功能逻辑实现

    这周的主要任务:userInfo页面Modify逻辑bug修复,search功能逻辑实现. (一)Modify逻辑bug修复: 这里存在的bug就是在我们不重置password的时候依照前面的逻辑是不 ...

  4. cocos2d-x多分辨率和随后的自适应CCListView的bug修复

    cocos2d-x多分辨率自适配及因此导致的CCListView的bug修复 cocos2d-x是一款众所周知的跨平台的游戏开发引擎.因为其跨平台的特性.多分辨率支持也自然就有其需求. 因此.在某一次 ...

  5. android-misc-widgets四向(上下左右)抽屉bug修复版--转载

     android-misc-widgets四向(上下左右)抽屉bug修复版 2013-08-04 08:58:13 标签:bug down top panel slidingdrawer 原创作品,允 ...

  6. Spring+SpringMVC+MyBatis+easyUI整合基础篇(八)mysql中文查询bug修复

    写在前面的话 在测试搜索时出现的问题,mysql通过中文查询条件搜索不出数据,但是英文和数字可以搜索到记录,中文无返回记录.本文就是写一下发现问题的过程及解决方法.此bug在第一个项目中点这里还存在, ...

  7. 微信小程序(有始有终,全部代码)开发---跑步App+音乐播放器 Bug修复

    开篇语 昨晚发了一篇: <简年15: 微信小程序(有始有终,全部代码)开发---跑步App+音乐播放器 > 然后上午起来吃完午饭之后,我就准备继续开工的,但是突然的,想要看B站.然后在一股 ...

  8. Saiku Table展示数据合并bug修复(二十五)

    Saiku Table展示数据合并bug修复 Saiku以table的形式展示数据,如果点击了 非空的字段 按钮,则会自动进行数据合并,为空的数据行以及数据列都会自动隐藏掉. 首先我们应该定位问题: ...

  9. ThinkPHP 3.2.3+ORACLE插入数据BUG修复及支持获取自增Id的上次记录

    TP+ORACLE插入数据BUG修复以及获取自增Id支持getLastInsID方法 这些天在做Api接口时候,发现用TP操作Oracle数据库,发现查询修改删除都能执行, 但一旦执行插入操作老是报错 ...

随机推荐

  1. 【scrapy】使用方法概要(一)(转)

    [请初学者作为参考,不建议高手看这个浪费时间] 工作中经常会有这种需求,需要抓取互联网上的数据.笔者就经常遇到这种需求,一般情况下会临时写个抓取程序,但是每次遇到这种需求的时候,都几乎要重头写,特别是 ...

  2. ARM ® and Thumb ®-2 指令系统

    指令表关键词        Rm {, <opsh>} 寄存器移位方式,将寄存器的移位结果作为操作数而Rm值保持不变       <Operand2> 灵活的使用第二个操作数. ...

  3. 《C预处理》Linux内核中可变参数宏的用法

    http://blog.csdn.net/tankai19880619/article/details/12015305

  4. JavaScript 复制对象【Object.assign方法无法实现深复制】

    在JavaScript这门语言中,数据类型分为两大类:基本数据类型和复杂数据类型.基本数据类型包括Number.Boolean.String.Null.String.Symbol(ES6 新增),而复 ...

  5. Ext BoxComponent

    Ext.BoxComponent也是一个比较重要的基础类,它直接继承自Ext.Component,并实现了定位和控制自身大小的功能. 可以使用pageX.pageY.x.y为Ext.BoxCompon ...

  6. python测试开发django-7.django模板继承(block和extends)

    前言 打开一个网站时候,点导航栏切换到不同的页面,发现导航部分是不变的,只是页面的主体内容变了,于是就可以写个母模板,其它的子页面继承母模板就可以了. 母模板 可以在母模板中添加多个块标签,每个块标签 ...

  7. velocity的一些优化记录

    背景 前段时间做了个项目,主要优化一个产品页面.整个优化过程中,针对velocity的分析过程占了比较大的比重,这里做一下整理和记录. 描述 velocity版本: <dependency> ...

  8. Android之在应用程序内部关注某人的微信

    Intent intent = new Intent(Intent.ACTION_VIEW); intent.setPackage("com.tencent.mm");//直接打开 ...

  9. python文件目录操作

    一.python中对文件.文件夹操作时经常用到的os模块和shutil模块常用方法.1.得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd()2.返回指定目录下的所有文件和目 ...

  10. Mysql 查询注意和运行shell命令

    Mysql 查询注意 1. 在mysql查询的时候须要注意在表的前面加上数据库的前缀,不然就是默认是当前的数据库(当多个库查询的时候,可能会出现反复的查同样的表多次) 2. \! ls –al ,my ...