TTL(Time To Live)生存期
hbase表默认保存一个版本的数据
hbase(main):123:0> create 't_name','st1'
Created table t_name
Took 1.3807 seconds
=> Hbase::Table - t_name
hbase(main):124:0> desc 't_name'
Table t_name is ENABLED
t_name
COLUMN FAMILIES DESCRIPTION
{NAME => 'st1', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENC
ODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WR
ITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}
1 row(s)
Took 0.0310 seconds
添加一个列族
hbase(main):126:0> alter 't_name',{NAME=>'st2'}
Updating all regions with the new schema...
All regions updated.
Done.
Took 1.5367 seconds
hbase(main):127:0> desc 't_name'
Table t_name is DISABLED
t_name
COLUMN FAMILIES DESCRIPTION
{NAME => 'st1', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENC
ODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WR
ITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}
{NAME => 'st2', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENC
ODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WR
ITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}
2 row(s)
Took 0.0147 seconds
修改版本数:
hbase(main):151:0> alter 't_name',{NAME=>'st1'},{NAME=>'st1',VERSIONS=>5}
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 3.6029 seconds
插入数据:
hbase(main):128:0> enable 't_name'
Took 1.2686 seconds
hbase(main):129:0> put 't_name','1','st1:name','xiaoma'
Took 0.0060 seconds
hbase(main):146:0> put 't_name','1','st1:age','30'
Took 0.0024 seconds
hbase(main):155:0> put 't_name','1','st1:age',100
Took 0.0028 seconds
hbase(main):157:0> put 't_name','1','st1:age',88
Took 0.0022 seconds
同一单元写入3次,查询:
hbase(main):158:0> scan 't_name'
ROW COLUMN+CELL
1 column=st1:age, timestamp=1526971520170, value=88
1 column=st1:name, timestamp=1526971227081, value=xiaoma
1 column=st2:level, timestamp=1526971286607, value=50
1 row(s)
Took 0.0042 seconds
hbase(main):173:0> get 't_name','1'
COLUMN CELL
st1:age timestamp=1526971520170, value=88
st1:name timestamp=1526971227081, value=xiaoma
st2:level timestamp=1526971286607, value=50
1 row(s)
Took 0.0037 seconds
发现查询结果为最后一次写入的值
查看历史版本:
hbase(main):174:0> get 't_name',1,{COLUMN=>'st1:age',VERSIONS=>1}
COLUMN CELL
st1:age timestamp=1526971520170, value=88
1 row(s)
Took 0.0055 seconds
hbase(main):175:0> get 't_name',1,{COLUMN=>'st1:age',VERSIONS=>2}
COLUMN CELL
st1:age timestamp=1526971520170, value=88
st1:age timestamp=1526971419514, value=100
1 row(s)
Took 0.0032 seconds
hbase(main):176:0> get 't_name',1,{COLUMN=>'st1:age',VERSIONS=>3}
COLUMN CELL
st1:age timestamp=1526971520170, value=88
st1:age timestamp=1526971419514, value=100
st1:age timestamp=1526971266685, value=30
1 row(s)
Took 0.0044 seconds
hbase(main):193:0> get 't_name','1',{COLUMN=> 'st1:age',TIMERANGE => [1526971266685,1526971520170] ,VERSIONS => 4}
COLUMN CELL
st1:age timestamp=1526971419514, value=100
st1:age timestamp=1526971266685, value=30
1 row(s)
Took 0.0039 seconds
hbase(main):194:0> get 't_name','1',{COLUMN=>'st1:age',TIMESTAMP=>1526971419514,VERSIONS=>4}
COLUMN CELL
st1:age timestamp=1526971419514, value=100
1 row(s)
Took 0.0028 seconds