hbase 源代码分析 (15)compact 过程

上一个章节分析了spit过程。当时遗留了compact问题没有分析。这个章节将重点分析一下。

compact流程: 
这个流程没有写完,涉及都行太多了,都没有心情写了。先留着吧,


入口:HStore.java 结束flush之后,会做这样一个判断。
   
   
  1. private boolean updateStorefiles(final List<StoreFile> sfs, final long snapshotId)
  2. throws IOException {
  3. return needsCompaction();
  4. }
主要比较
public boolean needsCompaction(final Collection<StoreFile> storeFiles,
    final List<StoreFile> filesCompacting) {
  int numCandidates = storeFiles.size() - filesCompacting.size();
  return numCandidates >= comConf.getMinFilesToCompact();
}
minFilesToCompact = Math.max(2, conf.getInt(HBASE_HSTORE_COMPACTION_MIN_KEY,
      /*old name*/ conf.getInt("hbase.hstore.compactionThreshold", 3)));
public static final String HBASE_HSTORE_COMPACTION_MIN_KEY = "hbase.hstore.compaction.min";
当然还有一些守候进程会去触发compact
   
   
  1. // Cache flushing thread.
  2. this.cacheFlusher = new MemStoreFlusher(conf, this);
  3. // Compaction thread
  4. this.compactSplitThread = new CompactSplitThread(this);
    1. // Background thread to check for compactions; needed if region has not gotten updates
  5. // in a while. It will take care of not checking too frequently on store-by-store basis.
  6. this.compactionChecker = new CompactionChecker(this, this.threadWakeFrequency, this);
  7. this.periodicFlusher = new PeriodicMemstoreFlusher(this.threadWakeFrequency, this);

1)如果触发了compact ,需要针对当前region的每个store进行compact,在CompatSpitThread.java 
   
   
  1. private List<CompactionRequest> requestCompactionInternal(final Region r, final String why,
  2. int p, List<Pair<CompactionRequest, Store>> requests, boolean selectNow, User user)
  3. throws IOException {
  4. for (Store s : r.getStores()) {
  5. CompactionRequest cr = requestCompactionInternal(r, s, why, p, null, selectNow, user);
  6. }
  7. }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值