Good programmers Big Data learning route hbase Quick Start Hbase Profile

Good programmers Big Data learning route hbase Quick Start Hbase Profile

1.Hbase What is

Apache HBase Hadoop database is a distributed, scalable large data storage.

When you need a large random data, real-time read when / write access, use the Apache HBase. The objective of the project is very large tables hosted on commodity hardware cluster - column billions of rows of one million. Apache HBase is an open source, distributed, versioned, non-relational database, which mimics Google's Bigtable: a distributed storage system structured data, like Google Bigtable use of distributed data storage file system provides Like, Apache HBase provides similar functionality bigtable on Hadoop and HDFS

1) .Hbase features

Large: a table can be billions of rows on one million;

No Mode: Each line has a primary sort key and any number of columns, the column can be increased as needed dynamically, with a different row in the table can have distinct columns;

Column-oriented: oriented column (group) and memory access control, the column (group) independent retrieval;

Sparse: For empty ( column null) and does not take up storage space, you can watch design is very sparse;

Multiple versions of data: the data in each cell may have multiple versions, the version number is automatically assigned by default, the time stamp is inserted into the cell;

Single Data Type: Data are Hbase the string, no type.

2) .Hbase compared with the relational database


Traditional line database:

Data is stored in rows

Not indexed queries using a large number of I / O

Indexing and materialized views need to spend a lot of time and resources

The demand for the query, the database must be expanded to meet the performance requirements of a large number of

Columnar database :

Data are stored in columns - each column separately stored

That is the index data

Access refers to the column involved in the query - a significant reduction in system I / O

Each column consists of a clue to handle - handle concurrent queries

 Consistent with the data type, data of similar characteristics - Efficient Compression

3) .Hbase with HDFS contrast


Both have good fault tolerance and scalability, it can be extended to hundreds of nodes;

HDFS for Batch scene

Find data do not support random

Not suitable for handling incremental data

It does not support data update

2.Hbase architecture


1).Client

 HBase Client using HBase the RPC mechanism HMaster and HRegionServer communication, management class for operation, Client HMaster performed with RPC; classes for data read and write operations, the Client HRegionServer for RPC.

2).Zookeeper

 Zookeeper Quorum in addition to storing the -ROOT- address table and HMaster address, HRegionServer will put itself in Ephemeral Register to  Zookeeper, making HMaster can perceive the health status of each HRegionServer at any time. In addition, Zookeeper HMaster also avoids the problem of a single point.

3).Hmaster
  • 管理用户对Table的增、删、改、查操作;

  • 管理HRegion Server的负载均衡,调整Region分布;

  • Region Split后,负责新Region的分配;

  • HRegion Server停机后,负责失效HRegion Server 上的Regions迁移。

4).Region


 当表的大小超过设置值的时候,HBase会自动地将表划分为不同的区域,每个区域包含所有行的一个子集。对用户来说,每个表是一堆数据的集合,靠主键来区分。从物理上来说,一张表被拆分成了多块,每一块就是一个Region。我们用表名+开始/结束主键,来区分每一个Region,一个Region会保存一个表里面某段连续的数据,从开始主键到结束主键,一张完整的表格是保存在多个Region上面。

5).HRegion Server

 所有的数据库数据一般是保存在Hadoop HDFS分布式文件系统上面,用户通过一系列HRegion Server获取这些数据,一台机器上面一般只运行一个HRegion Server,且每一个区段的HRegion也只会被一个HRegion Server维护。下面是HRegion Server数据存储关系图。


 HRegion Server主要负责响应用户I/O请求,向HDFS文件系统中读写数据,是HBase中最核心的模块。

 HRegion Server内部管理了一系列HRegion对象,每个HRegion对应了Table中的一个RegionRegion中由多个Store组成。每个Store对应了Table中的一个Column Family的存储,可以看出每个Column Family其实就是一个集中的存储单元,因此最好将具备共同IO特性的column放在一个Column Family中,这样最高效。

  Store存储是HBase存储的核心了,其中由两部分组成,一部分是MemStore,一部分是StoreFilesMemStoreSorted Memory Buffer,用户写入的数据首先会放入MemStore,当MemStore满了以后会Flush成一个StoreFile(底层实现是HFile), StoreFile文件数量增长到一定阈值,会触发Compact合并操作,将多个StoreFiles合并成一个StoreFile,合并过程中会进行版本合并和数据删除,因此可以看出HBase其实只有增加数据,所有的更新和删除操作都是在后续的compact过程中进行的,这使得用户的写操作只要进入内存中就可以立即返回,保证了HBase I/O的高性能。当StoreFiles Compact后,会逐步形成越来越大的StoreFile,当单个StoreFile大小超过一定阈值后,会触发Split操作,同时把当前Region Split2Region,父Region会下线,新Split出的2个孩子Region会被HMaster分配到相应的HRegionServer 上,使得原先1个Region的压力得以分流到2个Region上。下图描述了Compaction和Split的过程。


    Compaction和Split的过程

 在理解了上述HStore的基本原理后,还必须了解一下HLog的功能,因为上述的HStore在系统正常工作的前提下是没有问题的,但是在分布式系统环境中,无法避免系统出错或者宕机,因此一旦HRegion Server意外退出,MemStore中的内存数据将会丢失,这就需要引入HLog了。每个HRegion Server中都有一个HLog对象,HLog是一个实现Write Ahead Log的类,在每次用户操作写入MemStore的同时,也会写一份数据到HLog文件中(HLog文件格式见后续),HLog文件定期会滚动出新的,并删除旧的文件(已持久化到StoreFile中的数据)。当HRegion Server意外终止后,HMaster会通过Zookeeper感知到,HMaster首先会处理遗留的 HLog文件,将其中不同RegionLog数据进行拆分,分别放到相应region的目录下,然后再将失效的region重新分配,领取到这些region的HRegion Server在Load Region的过程中,会发现有历史HLog需要处理,因此会Replay HLog中的数据到MemStore中,然后flush到StoreFiles,完成数据恢复。

