put更新操作測試
-- 創(chuàng)建HBase表student
create 'student','info'
-- put數(shù)據(jù)
put 'student','001','info:name','zhangsan'
-- 全表掃描student
hbase(main):023:0> scan 'student'
ROW COLUMN+CELL
001 column=info:name, timestamp=1576226988856, value=zhangsan
1 row(s)
Took 0.0550 seconds
flush 'student'
-- 更新該rowkey的數(shù)據(jù)
put 'student','001','info:name','lisi'
-- 查看所有版本數(shù)據(jù)的時候,zhangsan并沒有被刪掉
hbase(main):009:0> scan 'student',{RAW=>TRUE,VERSIONS=>10}
ROW COLUMN+CELL
001 column=info:name, timestamp=1576227210750, value=lisi
001 column=info:name, timestamp=1576226988856, value=zhangsan
1 row(s)
Took 0.0164 seconds
-- 此時進行flush,刷寫到磁盤形成小文件。zhangsan依然存在
hbase(main):001:0> flush 'student'
hbase(main):003:0> scan 'student',{RAW=>TRUE,VERSIONS=>10}
ROW COLUMN+CELL
001 column=info:name, timestamp=1576227210750, value=lisi
001 column=info:name, timestamp=1576226988856, value=zhangsan
1 row(s)
Took 0.0417 seconds
-- 得到結(jié)論: flush后,之前版本的數(shù)據(jù)不刪除,因為flush只管將mem store的數(shù)據(jù)寫成一個文件
之后put蹲蒲、flush使文件達到4個,滿足compact大于3的條件,進行merge文件合并
hbase(main):014:0> compact 'student'
Took 0.0305 seconds
hbase(main):015:0> scan 'student',{RAW=>TRUE,VERSIONS=>10}
ROW COLUMN+CELL
001 column=info:name, timestamp=1576227681356, value=lisi3
1 row(s)
-- 此時合并后文件剩余1個,版本數(shù)據(jù)查詢結(jié)果也為1沪伙。
-- 結(jié)論:當(dāng)進行compact時HFile文件數(shù)大于3,觸發(fā)合成文件操作饶号。會刪除之前版本的數(shù)據(jù)株依。
delete操作測試
-- 刪除該rowkey數(shù)據(jù),此時已經(jīng)打上了Delete標(biāo)記
hbase(main):003:0> delete 'student','001','info:name'
hbase(main):005:0> scan 'student',{RAW=>TRUE,VERSIONS=>10}
ROW COLUMN+CELL
001 column=info:name, timestamp=1576227681356, type=Delete
001 column=info:name, timestamp=1576227681356, value=lisi3
1 row(s)
Took 0.0129 seconds
-- 再次刷寫文件數(shù)到4個
hbase(main):001:0> put 'student','001','info:name','lisi4'
hbase(main):002:0> flush 'student'
hbase(main):003:0> put 'student','001','info:name','lisi5'
hbase(main):004:0> flush 'student'
hbase(main):005:0> put 'student','001','info:name','lisi6'
hbase(main):006:0> flush 'student'
-- 此時全表掃描還是能找到所有數(shù)據(jù)
hbase(main):001:0> scan 'student',{RAW=>TRUE,VERSIONS=>10}
ROW COLUMN+CELL
001 column=info:name, timestamp=1576228552290, value=lisi6
001 column=info:name, timestamp=1576228547984, value=lisi5
001 column=info:name, timestamp=1576228540184, value=lisi4
001 column=info:name, timestamp=1576227681356, type=Delete
001 column=info:name, timestamp=1576227681356, value=lisi3
1 row(s)
Took 0.3525 seconds
-- 進行compact,此時產(chǎn)生了新的合并文件
hbase(main):001:0> compact 'student'
-- 再次查詢所有版本數(shù)據(jù),只剩下一條最后時間段的數(shù)據(jù)了
hbase(main):002:0> scan 'student',{RAW=>TRUE,VERSIONS=>10}
ROW COLUMN+CELL
001 column=info:name, timestamp=1576228552290, value=lisi6
1 row(s)
Took 0.0321 seconds