最近完成了一個GitHub項目:Storm-HBase,該項目是Twitter Storm和Apache HBase的結合,它使用HBase cluster作為Storm的Spout資料來源,目前只是初步實現,後續會進一步完善。
HBaseSpout根據時間戳記範圍[start_timestamp, stop_timestamp],持續不間斷地從HBase cluster讀取流資料:
如果start_timestamp = 0,HBaseSpout將預設從3分鐘前的資料開始讀取並發送到Storm cluster;否則從使用者指定的start_timestamp開始讀取資料。
如果stop_timestamp = 0, HBaseSpout將預設讀取到目前時間的資料,並隨著時間流動持續地讀取新的資料並發送到Storm cluster;否則讀取到使用者指定的stop_timestamp後停止讀取。
以上有關[start_timestamp, stop_timestamp]的設計,是為了適應不同的運行模式:
最典型情況下,start_timestamp = 0 and stop_timestamp = 0,則從3分鐘前開始讀取發送資料,然後會同步掃描HBase cluster中的新資料,並發送給Storm cluster,適合使用者即時計算的情景。
出現問題的情況下,例如Storm cluster重啟,計算任務狀態被丟失,此時可能需要能夠Spout進行資料的回傳(data rewind),通過指定[start_timestamp, stop_timestamp]可以滿足這一需求。
Storm-HBase力求儘可能做到通用化,因此提取了Storm和HBase的配置資訊。有關Storm-HBase的配置選項,可以在GitHub工程的src/main/resources/storm.properties以及src/main/resources/hbase.properties檔案中找到。如果你的HBase表的Schema結構與上述類似,那麼只需要進行簡單的配置即可使用Storm-HBase。
目前的HBaseSpout實現基於以下假設:
HBase表的rowkey形式為[shardingkey, timestamp, ...];
shardingkey佔據第1個byte,表示表中資料的分區數,一般是100以內,所以這裡使用了short類型儲存;
timestamp佔據第2~5個byte,表示資料中的時間戳記資訊,這裡timestamp是秒級的UNIX時間戳記值,使用了int型儲存。
更多關於Storm-HBase的介紹及進展,請參加項目的GitHub連結:https://github.com/ypf412/storm-hbase
更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/database/extra/