6).Hbase的存储格式

 HBase中的所有数据文件都存储在Hadoop HDFS文件系统上为例,主要包括上述提出的两种文件类型:HFile, HBase中KeyValue数据的存储格式,HFile是Hadoop的二进制格式文件,实际上StoreFile就是对HFile做了轻量级包装,即StoreFile底层就是HFile。HLog File,HBase中WAL(Write Ahead Log) 的存储格式,物理上是Hadoop的Sequence File。

7).ROOT表和META

 用户表的Regions元数据被存储在.META.表中,随着Region的增多,.META.表中的数据也会增大,并分裂成多个Regions。为了定位.META.表中各个Regions的位置,把.META.表中所有Regions的元数据保存在-ROOT-表中,最后由ZooKeeper记录-ROOT-表的位置信息。所有客户端访问用户数据前,需要首先访问ZooKeeper获得-ROOT-的位置,然后访问-ROOT-表获得.META.表的位置,最后根据.META.表中的信息确定用户数据存放的位置,如下图所示。


 -ROOT-表永远不会被分割,它只有一个Region,这样可以保证最多需要三次跳转就可以定位任意一个Region。为了加快访问速度,.META.表的Regions全部保存在内存中。客户端会将查询过的位置信息缓存起来,且缓存不会主动失效。如果客户端根据缓存信息还访问不到数据,则询问只有相关.META.表的Region服务器,试图获取数据的位置,如果还是失败,则询问-ROOT-表相关的.META.表在哪里。最后,如果前面的信息全部失效,则通过ZooKeeper重新定位Region的信息。所以如果客户端上的缓存全部是失效,则需要进行6次网络来回,才能定位到正确的Region。


8).MapReduce On HBase

 HBase系统上运行批处理运算,最方便和实用的模型依然是MapReduce,如下图:


 HBase Table和Region的关系,比较类似HDFS File和Block的关系,HBase提供了配套的TableInputFormat和TableOutputFormat API,可以方便的将HBase Table作为Hadoop MapReduce的Source和Sink,对于MapReduce Job应用开发人员来说,基本不需要关注HBase系统自身的细节。

3.HBase数据模型


 以关系型数据的思维下会感觉,上面的表格是一个5列4行的数据表格,但是在HBase中这种理解是错误的,其实在HBase中上面的表格只是一行数据;

1).Row Key:

 – 决定一行数据的唯一标识

 – RowKey是按照字典顺序排序的。

 – Row key最多只能存储64k的字节数据。

2).Column Family列族(CF1CF2CF3) & qualifier列:

 – HBase表中的每个列都归属于某个列族,列族必须作为表模式(schema) 定义的一部分预先给出。如create ‘test’, ‘course’;

 – 列名以列族作为前缀,每个“列族”都可以有多个列成员(column,每个列族中可以存放几千~上千万个列);如 CF1:q1, CF2:qw,

 新的列族成员(列)可以随后按需、动态加入,Family下面可以有多个Qualifier,所以可以简单的理解为,HBase中的列是二级列,

 也就是说Family是第一级列,Qualifier是第二级列。两个是父子关系。

 – 权限控制、存储以及调优都是在列族层面进行的;

 – HBase把同一列族里面的数据存储在同一目录下,由几个文件保存。

 – 目前为止HBase的列族能能够很好处理最多不超过3个列族。

3).Timestamp时间戳:

 – 在HBase每个cell存储单元对同一份数据有多个版本,根据唯一的时间 戳来区分每个版本之间的差异,不同版本的数据按照时间倒序排序,

 最新的数据版本排在最前面。

 – 时间戳的类型是64位整型。

 – 时间戳可以由HBase(在数据写入时自动)赋值,此时时间戳是精确到毫 秒的当前系统时间。

 – 时间戳也可以由客户显式赋值,如果应用程序要避免数据版本冲突, 就必须自己生成具有唯一性的时间戳。

4).Cell单元格:

 – 由行和列的坐标交叉决定;

 – 单元格是有版本的(由时间戳来作为版本);

 – 单元格的内容是未解析的字节数组(Byte[]),cell中的数据是没有类型的,全部是字节码形式存贮。

 • 由{row key,column(= +),version}唯一确定的单元。

4.Hbase应用介绍

  • –列族结构经常调整

  • –高并发写入

  • –结构化数据、半结构化数据存储

  • –Key-Value存储

  • –有序存储

  • –固定集合(多版本)

  • –定时删除记录(TTL)


Guess you like

Origin blog.51cto.com/14256902/2424603