设计原则
设置预分区
原创大约 5 分钟
TTL
(过期失效时间,单位为秒)实现。下面的操作给表user
的列族info
设置了TTL
,超过这一时间后,数据将会在HFile
大合并时被自动删除。hbase:001:0> create 'user1', {NAME => 'info', TTL => '3600'}
hbase:001:0> desc 'user1'
Table user1 is ENABLED
user
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', ..., TTL => '600 SECONDS (10 MINUTES)', ...}
1 row(s)
Quota is disabled
Took 0.0381 seconds
每个HRegionServer
包含一个HLog
和多个HRegion
。
HLog
负责日志记录,针对HRegionServer
的所有写操作(例如put
、delete
等)都会先记录到这个日志中,然后再把数据写到对应的HRegion
。
HRegion
负责数据的存储,它的表面意思是区域
,HBase表中的数据会按照行被横向划分为多个Region
。
每个HRegion
按照存储的最小RowKey
和最大RowKey
指定,也就是个HRegion
包含的区间为[startRowKey, endRowKey)
,RowKey
是按升序排列的。
每一个列族
在HBase中都是一个单独的文件,对应一个Store
,每个HRegion
中都可能会有多个Store
。
就像操作MySQL数据库基本上都是通过编程语言实现的那样,操作HBase中的数据也需要通过API来完成。
先引入依赖。
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>2.4.18</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-mapreduce</artifactId>
<version>2.4.18</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>3.2.0</version>
<scope>provided</scope>
</dependency>
HBase中的命令分为两类。
基础命令。
SQL
命令。
其中SQL
命令又分为DDL
命令和DML
命令。
status
可以查看集群当前的状态。
hbase:001:0> status
1 active master, 0 backup masters, 1 servers, 0 dead, 3.0000 average load
Took 0.0017 seconds