HBase(Hadoop Database)是 Google Bigtable 的开源实现,一个高可靠、高性能、面向列、可伸缩的分布式存储系统,可在廉价 PC Server 上搭建大规模结构化存储集群。它以 Hadoop HDFS 为底层存储、MapReduce 为计算框架、Zookeeper 为协同服务,位于 Hadoop EcoSystem 的结构化存储层,Pig、Hive 提供高层语言支持,Sqoop 负责 RDBMS 数据导入。访问接口包括 Native Java API、HBase Shell、Thrift/REST Gateway、Pig、Hive 等。
数据模型方面,Table 由 Row Key、Timestamp 和多个 Column Family 组成,Column Family 支持动态扩展,数据以二进制存储。Table 随数据增长分裂为 Region,由 Master 分配给 RegionServer 管理;客户端通过 Zookeeper→-ROOT-→.META. 三级寻址定位数据,并做 cache 缓存。HBase 还提供 TableInputFormat/TableOutputFormat,方便将表作为 MapReduce 的 Source 和 Sink。
系统架构上,HMaster 负责 Table 与 Region 管理、负载均衡和故障恢复,借助 Zookeeper 的 Master Election 消除单点;HRegionServer 响应 I/O 请求,内部的 HStore 由 MemStore 和 StoreFiles 组成,写入先进内存,经 Flush、Compaction、Split 逐步落盘,更新删除在 compact 中完成,保证写高性能。HLog 以 WAL 机制防宕机丢数据,故障后由 Master 拆分 Replay 恢复。存储格式上 StoreFile 底层为 HFile(Data Block 为 I/O 基本单元,含 LRU Block Cache),HLog 则是 Hadoop Sequence File。一淘的存储系统即基于 HBase 搭建。