---
title: "HBase compaction行为及触发条件"
author: "Vitas_Wang"
date: "2013-10-25T16:41:41Z"
tags: []
categories: ["开源软件"]
slug: "hbase-compaction"
draft: false
lastmod: "2013-10-25T16:41:41Z"
id: 1964708
url: "https://jaler.iteye.com/blog/1964708"
---

HBase compaction come in two varieties: minor and major.

for the minor:

将最新的几个小文件合成一个大文件。

何时合并行为发生？

当文件满足下面所有条件时，合并行为将发生：

1&gt; 参与合并的文件个数 &gt;= hbase.hstore.compaction.min (default is 3), 但最多不超过hbase.hstore.compaction.max(default is 10)

2&gt; 参与合并的文件需满足的条件： 

文件大小 &lt; hbase.hstore.compaction.max.size (default is Long.MAX\_VALUE)

且，文件大小 &lt; 所有创建日期比该文件大（新）的文件大小之和\*1.2

文件大小 &lt; hbase.hstore.compactoin.min.size(memstore flush size)

3&gt; 文件选择的优先级

优先考虑老文件。

for the major:

将所有文件合并

Which compaction type is run is automatically determined when the compaction

check is executed。 The check is triggered either after a memstore has been flushed to

disk, after the compact or major\_compact shell commands or corresponding API calls

have been invoked, or by a background thread.