There are two types of compactions: minor and major. Minor compactions will usually pick up a couple of the smaller adjacent StoreFiles and rewrite them as one. Minors do not drop deletes or expired cells, only major compactions do this. Sometimes a minor compaction will pick up all the StoreFiles in the Store and in this case it actually promotes itself to being a major compaction.
After a major compaction runs there will be a single StoreFile per Store, and this will help performance usually. Caution: major compactions rewrite all of the Stores data and on a loaded system, this may not be tenable; major compactions will usually have to be done manually on large systems.
判断是否进行minor compaction
基于compaction policy来判断, 当前1.2.0版本的默认policy 是 RatioBasedCompactionPolicy, 根据当前的 num of storeFiles - num of compaction files > minFilesToCompact(默认为3)
hbase 特点
rowKey 的设计
tall-Narrow 模式 例如查找查找一个用户的所有邮件 可以这样设计 userId-date-messageId-attachmentId 可以用prefixFilter查询
flat-wide mode userId为rowKey, valueId为Column key, 很多相同的rowKey,
为什么tall模式比wide模式快 因为HFile的下一级存储模式是key-value, 结构如下: 可以更快的获取到column qualifier
hbase 命令
hbase 架构
RS下有多个region, 根据rowkey的分布均匀分布在多个region; 一个table的数据分布在多个region, 一个CF对应一个store, 一个memstore, 一个store下面对应多个storeFile,一个storeFile由多个hdfs的block组成
hbase 读流程
hbase写流程
Hbase 写入流程(网易-范欣欣)
hive数据批量写入hbase
问题
Memstore Flush
Memstore级别限制 当Region中任意一个MemStore的大小达到了上限(hbase.hregion.memstore.flush.size,默认128MB),会触发Memstore刷新。
Region级别限制 当Region中所有Memstore的大小总和达到了上限(hbase.hregion.memstore.block.multiplier hbase.hregion.memstore.flush.size,默认 4 128M),会触发memstore刷新。
Region Server级别限制 当一个Region Server中所有Memstore的大小总和达到了上限(hbase.regionserver.global.memstore.upperLimit * hbase_heapsize,默认 40%的JVM内存使用量),会触发部分Memstore刷新。Flush顺序是按照Memstore由大到小执行,先Flush Memstore最大的Region,再执行次大的,直至总体Memstore内存使用量低于阈值(hbase.regionserver.global.memstore.lowerLimit * hbase_heapsize,默认 38%的JVM内存使用量)。当一个Region Server中HLog数量达到上限(可通过参数hbase.regionserver.maxlogs配置)时,系统会选取最早的一个 HLog对应的一个或多个Region进行flush
HBase定期刷新Memstore 默认周期为1小时,确保Memstore不会长时间没有持久化。为避免所有的MemStore在同一时间都进行flush导致的问题,定期的flush操作有20000左右的随机延时。
手动执行flush 用户可以通过shell命令 flush ‘tablename’或者flush ‘region name’分别对一个表或者一个Region进行flush。
Compaction
流程
触发时机
文件选择策略
如果不满足major compaction条件,就必然为minor compaction,HBase主要有两种minor策略:RatioBasedCompactionPolicy和ExploringCompactionPolicy,
After a major compaction runs there will be a single StoreFile per Store, and this will help performance usually. Caution: major compactions rewrite all of the Stores data and on a loaded system, this may not be tenable; major compactions will usually have to be done manually on large systems.
hbase major和minor compaction源码解析(待测试和根据博文hbase compaction 深入研究,了解几个策略的不同)
前言 本来只想围绕 触发条件, 触发周期, 内部流程, 外部影响, 如何控制几个方面来看这个代码, 忽略不重要的细节, 以了解整体流程为主要目的, 相信这也是看源码的一个指导方针吧(不然只见树木不见森林),但是从入口这里 线程池的抽象挺有意思.
ChoreService,chore原意为工人,这里可以把这个类理解为包工头,内部有个线程池和一个管理着每个工人返回结果的map 工人默认每隔十秒钟检查一次, compactionChecker里面有个mutilper, 变成每隔 compactionchecker.interval.multiplier(默认1000) thread.wakefrequecy(默认10 1000) 毫秒执行一次check
判断是否进行minor compaction 基于compaction policy来判断, 当前1.2.0版本的默认policy 是 RatioBasedCompactionPolicy, 根据当前的 num of storeFiles - num of compaction files > minFilesToCompact(默认为3)
判断是否是MajorCompaction 首先基础间隔是 hbase.hregion.majorcompaction = 七天 , 并根据majorcompaction.jitter 作浮动, 根据 storeFiles中文件最早的修改时间距离今天已经超过了间隔时间, 则进行MC 可通过配置 hbase.hregion.majorcompaction = 0 来全局关闭 MC.
可在 建表的时候指定 COMPACTION => false来关闭所有的compaction
region split
产生条件 smaller(设置的最大的region size(默认10 GB), current region number的立方 2 memory flush size)
compaction和split为何会影响 IO? 亦或是其他?需要实验
关闭 auto split
手动触发major compaction
zookeeper在hbase中的作用
dataType
hbase important configuration