You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by se...@apache.org on 2013/07/20 00:40:44 UTC

svn commit: r1505061 - in /hbase/branches/0.95: hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java hbase-server/src/main/ruby/hbase/admin.rb

Author: sershe
Date: Fri Jul 19 22:40:43 2013
New Revision: 1505061

URL: http://svn.apache.org/r1505061
Log:
HBASE-7875 introduce a compaction switch in HBase Shell (Liang Xie)

Modified:
    hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java
    hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java
    hbase/branches/0.95/hbase-server/src/main/ruby/hbase/admin.rb

Modified: hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java?rev=1505061&r1=1505060&r2=1505061&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java (original)
+++ hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java Fri Jul 19 22:40:43 2013
@@ -126,6 +126,16 @@ public class HTableDescriptor implements
 
   /**
    * <em>INTERNAL</em> 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));
+
+  /**
+   * <em>INTERNAL</em> Used by HBase Shell interface to access this metadata
    * attribute which represents the maximum size of the memstore after which
    * its contents are flushed onto the disk
    *
@@ -196,6 +206,11 @@ public class HTableDescriptor implements
   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
    */
@@ -612,6 +627,25 @@ public class HTableDescriptor implements
   }
 
   /**
+   * 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.
    *
    * @return true if that deferred log flush is enabled on the table

Modified: hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java?rev=1505061&r1=1505060&r2=1505061&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java (original)
+++ hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java Fri Jul 19 22:40:43 2013
@@ -297,7 +297,8 @@ public class CompactSplitThread implemen
   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 implemen
     @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.

Modified: hbase/branches/0.95/hbase-server/src/main/ruby/hbase/admin.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/main/ruby/hbase/admin.rb?rev=1505061&r1=1505060&r2=1505061&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/main/ruby/hbase/admin.rb (original)
+++ hbase/branches/0.95/hbase-server/src/main/ruby/hbase/admin.rb Fri Jul 19 22:40:43 2013
@@ -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]