HBase中的TTL与MinVersion的关系

HBase版本:1.3.1

 

TTL(Time-To-Live):每个Cell的数据超时时间(当前时间 - 最后更新的时间)

MinVersion:如果当前存储的所有时间版本都早于TTL,至少MIN_VERSION个最新版本会保留下来。这样确保在你的查询以及数据早于TTL时有结果返回

HBase中的TTL与MinVersion的关系_第1张图片

 

 

===先做一个实验===

1、创建一个表TEST1

包含两个列族df、ex,其中列族ex为测试对象:VERSIONS => 4, MIN_VERSIONS => 2, TTL => 3分钟

HBase中的TTL与MinVersion的关系_第2张图片

2、向该表中生产10条数据

 生产数据的代码如下所示:

package api;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;

public class table_put_sample1 { public static void main(String[] args) throws Exception { Configuration conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum", "192.168.1.80,192.168.1.81,192.168.1.82"); Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(TableName.valueOf(constants.TABLE_NAME)); for (int i = 0; i < 10; i++) { Put put = new Put("row01".getBytes()); put.addColumn(constants.COLUMN_FAMILY_DF.getBytes(), "name".getBytes(), random.getName()); put.addColumn(constants.COLUMN_FAMILY_DF.getBytes(), "sex".getBytes(), random.getSex()); put.addColumn(constants.COLUMN_FAMILY_EX.getBytes(), "height".getBytes(), random.getHeight()); put.addColumn(constants.COLUMN_FAMILY_EX.getBytes(), "weight".getBytes(), random.getWeight()); table.put(put); System.out.print("[------]put i=" + i + "\n"); Thread.sleep(1000); } table.close(); connection.close(); } }

 

3、scan这个表看一下结果。

我们插入了10条数据,因为ex列族的最大半版本为4,所以,这里只保存了4个版本的数据。

HBase中的TTL与MinVersion的关系_第3张图片

 

4、过3分钟之后,再次扫描该表。

虽然从TTL来看,所有的数据都已经过期了,但是由于设置了MIN_VERSIONS => 2的原因,HBase仍然保留了2个版本的数据。以确保可以返回查询结果。

HBase中的TTL与MinVersion的关系_第4张图片

 

===再做一个实验===

1、将表的MIN_VERSIONS变更为0

变更命令:alter 'TEST1', {NAME => 'ex', MIN_VERSIONS => '0'}

HBase中的TTL与MinVersion的关系_第5张图片

3、清空TEST1表中的数据,然后再向表中插入10条数据。

《清空》

HBase中的TTL与MinVersion的关系_第6张图片

《插入10条记录》

查看命令:scan 'TEST1', {VERSIONS => 10}

HBase中的TTL与MinVersion的关系_第7张图片

 

4、过几分钟(TTL时间以上)再次scan表。

再次查看一下表发现ex列族的数据都被自动清理掉了。

HBase中的TTL与MinVersion的关系_第8张图片

 

===结论===

MinVersion:used when timeToLive is set

如果HBase中的表设置了TTL的时候,MinVersion才会起作用。

a)MIN_VERSION > 0时:

Cell至少有MIN_VERSION个最新版本会保留下来。这样确保在你的查询以及数据早于TTL时有结果返回。

b)MIN_VERSION = 0时:

Cell中的数据超过TTL时间时,全部清空,不保留最低版本。

 

--END--

转载于:https://www.cnblogs.com/quchunhui/p/7543121.html

你可能感兴趣的:(HBase中的TTL与MinVersion的关系)