Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6D0B11086B for ; Mon, 10 Jun 2013 20:53:53 +0000 (UTC) Received: (qmail 74995 invoked by uid 500); 10 Jun 2013 20:53:53 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 74964 invoked by uid 500); 10 Jun 2013 20:53:53 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 74955 invoked by uid 99); 10 Jun 2013 20:53:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Jun 2013 20:53:53 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Jun 2013 20:53:52 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D28722388A32; Mon, 10 Jun 2013 20:53:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1491598 - /hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactionTool.java Date: Mon, 10 Jun 2013 20:53:32 -0000 To: commits@hbase.apache.org From: sershe@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130610205332.D28722388A32@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sershe Date: Mon Jun 10 20:53:32 2013 New Revision: 1491598 URL: http://svn.apache.org/r1491598 Log: HBASE-8683 Add major compaction support in CompactionTool (Jerry He) Modified: hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactionTool.java Modified: hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactionTool.java URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactionTool.java?rev=1491598&r1=1491597&r2=1491598&view=diff ============================================================================== --- hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactionTool.java (original) +++ hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactionTool.java Mon Jun 10 20:53:32 2013 @@ -79,6 +79,7 @@ public class CompactionTool extends Conf private final static String CONF_TMP_DIR = "hbase.tmp.dir"; private final static String CONF_COMPACT_ONCE = "hbase.compactiontool.compact.once"; + private final static String CONF_COMPACT_MAJOR = "hbase.compactiontool.compact.major"; private final static String CONF_DELETE_COMPACTED = "hbase.compactiontool.delete"; private final static String CONF_COMPLETE_COMPACTION = "hbase.hstore.compaction.complete"; @@ -104,41 +105,43 @@ public class CompactionTool extends Conf /** * Execute the compaction on the specified path. * - * @param path Directory path on which run a + * @param path Directory path on which to run compaction. * @param compactOnce Execute just a single step of compaction. + * @param major Request major compaction. */ - public void compact(final Path path, final boolean compactOnce) throws IOException { + public void compact(final Path path, final boolean compactOnce, final boolean major) throws IOException { if (isFamilyDir(fs, path)) { Path regionDir = path.getParent(); Path tableDir = regionDir.getParent(); HTableDescriptor htd = FSTableDescriptors.getTableDescriptor(fs, tableDir); HRegionInfo hri = HRegionFileSystem.loadRegionInfoFileContent(fs, regionDir); - compactStoreFiles(tableDir, htd, hri, path.getName(), compactOnce); + compactStoreFiles(tableDir, htd, hri, path.getName(), compactOnce, major); } else if (isRegionDir(fs, path)) { Path tableDir = path.getParent(); HTableDescriptor htd = FSTableDescriptors.getTableDescriptor(fs, tableDir); - compactRegion(tableDir, htd, path, compactOnce); + compactRegion(tableDir, htd, path, compactOnce, major); } else if (isTableDir(fs, path)) { - compactTable(path, compactOnce); + compactTable(path, compactOnce, major); } else { throw new IOException( "Specified path is not a table, region or family directory. path=" + path); } } - private void compactTable(final Path tableDir, final boolean compactOnce) + private void compactTable(final Path tableDir, final boolean compactOnce, final boolean major) throws IOException { HTableDescriptor htd = FSTableDescriptors.getTableDescriptor(fs, tableDir); for (Path regionDir: FSUtils.getRegionDirs(fs, tableDir)) { - compactRegion(tableDir, htd, regionDir, compactOnce); + compactRegion(tableDir, htd, regionDir, compactOnce, major); } } private void compactRegion(final Path tableDir, final HTableDescriptor htd, - final Path regionDir, final boolean compactOnce) throws IOException { + final Path regionDir, final boolean compactOnce, final boolean major) + throws IOException { HRegionInfo hri = HRegionFileSystem.loadRegionInfoFileContent(fs, regionDir); for (Path familyDir: FSUtils.getFamilyDirs(fs, regionDir)) { - compactStoreFiles(tableDir, htd, hri, familyDir.getName(), compactOnce); + compactStoreFiles(tableDir, htd, hri, familyDir.getName(), compactOnce, major); } } @@ -148,14 +151,17 @@ public class CompactionTool extends Conf * no more compactions are needed. Uses the Configuration settings provided. */ private void compactStoreFiles(final Path tableDir, final HTableDescriptor htd, - final HRegionInfo hri, final String familyName, final boolean compactOnce) - throws IOException { + final HRegionInfo hri, final String familyName, final boolean compactOnce, + final boolean major) throws IOException { HStore store = getStore(conf, fs, tableDir, htd, hri, familyName, tmpDir); LOG.info("Compact table=" + htd.getNameAsString() + " region=" + hri.getRegionNameAsString() + " family=" + familyName); + if (major) { + store.triggerMajorCompaction(); + } do { - CompactionContext compaction = store.requestCompaction(); + CompactionContext compaction = store.requestCompaction(Store.PRIORITY_USER, null); if (compaction == null) break; List storeFiles = store.compact(compaction); if (storeFiles != null && !storeFiles.isEmpty()) { @@ -203,11 +209,13 @@ public class CompactionTool extends Conf extends Mapper { private CompactionWorker compactor = null; private boolean compactOnce = false; + private boolean major = false; @Override public void setup(Context context) { Configuration conf = context.getConfiguration(); compactOnce = conf.getBoolean(CONF_COMPACT_ONCE, false); + major = conf.getBoolean(CONF_COMPACT_MAJOR, false); try { FileSystem fs = FileSystem.get(conf); @@ -221,7 +229,7 @@ public class CompactionTool extends Conf public void map(LongWritable key, Text value, Context context) throws InterruptedException, IOException { Path path = new Path(value.toString()); - this.compactor.compact(path, compactOnce); + this.compactor.compact(path, compactOnce, major); } } @@ -333,9 +341,10 @@ public class CompactionTool extends Conf * Execute compaction, using a Map-Reduce job. */ private int doMapReduce(final FileSystem fs, final Set toCompactDirs, - final boolean compactOnce) throws Exception { + final boolean compactOnce, final boolean major) throws Exception { Configuration conf = getConf(); conf.setBoolean(CONF_COMPACT_ONCE, compactOnce); + conf.setBoolean(CONF_COMPACT_MAJOR, major); Job job = new Job(conf); job.setJobName("CompactionTool"); @@ -367,10 +376,10 @@ public class CompactionTool extends Conf * Execute compaction, from this client, one path at the time. */ private int doClient(final FileSystem fs, final Set toCompactDirs, - final boolean compactOnce) throws IOException { + final boolean compactOnce, final boolean major) throws IOException { CompactionWorker worker = new CompactionWorker(fs, getConf()); for (Path path: toCompactDirs) { - worker.compact(path, compactOnce); + worker.compact(path, compactOnce, major); } return 0; } @@ -379,6 +388,7 @@ public class CompactionTool extends Conf public int run(String[] args) throws Exception { Set toCompactDirs = new HashSet(); boolean compactOnce = false; + boolean major = false; boolean mapred = false; Configuration conf = getConf(); @@ -389,6 +399,8 @@ public class CompactionTool extends Conf String opt = args[i]; if (opt.equals("-compactOnce")) { compactOnce = true; + } else if (opt.equals("-major")) { + major = true; } else if (opt.equals("-mapred")) { mapred = true; } else if (!opt.startsWith("-")) { @@ -415,9 +427,9 @@ public class CompactionTool extends Conf // Execute compaction! if (mapred) { - return doMapReduce(fs, toCompactDirs, compactOnce); + return doMapReduce(fs, toCompactDirs, compactOnce, major); } else { - return doClient(fs, toCompactDirs, compactOnce); + return doClient(fs, toCompactDirs, compactOnce, major); } } @@ -430,11 +442,12 @@ public class CompactionTool extends Conf System.err.println(message); } System.err.println("Usage: java " + this.getClass().getName() + " \\"); - System.err.println(" [-compactOnce] [-mapred] [-D]* files..."); + System.err.println(" [-compactOnce] [-major] [-mapred] [-D]* files..."); System.err.println(); System.err.println("Options:"); System.err.println(" mapred Use MapReduce to run compaction."); System.err.println(" compactOnce Execute just one compaction step. (default: while needed)"); + System.err.println(" major Trigger major compaction."); System.err.println(); System.err.println("Note: -D properties will be applied to the conf used. "); System.err.println("For example: ");