0301taildir-source报错-flume-大数据

{“inode”:2496275,“pos”:12,“file”:"/opt/module/flume/files2/log.t

xt"}

* 而flume会同时判断Inode和file来确定是否同一文件

 注:Linux 中储存文件元数据的区域就叫做 inode,每个 inode 都有一个号码,操作系统

 用 inode 号码来识别不同的文件,Unix/Linux 系统内部不使用文件名,而使用 inode 号码来

 识别文件。


### 3 解决


场景1解决方案有两种:


1. 既然是创建父目录已存在,我们可以吧positionFile位置重新配置。
2. 修改源代码,我们通过源代码找下处理逻辑,下载1.9.0版本的flume源代码,官网地址:<https://archive.apache.org/dist/flume/>,找到TailSource 170行

 

@Override
public synchronized void configure(Context context) {
String fileGroups = context.getString(FILE_GROUPS);
Preconditions.checkState(fileGroups != null, "Missing param: " + FILE_GROUPS);

filePaths = selectByKeys(context.getSubProperties(FILE_GROUPS_PREFIX),
                         fileGroups.split("\\s+"));
Preconditions.checkState(!filePaths.isEmpty(),
    "Mapping for tailing files is empty or invalid: '" + FILE_GROUPS_PREFIX + "'");

String homePath = System.getProperty("user.home").replace('\\', '/');
positionFilePath = context.getString(POSITION_FILE, homePath + DEFAULT_POSITION_FILE);
Path positionFile = Paths.get(positionFilePath);
try {
  // 此处创建父目录,如果存在报错
  Files.createDirectories(positionFile.getParent());
} catch (IOException e) {
  throw new FlumeException("Error creating positionFile parent directories", e);
}
headerTable = getTable(context, HEADERS_PREFIX);
batchSize = context.getInteger(BATCH_SIZE, DEFAULT_BATCH_SIZE);
skipToEnd = context.getBoolean(SKIP_TO_END, DEFAULT_SKIP_TO_END);
byteOffsetHeader = context.getBoolean(BYTE_OFFSET_HEADER, DEFAULT_BYTE_OFFSET_HEADER);
idleTimeout = context.getInteger(IDLE_TIMEOUT, DEFAULT_IDLE_TIMEOUT);
writePosInterval = context.getInteger(WRITE_POS_INTERVAL, DEFAULT_WRITE_POS_INTERVAL);
cachePatternMatching = context.getBoolean(CACHE_PATTERN_MATCHING,
    DEFAULT_CACHE_PATTERN_MATCHING);

backoffSleepIncrement = context.getLong(PollableSourceConstants.BACKOFF_SLEEP_INCREMENT,
    PollableSourceConstants.DEFAULT_BACKOFF_SLEEP_INCREMENT);
maxBackOffSleepInterval = context.getLong(PollableSourceConstants.MAX_BACKOFF_SLEEP,
    PollableSourceConstants.DEFAULT_MAX_BACKOFF_SLEEP);
fileHeader = context.getBoolean(FILENAME_HEADER,
        DEFAULT_FILE_HEADER);
fileHeaderKey = context.getString(FILENAME_HEADER_KEY,
        DEFAULT_FILENAME_HEADER_KEY);
maxBatchCount = context.getLong(MAX_BATCH_COUNT, DEFAULT_MAX_BATCH_COUNT);
if (maxBatchCount <= 0) {
  maxBatchCount = DEFAULT_MAX_BATCH_COUNT;
  logger.warn("Invalid maxBatchCount specified, initializing source "
      + "default maxBatchCount of {}", maxBatchCount);
}

if (sourceCounter == null) {
  sourceCounter = new SourceCounter(getName());
}

}

 ![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/fea36abce2d8400e9bd07b195ced6bca.png#pic_center)


可以在创建父目录之前检测是否已存在,如果已存在,直接跳过创建即可,修改try代码块中内容如下



boolean exists = Files.exists(positionFile.getParent());
if (!exists)
Files.createDirectories(positionFile.getParent());


maven打包替换flume/lib/下 flume-taildir-source-1.9.0.jar 如图所示:![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/1412feca802c45a3af4eb034156e797c.png#pic_center)


重新运行,正常启动,如下图日志所示:![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/4975dd6399a64eac8feccc63cf8011b0.png#pic_center)


kafka中新接收的数据如下图所示:![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/f6133495c165467aaf57ec0d7e660cd1.png#pic_center)


场景2解决方案 把TailFile如下代码



public boolean updatePos(String path, long inode, long pos) throws IOException {
if (this.inode == inode && this.path.equals(path)) {
setPos(pos);
updateFilePos(pos);
logger.info("Updated position, file: " + path + ", inode: " + inode + ", pos: " + pos);
return true;
}
return false;
}

// 修改为
public boolean updatePos(String path, long inode, long pos) throws IOException {
if (this.inode == inode) {
setPos(pos);
updateFilePos(pos);
logger.info("Updated position, file: " + path + ", inode: " + inode + ", pos: " + pos);
return true;
}
return false;
}


即不校验file只校验inode,具体这里不再去验证,有兴趣自己验证下


### 结语


如果小伙伴什么问题或者指教,欢迎交流。



> 
> ❓QQ:806797785
> 
> 
> 


参考链接:


[1][flume教学视频]( )[CP/OL].2020-04-16.


![img](https://img-blog.csdnimg.cn/img_convert/e3034bca25e0a95baf94f5b5672db590.png)
![img](https://img-blog.csdnimg.cn/img_convert/0fade1279053d02fb5aefb03d02214d6.png)

**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**


**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

可以戳这里获取](https://bbs.csdn.net/topics/618545628)**


**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

  • 6
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值