You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by li...@apache.org on 2014/03/12 21:34:41 UTC
svn commit: r1576886 - in /hbase/branches/0.89-fb/src:
main/java/org/apache/hadoop/hbase/regionserver/Store.java
test/java/org/apache/hadoop/hbase/regionserver/TestStore.java
Author: liyin
Date: Wed Mar 12 20:34:40 2014
New Revision: 1576886
URL: http://svn.apache.org/r1576886
Log:
[HBASE-7099][89-fb] Change compaction hook impl in online config fashion
Author: adela
Test Plan: unit test in TestStore
Reviewers: gauravm
Reviewed By: gauravm
CC: hbase-eng@
Differential Revision: https://phabricator.fb.com/D1204324
Task ID: 3818917
Modified:
hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/Store.java
hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java
Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/Store.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/Store.java?rev=1576886&r1=1576885&r2=1576886&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/Store.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/Store.java Wed Mar 12 20:34:40 2014
@@ -44,9 +44,6 @@ import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.conf.ConfigurationObserver;
-import org.apache.hadoop.io.WriteOptions;
-import org.apache.hadoop.io.nativeio.NativeIO;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
@@ -54,6 +51,7 @@ import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueContext;
import org.apache.hadoop.hbase.RemoteExceptionHandler;
import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.conf.ConfigurationObserver;
import org.apache.hadoop.hbase.io.HeapSize;
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
import org.apache.hadoop.hbase.io.hfile.Compression;
@@ -77,6 +75,8 @@ import org.apache.hadoop.hbase.util.Dyna
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.InjectionEvent;
import org.apache.hadoop.hbase.util.InjectionHandler;
+import org.apache.hadoop.io.WriteOptions;
+import org.apache.hadoop.io.nativeio.NativeIO;
import org.apache.hadoop.util.StringUtils;
import com.google.common.base.Preconditions;
@@ -342,6 +342,7 @@ public class Store extends SchemaConfigu
try {
this.compactHook = (CompactionHook) Class.forName(compactHookString).newInstance();
+ LOG.info("Compaction hook loaded: " + compactHook.getClass().getName());
} catch (InstantiationException e) {
throw new IllegalArgumentException(e);
} catch (IllegalAccessException e) {
@@ -349,6 +350,9 @@ public class Store extends SchemaConfigu
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
+ } else {
+ LOG.info("Compaction hook is null");
+ this.compactHook = null;
}
}
@@ -998,7 +1002,7 @@ public class Store extends SchemaConfigu
return needsCompaction();
}
- /*
+ /**
* Notify all observers that set of Readers has changed.
* @throws IOException
*/
@@ -2220,11 +2224,29 @@ public class Store extends SchemaConfigu
// Re-create the CompoundConfiguration in the manner that it is created in
// the hierarchy. Add the conf first, then add the values from the table
// descriptor, and then the column family descriptor.
- this.conf = new CompoundConfiguration()
- .add(confParam)
- .add(getHRegionInfo().getTableDesc().getValues())
- .add(family.getValues());
-
+ this.conf = new CompoundConfiguration().add(confParam)
+ .add(getHRegionInfo().getTableDesc().getValues())
+ .add(family.getValues());
+
+ String compactionHookNew = confParam.get(HConstants.COMPACTION_HOOK);
+ if ((compactHook != null && !compactHook.getClass().getName().equals(compactionHookNew))
+ || (compactHook == null && compactionHookNew != null)) {
+ if (compactionHookNew != null && !compactionHookNew.isEmpty()) {
+ try {
+ this.compactHook = (CompactionHook) Class.forName(compactionHookNew)
+ .newInstance();
+ } catch (InstantiationException | IllegalAccessException
+ | ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ } else {
+ this.compactHook = null;
+ }
+ }
compactionManager.updateConfiguration(this.conf);
}
+
+ public CompactionHook getCompactHook() {
+ return compactHook;
+ }
}
Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java?rev=1576886&r1=1576885&r2=1576886&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java (original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java Wed Mar 12 20:34:40 2014
@@ -503,7 +503,7 @@ public class TestStore extends TestCase
@Override
public FSDataOutputStream create(Path p,
- FsPermission permission,
+ FsPermission permission,
boolean overwrite,
int bufferSize,
short replication,
@@ -511,8 +511,8 @@ public class TestStore extends TestCase
int bytesPerChecksum,
Progressable progress) throws IOException {
return new FaultyOutputStream(super.create(p,
- permission, overwrite, bufferSize, replication,
- blockSize, bytesPerChecksum, progress), faultPos);
+ permission, overwrite, bufferSize, replication,
+ blockSize, bytesPerChecksum, progress), faultPos);
}
@Override
@@ -659,4 +659,35 @@ public class TestStore extends TestCase
}
}
}
+
+ /**
+ * Checks whether compaction hook is updated in the configuration when we call
+ * {@link Store#notifyOnChange(Configuration)}
+ *
+ * @throws IOException
+ */
+ public void testCompactionHookOnlineConfigurationChange() throws IOException {
+ final String compactionHookExample = "org.apache.hadoop.hbase.regionserver.compactionhook.LowerToUpperCompactionHook";
+ final String compactionHookExample2 = "org.apache.hadoop.hbase.regionserver.compactionhook.SkipCompactionHook";
+ Configuration conf = HBaseConfiguration.create();
+ init(getName());
+ // compaction hook should be null by default
+ assertNull(this.store.getCompactHook());
+ assertNull(conf.get(HConstants.COMPACTION_HOOK));
+ conf.set(HConstants.COMPACTION_HOOK, compactionHookExample);
+ // confirm it is null before we call notifyOnChange
+ assertNull(this.store.getCompactHook());
+ this.store.notifyOnChange(conf);
+ assertTrue(this.store.getCompactHook().getClass().getName()
+ .equals(compactionHookExample));
+ // change it to another implmentation of compaction hook
+ conf.set(HConstants.COMPACTION_HOOK, compactionHookExample2);
+ this.store.notifyOnChange(conf);
+ // confirm that store has picked up the new compaction hook
+ assertTrue(this.store.getCompactHook().getClass().getName().equals(compactionHookExample2));
+ //set it to empty
+ conf.set(HConstants.COMPACTION_HOOK, "");
+ this.store.notifyOnChange(conf);
+ assertNull(this.store.getCompactHook());;
+ }
}