hbase 原始碼分析 (15)compact 過程
阿新 • • 發佈:2019-01-24
上一個章節分析了spit過程。當時遺留了compact問題沒有分析。這個章節將重點分析一下。
compact流程:
這個流程沒有寫完,涉及都行太多了,都沒有心情寫了。先留著吧,
入口:HStore.java 結束flush之後,會做這樣一個判斷。
private boolean updateStorefiles(final List<StoreFile> sfs, final long snapshotId)
throws IOException{
return needsCompaction();
}
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;
//Cache flushing thread.
this.cacheFlusher = new MemStoreFlusher(conf, this);
- //Compaction thread
this.compactSplitThread = new CompactSplitThread(this);
- //Background thread to check for compactions; needed if region has not gotten updates
//in a while.It will take care of not checking too frequently on store
this.compactionChecker = new CompactionChecker(this, this.threadWakeFrequency, this);
this.periodicFlusher = new PeriodicMemstoreFlusher(this.threadWakeFrequency, this);
private List<CompactionRequest> requestCompactionInternal(final Region r, final String why,
int p,List<Pair<CompactionRequest,Store>> requests, boolean selectNow,User user)
throws IOException{
for(Store s : r.getStores()){
CompactionRequest cr = requestCompactionInternal(r, s, why, p, null, selectNow, user);
}
}