Index: hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java
===================================================================
--- hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java (revision 1503643)
+++ hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java (working copy)
@@ -126,6 +126,16 @@
/**
* 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
* its contents are flushed onto the disk
*
@@ -196,6 +206,11 @@
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 @@
}
/**
+ * 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
Index: hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java
===================================================================
--- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java (revision 1503643)
+++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java (working copy)
@@ -297,7 +297,8 @@
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 @@
@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.
Index: hbase-server/src/main/ruby/hbase/admin.rb
===================================================================
--- hbase-server/src/main/ruby/hbase/admin.rb (revision 1503643)
+++ hbase-server/src/main/ruby/hbase/admin.rb (working copy)
@@ -259,6 +259,7 @@
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 @@
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]