From 20ee89aa4c37e15c404ef3b8599508a70cad750d Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Wed, 7 May 2008 16:58:10 +0000 Subject: [PATCH] HBASE-618 We always compact if 2 files, regardless of the compaction threshold setting git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@654169 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../hadoop/hbase/regionserver/HRegion.java | 4 +-- .../hadoop/hbase/regionserver/HStore.java | 36 +++++++++++-------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 91eba96b717..4ef7a984336 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -31,6 +31,7 @@ Hbase Change Log HBASE-607 MultiRegionTable.makeMultiRegionTable is not deterministic enough for regression tests HBASE-405 TIF and TOF use log4j directly rather than apache commons-logging + HBASE-618 We always compact if 2 files, regardless of the compaction threshold setting IMPROVEMENTS HBASE-559 MR example job to count table rows diff --git a/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java index d1875cd6423..c809eee426c 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -860,7 +860,7 @@ public class HRegion implements HConstants { return midKey; } } - LOG.info("starting compaction on region " + getRegionName()); + LOG.info("checking compaction on region " + getRegionName()); long startTime = System.currentTimeMillis(); doRegionCompactionPrep(); for (HStore store: stores.values()) { @@ -870,7 +870,7 @@ public class HRegion implements HConstants { } } doRegionCompactionCleanup(); - LOG.info("compaction completed on region " + getRegionName() + " in " + + LOG.info("compaction checking completed on region " + getRegionName() + " in " + StringUtils.formatTimeDiff(System.currentTimeMillis(), startTime)); } finally { synchronized (writestate) { diff --git a/src/java/org/apache/hadoop/hbase/regionserver/HStore.java b/src/java/org/apache/hadoop/hbase/regionserver/HStore.java index 287d873cfa4..1f7a4ee7766 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HStore.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HStore.java @@ -26,6 +26,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Collection; import java.util.Map; import java.util.Set; import java.util.SortedMap; @@ -737,6 +738,21 @@ public class HStore implements HConstants { ////////////////////////////////////////////////////////////////////////////// // Compaction ////////////////////////////////////////////////////////////////////////////// + + /* + * @param files + * @return True if any of the files in files are References. + */ + private boolean hasReferences(Collection files) { + if (files != null && files.size() > 0) { + for (HStoreFile hsf: files) { + if (hsf.isReference()) { + return true; + } + } + } + return false; + } /** * Compact the back-HStores. This method may take some time, so the calling @@ -763,30 +779,22 @@ public class HStore implements HConstants { List filesToCompact = null; synchronized (storefiles) { filesToCompact = new ArrayList(this.storefiles.values()); - if (filesToCompact.size() < 1) { - return checkSplit(); - } else if (filesToCompact.size() == 1) { - if (!filesToCompact.get(0).isReference()) { - return checkSplit(); - } - } else if (filesToCompact.size() < compactionThreshold) { + if (!hasReferences(filesToCompact) && + filesToCompact.size() < compactionThreshold) { return checkSplit(); } - if (!fs.exists(compactionDir) && !fs.mkdirs(compactionDir)) { LOG.warn("Mkdir on " + compactionDir.toString() + " failed"); return checkSplit(); } - // Storefiles are keyed by sequence id. The oldest file comes first. - // We need to return out of here a List that has the newest file first. - Collections.reverse(filesToCompact); - // The max-sequenceID in any of the to-be-compacted TreeMaps is the // last key of storefiles. - maxId = this.storefiles.lastKey().longValue(); } + // Storefiles are keyed by sequence id. The oldest file comes first. + // We need to return out of here a List that has the newest file first. + Collections.reverse(filesToCompact); // Step through them, writing to the brand-new MapFile HStoreFile compactedOutputFile = new HStoreFile(conf, fs, @@ -1801,4 +1809,4 @@ public class HStore implements HConstants { return copy; } } -} \ No newline at end of file +}