put更新操作测试
-- 创建HBase表student
create 'student','info'
-- put数据
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的数据
put 'student','001','info:name','lisi'
-- 查看所有版本数据的时候,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
-- 得到结论: flush后,之前版本的数据不删除,因为flush只管将mem store的数据写成一个文件
之后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个,版本数据查询结果也为1。
-- 结论:当进行compact时HFile文件数大于3,触发合成文件操作。会删除之前版本的数据。
delete操作测试
-- 删除该rowkey数据,此时已经打上了Delete标记
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
-- 再次刷写文件数到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'
-- 此时全表扫描还是能找到所有数据
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,此时产生了新的合并文件
hbase(main):001:0> compact 'student'
-- 再次查询所有版本数据,只剩下一条最后时间段的数据了
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