HBase是将数据存在hdfs上面的。那么RegionServer全局的Flush都有可能会在hdfs上面形成很多的小文件,这是很浪费资源的。具体的浪费资源指的是:一个文件在hdfs上面都要消耗Namenode的150byte去存这个文件的元数据信息。所以Hbase要去对小的文件进行compact。
Minor Compaction(将一个小的文件合并成几个大的)
默认的,当文件数量>= 3的时候,Minor合并的时候也会触发Major compaction
相同rowkey的数据在进行minor合并的时候,不会删除数据。
相关参数:
每个minor compaction操作的 允许的最大hfile文件上限
<property>
<name>hbase.hstore.compaction.max</name>
<value>10</value>
<description>Max number of HStoreFiles to compact per 'minor'
compaction.</description>
</property>
Major Compaction(全局的合并,最后只会生成一个大文件)
相同rowkey的数据在进行minor合并的时候,会删除timestamp较小的数据。
一个region进行 major compaction合并的周期,在这个点的时候, 这个region下的所有StoreFile会进行合并,默认是7天,major compaction非常耗资源,建议生产关闭(设置为0),在应用空闲时间手动触发。
<property>
<name>hbase.hregion.majorcompaction</name>
<value>604800000</value>
<description>The time (in miliseconds) between 'major' compactions of
all
HStoreFiles in a region. Default: Set to 7 days. Major compactions tend to
happen exactly when you need them least so enable them such that they
run at
off-peak for your deploy; or, since this setting is on a periodicity that is
unlikely to match your loading, run the compactions via an external
invocation out of a cron job or some such.
</description>
</property>
一个store里面允许存的StoreFile的个数,超过这个个数会被写到新的一个StoreFile里面 也即是每个region的每个列族对应的memstore在fulsh为hfile的时候,默认情况下当超过3个hfile的时候就会对这些文件进行合并重写为一个新文件,设置个数越大可以减少触发合并的时间,但是每次合并的时间就会越长
<property>
<name>hbase.hstore.compactionThreshold</name>
<value>3</value>
<description>
If more than this number of HStoreFiles in any one HStore
(one HStoreFile is written per flush of memstore) then a compaction
is run to rewrite all HStoreFiles files as one. Larger numbers
put off compaction but when it runs, it takes longer to complete.
</description>
</property>