上一个章节分析了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-by-store basis.
this.compactionChecker = new CompactionChecker(this, this.threadWakeFrequency, this);
this.periodicFlusher = new PeriodicMemstoreFlusher(this.threadWakeFrequency, this);
1)如果触发了compact ,需要针对当前region的每个store进行compact,在CompatSpitThread.java
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);
}
}