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

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

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

1.5版本:

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

1.7版本 :

  private Optional<FileInfo> getNextFile() {
List<File> candidateFiles = Collections.emptyList(); if (consumeOrder != ConsumeOrder.RANDOM ||
candidateFileIter == null ||
!candidateFileIter.hasNext()) {
candidateFiles = getCandidateFiles(spoolDirectory.toPath());
listFilesCount++;
candidateFileIter = candidateFiles.iterator();
} if (!candidateFileIter.hasNext()) { // No matching file in spooling directory.
return Optional.absent();
} File selectedFile = candidateFileIter.next();
if (consumeOrder == ConsumeOrder.RANDOM) { // Selected file is random.
return openFile(selectedFile);
} else if (consumeOrder == ConsumeOrder.YOUNGEST) {
for (File candidateFile : candidateFiles) {
long compare = selectedFile.lastModified() -
candidateFile.lastModified();
if (compare == 0) { // ts is same pick smallest lexicographically.
selectedFile = smallerLexicographical(selectedFile, candidateFile);
} else if (compare < 0) { // candidate is younger (cand-ts > selec-ts)
selectedFile = candidateFile;
}
}
} else { // default order is OLDEST
for (File candidateFile : candidateFiles) {
long compare = selectedFile.lastModified() -
candidateFile.lastModified();
if (compare == 0) { // ts is same pick smallest lexicographically.
selectedFile = smallerLexicographical(selectedFile, candidateFile);
} else if (compare > 0) { // candidate is older (cand-ts < selec-ts).
selectedFile = candidateFile;
}
}
} firstTimeRead = true; //修复传输大文件报错文件被修改的BUG
this.checkFileCpIsOver(selectedFile);//此处被阻塞,直到文件拷贝文件或者超过20秒
return openFile(selectedFile);
}

解决代码:

 /**
*
* @Title: checkFileCpIsOver
* @Description: TODO(用来检查文件拷贝是否完成)
* @param @param currentFile 设定文件
* @return void 返回类型
* @throws
*/
private void checkFileCpIsOver(File file) {
long modified = file.lastModified();//目前文件的修改时间
long length = file.length();//目前文件的大小
try {
Thread.sleep(1000);//等待1秒钟
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
File currentFile = new File(file.getAbsolutePath());
int count = 0;//记录循环次数,超过20次,也就是10秒后抛出异常
while(currentFile.lastModified() != modified || currentFile.length() != length) {
if(count > 20) {
String message = "File Copy time too long. please check copy whether exception!" + "\n"
+ "File at :" + file.getAbsolutePath() + "\n"
+ "File current length is:" + currentFile.lastModified();
new IllegalStateException(message);
}
count++;
modified = currentFile.lastModified();
length = currentFile.length();
try {
Thread.sleep(500);//等待500毫秒
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
currentFile = new File(file.getAbsolutePath()); }
//一直到文件传输完成就可以退出
}

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. 嵌入式设备hacking(转)

    原帖地址:http://drops.wooyun.org/papers/5157 0x00 IPCAM hacking TOOLS github-binwalk firmware-mod-kit ID ...

  2. chrome --headless --disable-gpu --dump-dom http://www.python.org

    Driving Headless Chrome with Python:Python chrome --headless --disable-gpu --dump-dom http://www.pyt ...

  3. Syslink Control in MFC 9.0(转)

    Visual Studio 2008 (formely code-named ‘Orcas’) has several important updates for VC++ and MFC. Amon ...

  4. 使用LibZ合并.Net程序集,支持WPF

    最近写了一个小的WPF程序,发布的时候发现依赖着两三个20~30k的小dll的,感觉有点不爽,就想把它合并一下.以前在WinForm下用过微软的ILMerge合并程序集,不过记得它对WPF程序支持不大 ...

  5. git 忽略文件 .gitignore 以及规则

    git提供了文件忽略系统,当对工作区某个目录或文件设置了忽略后,在执行status查看状态时,被忽略的文件即使存在也不会显示出来. 这样我就可以把那些不需要上传,不需要保留的文件或目录忽略掉(比如一些 ...

  6. Reverse Engineering the NC ECU (revisited) -- SH7508

    http://forum.miata.net/vb/showthread.php?t=536601 Hey all! About 5 years ago, there was a great thre ...

  7. 提交改动到 github 远程服务器,怎么跳过要求输入密码的步骤

    新机器上将工程改动提交到 github 服务器时,发现每次都要输入密码,这个有点儿小烦人,怎么解决这个问题呢? 首先,切换到工程根目录的 .git 隐藏目录,用 TextEdit 打开 config ...

  8. TSC条码打印机C#例程(tsclib.dll调用)

    TSC条码打印机C#例程(tsclib.dll调用) //----  program.cs using System;using System.Collections.Generic;using Sy ...

  9. 正确理解java编译时,运行时以及构建时这三个概念

    Java中的许多对象(一般都是具有父子类关系的父类对象)在运行时都会出现两种类型:编译时类型和运行时类型,例如:Person person = new Student();这行代码将会生成一个pers ...

  10. C语言内存分析

    C语言内存分析 一.进制 概念:进制是一种计数方式,是数值的表现形式 4种主要的进制: ①. 十进制:0~9 ②. 二进制:0和1 ③. 八进制:0~7 ④. 十六进制:0~9+a b c d e f ...