spark-streaming消費kafka數(shù)據(jù)梢睛,采用buffermutator寫hbase踩坑記
場景
otter同步mysql的數(shù)據(jù)到kafka,spark-streaming消費kafka,采用mutator異步寫hbase尺上。mysql的insert金顿,update,delete特別頻繁贰您,每秒都有大量的insert坏平,delete,update
以下都是基于同一條數(shù)據(jù)操作
1. ?坑 Delete(byte [] row), Put(byte[] row)锦亦,
bufferedmutator寫hbase的時候 同一條數(shù)據(jù)先 delete 再put 舶替,
遇到的問題:
hbase顯示沒這個數(shù)據(jù);就是bufferedmutator處理數(shù)據(jù)亂序了(每次測試都是hbase找不到數(shù)據(jù))
解決的途徑:
遇坑后杠园,百度找到https://developer.aliyun.com/ask/129312?spm=a2c6h.13159736這篇文章顾瞪。意思就是new 對象 加上時間戳
2.坑 Delete(byte [] row, long timestamp) ,Put(byte[] row, long ts)?
代碼里時間戳使用System.currentTimeMillis()
遇到的問題:
spark-streaming處理數(shù)據(jù)的時候抛蚁,一個批次rdd遍歷起來很快陈醒,難免兩個System.currentTimeMillis()一樣,此時就和方法1一樣瞧甩,達不到先delete钉跷,后insert的效果,依然沒有解決(反復測試肚逸,確實有兩個時間戳一樣)
解決的途徑:
上邊的時間戳加1操作爷辙,使兩個時間戳不一樣
參照https://issues.apache.org/jira/browse/HBASE-8626?focusedCommentId=13669455&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-13669455?hbase的issue就是上邊mutator踩坑實錄
longnow =System.currentTimeMillis();?
?Delete delete =newDelete(row);?
?delete.deleteFamily(cf1, now);?
?Put put1 =newPut(row);
?put1.add(cf1,col1,now+1);