flume spooldir bug修复
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 OLDESTfor (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修复相关推荐
- flume1.7 TailDirSource断点续传与文件更名后数据重复采集的bug修复
flume1.7 TailDirSource断点续传与文件更名后数据重复采集的bug修复 一:flume1.7新增了组件Taildir Source 官方链接:http://flume.apache. ...
- TensorFlow 1.8.0正式发布,Bug修复和改进内容都在这里了
译者 | 王柯凝 编辑 | Just 出品 | AI科技大本营(公众号ID:rgznai100) [导语]TensorFlow 1.8.0 近日正式发布,新版本主要有以下改进内容,AI科技大本营对其编 ...
- TensorFlow1.8.0正式发布,Bug修复和改进内容都在这里了
译者 | 王柯凝 编辑 | Just 出品 | AI科技大本营(公众号ID:rgznai100) [导语]TensorFlow 1.8.0 近日正式发布,新版本主要有以下改进内容,AI科技大本营对其编 ...
- TensorFlow 1.7.0正式发布,Bug修复和改进内容都在这里了
编译 | AI科技大本营(公众号ID:rgznai100) 参与 | 张建军 TensorFlow 1.7.0 近日正式发布,新版本主要有以下改进内容,AI科技大本营对其进行了编译. 主要特征和改进 ...
- 一分钟详解initUndistortRectifyMap函数bug修复方法
本文首发于微信公众号「3D视觉工坊」--一分钟详解initUndistortRectifyMap函数bug修复方法 在上一篇文章OpenCV中initUndistortRectifyMap函数存在bu ...
- Swoole 1.8.12 发布,Bug修复版本
PHP的异步.并行.高性能网络通信引擎Swoole 已发布 1.8.12 版本.此版本是一个BUG修复版本,修复了多个细节问题.建议所有用户升级至此版本. 主要更新: 修复SwooleTable在遍历 ...
- IE haslayout的理解与bug修复
要想更好的理解 css, 尤其是 IE 下对 css 的渲染,haslayout 是一个非常有必要彻底弄清楚的概念.大多 IE 下的显示错误,就是源于 haslayout 什么是 haslayout ...
- 被尘封的故事技能点bug_新月纪元稳定版下载-新月纪元bug修复版1.0 修复版
新月纪元是一款二次元像素风格动作射击roguelike类游戏.玩家将成为主角开启自己的冒险之旅.多种游戏模式,海量的游戏关卡等你来战,还有强大的副本boss可以挑战,给你绝佳的游戏乐趣! 新月纪元bu ...
- OpenFOAM流固耦合问题-FsiFoam(foam-extend-4.0)运行tutorials的bug修复
OpenFOAM流固耦合问题-FsiFoam(foam-extend-4.0)运行tutorials的bug修复 问题描述: FsiFoam(foam-extend-4.0),./Allrun运行自带 ...
最新文章
- 被“钱”困住的开源开发者们!
- 工作118:封装一个带有对话框的button组件
- RabbitMQ管控台操作手册
- Open Flash Chart 图表组件
- elk-Logstash
- C++_类和对象_对象特性_构造函数和析构函数---C++语言工作笔记040
- 第八章 ---- 枚举注解
- 隐马尔科夫模型,第三种问题解法,维比特算法(biterbi) algorithm python代码
- Spring Bean实例化的几种特殊方式
- PostgreSQL学习笔记YY(2)--Ubuntu下使用DDD调试查看源码(原创)
- 视频转换器如何将腾讯QLV格式转换成MP4视频文件
- 树莓派GPIO引脚介绍
- 计算机组装维护安装光驱步骤,光驱怎么安装?教你如何正确安装光驱方法
- 微信号注册人工服务器,怎么设置微信公众号接入人工客服?
- java pgm_(转) PGM图像处理方法详解(很好一篇)
- 24位RGB颜色转换为16位RGB
- 构建orangePi r1 plus (RK3328)系统的整个过程
- java swing 抽奖程序_java swing抽奖程序
- 在编辑页面移动选中的代码
- 公农历转换和获取二十四节气算法
热门文章
- SpringBoot+Thymeleaf+Jquery实现模态框的显示与数据填充
- 小白入门学会将Eclipse中项目提交到github
- 对话:在敏捷中,是否可以仍然用需求来替代用户故事?
- linux权限776代表,Linux 权限设置chmod
- idea 用iterm 终端_帅气逼人的终端环境
- mysql是否有缓存区_Mysql查询高速缓存区
- 意向保护:你的 A/B 测试数据期骗你了吗?
- 硅谷增长专家 Ian Thiel 来华,首次揭秘数据驱动增长的道与术
- 百度视频携手神策数据 为用户精准推送短视频内容
- vue v-model 简单使用