HBase system architecture and data structure

First, the basic concept

Hbase Table A typical table is as follows:

1.1 Row Key (OK key)

Row KeyIt is the primary key used to retrieve records. You want to access data in HBase Table, only the following three ways:

  • By specifying the Row Keyaccess;
  • Row Key access through the range, i.e. access line within a specified range;
  • A full table scan.

Row KeyIt can be any string, when storing data in Row Keythe lexicographic order. It should be noted that the following two points:

  • Because lexicographical sort of Int result 1,10,100,11,12,13,14,15,16,17,18,19,2,20,21, ..., 9,91,92,93,94,95 , 96,97,98,99. If you use integer string as row keys, then in order to maintain the natural sequence of integers, 0 row keys must be left to fill.
  • Atomic (regardless of how many write a column) when a row of read and write operations.

1.2 Column Family (column family)

Each column HBase table, belongs to a family row. Schema column family is part of the table, the column families need to be defined when creating the table. All columns column families are in a column family name as a prefix, for example courses:history, courses:mathbelong to coursesthis column family.

1.3 Column Qualifier (column qualifier)

Column qualifier, you can be understood as a specific column name, for example courses:history, courses:mathbelong to coursesthis column families, their columns are the qualifiers historyand math. Note that the table is not part of the column qualifier Schema, you can dynamically create columns in the process of inserting data.

1.4 Column (column)

HBase columns by the column and row group qualifiers, which are the :separated (colon), i.e., a full name should be expressed as a column 列族名 :列限定符.

1.5 Cell

CellRow, column and row combinations qualifier group, and contains a timestamp value. You can be understood as the equivalent of a cell is determined by the specified row and a specified column of a relational database, but is a different cell HBase is a plurality of versions of data, each of which version of the data time stamp make that distinction.

1.6 Timestamp (time stamp)

HBase by row keyand columndetermined is referred to as a memory cell Cell. Each Cellis saved with multiple versions of the same data. Indexed by timestamp version, type is 64-bit integer time stamp, the time stamp can be automatically assigned by the data write HBase, you may be explicitly specified by the customer. In each Cell, the different versions of data are arranged in reverse time stamp, i.e. the newest data at the top.

Second, the storage structure

2.1 Regions

All rows HBase Table in accordance with Row Keythe dictionary arrangement order. HBase Tables by range (row key range) row of keys is cut into a plurality of levels Region, one Regioncontaining all the lines between the start key and the end key.

Each table is only a start Region, as data continues to increase, Regionwill continue to increase, when the increase to a threshold of time, Regionit will divided into two new Region. When growing in Table row, there will be more and more Region.

RegionHBase is the distributed storage load balancing and minimum unit . This means that different Regioncan be distributed in a different Region Serveron. But one Regionis not split into multiple Server.

2.2 Region Server

Region ServerRunning on HDFS's DataNode. It has the following components:

  • WAL (Write Ahead Log, write-ahead log) : Not used for storing data into the persistent store records for recovery if a failure occurs.
  • BlockCache : read cache. It frequently read data stored in memory, if the memory is insufficient, it will follow 最近最少使用原则to remove excess data.
  • Memstore : write cache. It has not write new data storage disk and will be sorted before the data is written to disk. Each column family on each Region has a MemStore.
  • HFile : line data in accordance with the Key \ Values is stored on the file system.

Region Server存取一个子表时,会创建一个Region对象,然后对表的每个列族创建一个Store实例,每个Store会有 0 个或多个StoreFile与之对应,每个StoreFile则对应一个HFile,HFile 就是实际存储在HDFS上的文件。

三、Hbase系统架构

3.1 系统架构

HBase系统遵循Master/Salve架构,由三种不同类型的组件组成:

Zookeeper

  1. 保证任何时候,集群中只有一个Master;
  2. 存贮所有Region的寻址入口;
  3. 实时监控Region Server的状态,将Region Server的上线和下线信息实时通知给Master;
  4. 存储HBase的Schema,包括有哪些Table,每个Table有哪些Column Family等信息。

Master

  1. 为Region Server分配Region ;
  2. 负责Region Server的负载均衡 ;
  3. 发现失效的Region Server并重新分配其上的Region;
  4. GFS上的垃圾文件回收;
  5. 处理Schema的更新请求。

Region Server

  1. Region Server负责维护Master分配给它的Region ,并处理发送到Region上的IO请求;
  2. Region Server负责切分在运行过程中变得过大的Region。

3.2 组件间的协作

HBase使用ZooKeeper作为分布式协调服务来维护集群中的服务器状态。 Zookeeper负责维护可用服务列表,并提供服务故障通知等服务:

  • 每个Region Server都会在ZooKeeper上创建一个临时节点,Master通过Zookeeper的Watcher机制对节点进行监控,从而可以发现新加入的Region Server或故障退出的Region Server;
  • 所有Masters会竞争性地在Zookeeper上创建同一个临时节点,由于Zookeeper只能有一个同名节点,所以必然只有一个Master能够创建成功,此时该Master就是主Master,主Master会定期向Zookeeper发送心跳。备用Masters则通过Watcher机制对主HMaster所在节点进行监听;
  • 如果主Master未能定时发送心跳,则其持有的Zookeeper会话会过期,相应的临时节点也会被删除,这会触发定义在该节点上的Watcher事件,使得备用的Master Servers得到通知。所有备用的Master Servers在接到通知后,会再次去竞争性地创建临时节点,完成主Master的选举。

四、数据的读写流程简述

4.1 写入数据的流程

  1. Client向Region Server提交写请求;
  2. Region Server找到目标Region;
  3. Region检查数据是否与Schema一致;
  4. 如果客户端没有指定版本,则获取当前系统时间作为数据版本;
  5. 将更新写入WAL Log;
  6. 将更新写入Memstore;
  7. 判断Memstore存储是否已满,如果存储已满则需要flush为Store Hfile文件。

更为详细写入流程可以参考:HBase - 数据写入流程解析

4.2 读取数据的流程

以下是客户端首次读写HBase上数据的流程:

  1. 客户端从Zookeeper获取META表所在的Region Server;
  2. 客户端访问META表所在的Region Server,从META表中查询到访问行键所在的Region Server,之后客户端将缓存这些信息以及META表的位置;
  3. 客户端从行键所在的Region Server上获取数据。

如果再次读取,客户端将从缓存中获取行键所在的Region Server。这样客户端就不需要再次查询META表,除非Region移动导致缓存失效,这样的话,则将会重新查询并更新缓存。

注:META表是HBase中一张特殊的表,它保存了所有Region的位置信息,META表自己的位置信息则存储在ZooKeeper上。

更为详细读取数据流程参考:

HBase原理-数据读取流程解析

HBase原理-迟到的‘数据读取流程部分细节

参考资料

本篇文章内容主要参考自官方文档和以下两篇博客,图片也主要引用自以下两篇博客:

官方文档:

更多大数据系列文章可以参见个人 GitHub 开源项目: 大数据入门指南

Guess you like

Origin www.cnblogs.com/danrenying/p/11079855.html
Recommended