HBASE 生存期 TTL

HBASE TTL生存期


大家都知道hbase有个version版本号,所谓的version其实就是同一条数据插入不同的时间戳来实现的,在hbase底层的存储是基于时间戳排序的,所以每次我们查到的数据都是最新的版本,除非我们指定了要读取特定的时间范围的数据。即hbase都是根据时间戳进行数据版本的迭代,但是,hbase还有个TTL(Time To Live)数据生存期,从官网找到如下关于TTL描述:

  1. Time To Live (TTL)

ColumnFamilies can set a TTL length in seconds, and HBase will
automatically delete rows once the expiration time is reached. This
applies to all versions of a row - even the current one. The TTL time
encoded in the HBase for the row is specified in UTC.

Store files which contains only expired rows are deleted on minor
compaction. Setting hbase.store.delete.expired.storefile to false
disables this feature. Setting minimum number of versions to other
than 0 also disables this.

See HColumnDescriptor for more information.

Recent versions of HBase also support setting time to live on a per
cell basis. See HBASE-10560 for more information. Cell TTLs are
submitted as an attribute on mutation requests (Appends, Increments,
Puts, etc.) using Mutation#setTTL. If the TTL attribute is set, it
will be applied to all cells updated on the server by the operation.
There are two notable differences between cell TTL handling and
ColumnFamily TTLs:

Cell TTLs are expressed in units of milliseconds instead of seconds.

A cell TTLs cannot extend the effective lifetime of a cell beyond a
ColumnFamily level TTL setting.

大意是:cf可以以秒为单位设置TTL,hbase会在设置的TTL时间点删除那行数据,包含当前version。
在微压缩时删除仅包含过期行的存储文件,可以设置hbase.store.delete.expired.storefile为false禁用这个属性,或设置最小版本号为非0的值也能禁用它。
最新版本还支持单元格的生存期,使用Mutation#setTTL将cell TTL作为突变请求(Appends,Increments,Puts等)的属性提交。如果设置了TTL属性,它将应用于操作在服务器上更新的所有单元格。
Column family的TTL以秒为单位,cell的TTL以毫秒为单位
如果有有cell级别的TTL,则cell的TTL override CF的TTL; 但是不能超出CF级别的TTL

也就是说hbase可能通过 TTL的设置,使数据保持活性,即最新的周期内的数据。但是对于全量数据来说,这个功能可能会带来不可恢复性的灾难。
公司生产库hbase,使用了TTL,设置了30天,结果发现昨天刚导出数据,今天就发现数据没了的问题如下 :
在这里插入图片描述
上亿条的数据就这样不见了。
最后是通过

disable 'table'
alter 'table',NAME=>'c',TTL=>'2147483647'
enable 'table'

在这里插入图片描述
本以为之前的数据会不见了,结果发现30几天前的数据还存在。发现处理这些问题的时间是2020-01-04,发现2019-11-21的数据还存在。
在这里插入图片描述
可能的原因是还没进行major compaction,但具体原因还有待探索

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值