Flume Spooldir 源的一些問題

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   使用   ar   java   檔案   

最近在用Flume做資料的收集。用到了裡面的Spooldir的源在使用中有如下的問題:

  • 如果檔案的某一行有亂碼,不符合指定的編碼規範,那麼flume會拋出一個exception,然後就停在那兒了。
  • spooldir指定的檔案夾中的檔案一旦被修改,flume就會拋出一個exception,然後停在那兒了。

其實,flume的最大問題就是不夠魯棒。一旦出現問題,不能跳過,只能死在那兒。不知道flume為什麼要這麼設計。理論上,它應該允許我們在設定檔中指定在遇到錯誤的行時,是停止還是跳過,不過它目前並不支援這個。所以,我們只能寫一個自己的flume的外掛程式了。

https://github.com/xlvector/flumehttps://github.com/ponyma/flume

這個外掛程式主要修複了前面提到的兩個問題:

  • 如果某一行有亂碼,flume會忽略這一行
  • flume只會check最近N分鐘沒有修改過的檔案

具體修改方法如下。首先,我們繼承了SpoolDirectorySource,實現了一個叫做RobustSpoolDirectorySource的類。這個類的代碼基本是拷貝了SpoolDirectorySource的代碼。但做了如下的修改。

在getNextFile()的函數中,我們發現了一個filter,做了如下的修改:

 1 FileFilter filter = new FileFilter() { 2     public boolean accept(File candidate) { 3         String fileName = candidate.getName(); 4         if ((candidate.isDirectory()) || 5             (fileName.endsWith(completedSuffix)) || 6             (fileName.startsWith(".")) || 7             ignorePattern.matcher(fileName).matches() || 8             (System.currentTimeMillis() - candidate.lastModified() < 600000)) { 9             return false;10         }11         return true;12     }13 };

這裡,我們加入了一個條件:

(System.currentTimeMillis() - candidate.lastModified() < 600000)

也就是說10分鐘之內修改過的檔案我們不會處理。

第二個修改是關於編碼的,你可以在ReliableSpoolingFileEventReader.java的代碼中找到如下的代碼:

1 ResettableInputStream in =2     new ResettableFileInputStream(nextFile, tracker,3         ResettableFileInputStream.DEFAULT_BUF_SIZE, inputCharset,4         DecodeErrorPolicy.FAIL);

這裡,我們只需要將DecodeErrorPolicy 改成 DecodeErrorPolicy.IGNORE 即可。

Flume Spooldir 源的一些問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.