HBase选择Store file做compaction的算法(3)

// if we don't have enough files to compact, just wait
        if (end - start < this.compactionThreshold) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("Skipped compaction of " + this.storeNameStr
              + " because only " + (end - start) + " file(s) of size "
              + StringUtils.humanReadableInt(totalSize)
              + " meet compaction criteria.");
          }
          return checkSplit(forceSplit);
        }

if (0 == start && end == countOfFiles) {
          // we decided all the files were candidates! major compact
          majorcompaction = true;
        } else {
          // 从待compaction的store file list中先切除一批满足条件的store file去做min compaction
          filesToCompact = new ArrayList<StoreFile>(filesToCompact.subList(start,
            end));
        }
        // 进入if的条件是major compaction为false,出来的时候major compaction可能是false,也可能是true
      } else {
        // all files included in this compaction
        for (long i : fileSizes) {
          totalSize += i;
        }
      }
      this.lastCompactSize = totalSize;

// Max-sequenceID is the last key in the files we're compacting
      long maxId = StoreFile.getMaxSequenceIdInList(filesToCompact);

// Ready to go.  Have list of files to compact.
      LOG.info("Started compaction of " + filesToCompact.size() + " file(s) in cf=" +
          this.storeNameStr +
        (references? ", hasReferences=true,": " ") + " into " +
          region.getTmpDir() + ", seqid=" + maxId +
          ", totalSize=" + StringUtils.humanReadableInt(totalSize));
      // 选择好了store file, compact就是真正去做merge的函数了
      StoreFile.Writer writer = compact(filesToCompact, majorcompaction, maxId);
      // Move the compaction into place.
      StoreFile sf = completeCompaction(filesToCompact, writer);
      if (LOG.isInfoEnabled()) {
        LOG.info("Completed" + (majorcompaction? " major ": " ") +
          "compaction of " + filesToCompact.size() +
          " file(s), new file=" + (sf == null? "none": sf.toString()) +
          ", size=" + (sf == null? "none": StringUtils.humanReadableInt(sf.getReader().length())) +
          "; total size for store is " + StringUtils.humanReadableInt(storeSize));
      }
    }
    return checkSplit(forceSplit);
  }

2011.12.13添加
 
几个关于compaction的hbase jira:
 
HBASE-3189 Stagger Major Compactions
 
HBASE-3209 : New Compaction Algorithm
 
HBASE-1476 Multithreaded Compactions
 
HBASE-3857 Change the HFile Format

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/f1a07c90478d39354a606428e68eaeb5.html