From 245cd389835d14d817104aab9e1251a5799643d8 Mon Sep 17 00:00:00 2001 From: sershe Date: Fri, 19 Jul 2013 22:40:31 +0000 Subject: [PATCH] HBASE-7875 introduce a compaction switch in HBase Shell (Liang Xie) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1505060 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/hadoop/hbase/HTableDescriptor.java | 34 +++++++++++++++++++ .../regionserver/CompactSplitThread.java | 6 ++-- hbase-server/src/main/ruby/hbase/admin.rb | 2 ++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java index 4669c284398..43f87329584 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java @@ -124,6 +124,16 @@ public class HTableDescriptor implements WritableComparable { private static final ImmutableBytesWritable READONLY_KEY = new ImmutableBytesWritable(Bytes.toBytes(READONLY)); + /** + * INTERNAL Used by HBase Shell interface to access this metadata + * attribute which denotes if the table is compaction enabled + * + * @see #isCompactionEnabled() + */ + public static final String COMPACTION_ENABLED = "COMPACTION_ENABLED"; + private static final ImmutableBytesWritable COMPACTION_ENABLED_KEY = + new ImmutableBytesWritable(Bytes.toBytes(COMPACTION_ENABLED)); + /** * INTERNAL Used by HBase Shell interface to access this metadata * attribute which represents the maximum size of the memstore after which @@ -195,6 +205,11 @@ public class HTableDescriptor implements WritableComparable { */ public static final boolean DEFAULT_READONLY = false; + /** + * Constant that denotes whether the table is compaction enabled by default + */ + public static final boolean DEFAULT_COMPACTION_ENABLED = true; + /** * Constant that denotes the maximum default size of the memstore after which * the contents are flushed to the store files @@ -611,6 +626,25 @@ public class HTableDescriptor implements WritableComparable { setValue(READONLY_KEY, readOnly? TRUE: FALSE); } + /** + * Check if the compaction enable flag of the table is true. If flag is + * false then no minor/major compactions will be done in real. + * + * @return true if table compaction enabled + */ + public boolean isCompactionEnabled() { + return isSomething(COMPACTION_ENABLED_KEY, DEFAULT_COMPACTION_ENABLED); + } + + /** + * Setting the table compaction enable flag. + * + * @param isEnable True if enable compaction. + */ + public void setCompactionEnabled(final boolean isEnable) { + setValue(COMPACTION_ENABLED_KEY, isEnable ? TRUE : FALSE); + } + /** * Check if deferred log edits are enabled on the table. * diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java index a2a346f3269..1f3bf4897d3 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java @@ -297,7 +297,8 @@ public class CompactSplitThread implements CompactionRequestor { private synchronized CompactionRequest requestCompactionInternal(final HRegion r, final Store s, final String why, int priority, CompactionRequest request, boolean selectNow) throws IOException { - if (this.server.isStopped()) { + if (this.server.isStopped() + || (r.getTableDesc() != null && !r.getTableDesc().isCompactionEnabled())) { return null; } @@ -418,7 +419,8 @@ public class CompactSplitThread implements CompactionRequestor { @Override public void run() { Preconditions.checkNotNull(server); - if (server.isStopped()) { + if (server.isStopped() + || (region.getTableDesc() != null && !region.getTableDesc().isCompactionEnabled())) { return; } // Common case - system compaction without a file selection. Select now. diff --git a/hbase-server/src/main/ruby/hbase/admin.rb b/hbase-server/src/main/ruby/hbase/admin.rb index 213f7a8f021..30ae110145a 100644 --- a/hbase-server/src/main/ruby/hbase/admin.rb +++ b/hbase-server/src/main/ruby/hbase/admin.rb @@ -259,6 +259,7 @@ module Hbase htd.setOwnerString(arg.delete(OWNER)) if arg[OWNER] htd.setMaxFileSize(JLong.valueOf(arg.delete(MAX_FILESIZE))) if arg[MAX_FILESIZE] htd.setReadOnly(JBoolean.valueOf(arg.delete(READONLY))) if arg[READONLY] + htd.setCompactionEnabled(JBoolean.valueOf(arg[COMPACTION_ENABLED])) if arg[COMPACTION_ENABLED] htd.setMemStoreFlushSize(JLong.valueOf(arg.delete(MEMSTORE_FLUSHSIZE))) if arg[MEMSTORE_FLUSHSIZE] htd.setDeferredLogFlush(JBoolean.valueOf(arg.delete(DEFERRED_LOG_FLUSH))) if arg[DEFERRED_LOG_FLUSH] htd.setDurability(org.apache.hadoop.hbase.client.Durability.valueOf(arg.delete(DURABILITY))) if arg[DURABILITY] @@ -468,6 +469,7 @@ module Hbase htd.setOwnerString(arg.delete(OWNER)) if arg[OWNER] htd.setMaxFileSize(JLong.valueOf(arg.delete(MAX_FILESIZE))) if arg[MAX_FILESIZE] htd.setReadOnly(JBoolean.valueOf(arg.delete(READONLY))) if arg[READONLY] + htd.setCompactionEnabled(JBoolean.valueOf(arg[COMPACTION_ENABLED])) if arg[COMPACTION_ENABLED] htd.setMemStoreFlushSize(JLong.valueOf(arg.delete(MEMSTORE_FLUSHSIZE))) if arg[MEMSTORE_FLUSHSIZE] htd.setDeferredLogFlush(JBoolean.valueOf(arg.delete(DEFERRED_LOG_FLUSH))) if arg[DEFERRED_LOG_FLUSH] htd.setDurability(org.apache.hadoop.hbase.client.Durability.valueOf(arg.delete(DURABILITY))) if arg[DURABILITY]