HBASE-14960 Fallback to using default RPCControllerFactory if class cannot be
loaded
Conflicts:
hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRpcControllerFactory.java
Amending-Author: Andrew Purtell <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/ee1e4536
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/ee1e4536
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/ee1e4536
Branch: refs/heads/0.98
Commit: ee1e453609e7838d8e447bea34b07fa27f11b336
Parents: 229c430
Author: Enis Soztutar <[email protected]>
Authored: Thu Dec 10 19:11:57 2015 -0800
Committer: Andrew Purtell <[email protected]>
Committed: Mon Dec 14 13:49:01 2015 -0800
----------------------------------------------------------------------
.../hadoop/hbase/ipc/RpcControllerFactory.java | 34 ++++++++++++++++++--
.../hbase/client/TestRpcControllerFactory.java | 19 +++++++++--
2 files changed, 49 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/ee1e4536/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcControllerFactory.java
----------------------------------------------------------------------
diff --git
a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcControllerFactory.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcControllerFactory.java
index c39c32b..83603b7 100644
---
a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcControllerFactory.java
+++
b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcControllerFactory.java
@@ -19,6 +19,8 @@ package org.apache.hadoop.hbase.ipc;
import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CellScannable;
import org.apache.hadoop.hbase.CellScanner;
@@ -30,7 +32,13 @@ import org.apache.hadoop.hbase.util.ReflectionUtils;
*/
@InterfaceAudience.Private
public class RpcControllerFactory {
+ private static final Log LOG = LogFactory.getLog(RpcControllerFactory.class);
+ /**
+ * Custom RPC Controller factory allows frameworks to change the RPC
controller. If the configured
+ * controller cannot be found in the classpath or loaded, we fall back to
the default RPC
+ * controller factory.
+ */
public static final String CUSTOM_CONTROLLER_CONF_KEY =
"hbase.rpc.controllerfactory.class";
protected final Configuration conf;
@@ -55,7 +63,29 @@ public class RpcControllerFactory {
String rpcControllerFactoryClazz =
configuration.get(CUSTOM_CONTROLLER_CONF_KEY,
RpcControllerFactory.class.getName());
- return ReflectionUtils.instantiateWithCustomCtor(rpcControllerFactoryClazz,
- new Class[] { Configuration.class }, new Object[] { configuration });
+ Throwable err = null;
+ try {
+ return
ReflectionUtils.instantiateWithCustomCtor(rpcControllerFactoryClazz,
+ new Class[] { Configuration.class }, new Object[] { configuration });
+ } catch (UnsupportedOperationException ex) {
+ err = ex;
+ // Fall through to workaround
+ } catch (NoClassDefFoundError ex) {
+ err = ex;
+ // Fall through to workaround
+ }
+ // Other uncaught runtime exceptions will bubble up to the caller from here
+
+ // HBASE-14960: In case the RPCController is in a non-HBase jar (Phoenix),
but the application
+ // is a pure HBase application, we want to fallback to the default one.
+ String msg = "Cannot load configured \"" + CUSTOM_CONTROLLER_CONF_KEY +
"\" ("
+ + rpcControllerFactoryClazz + ") from hbase-site.xml, falling back to
use "
+ + "default RpcControllerFactory";
+ if (LOG.isDebugEnabled()) {
+ LOG.warn(msg, err); // if DEBUG enabled, we want the exception, but
still log in WARN level
+ } else {
+ LOG.warn(msg);
+ }
+ return new RpcControllerFactory(configuration);
}
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/ee1e4536/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRpcControllerFactory.java
----------------------------------------------------------------------
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRpcControllerFactory.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRpcControllerFactory.java
index c5faed3..69fe364 100644
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRpcControllerFactory.java
+++
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRpcControllerFactory.java
@@ -19,6 +19,7 @@ package org.apache.hadoop.hbase.client;
import static org.apache.hadoop.hbase.HBaseTestingUtility.fam1;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.util.List;
@@ -53,14 +54,17 @@ public class TestRpcControllerFactory {
super(conf);
}
+ @Override
public PayloadCarryingRpcController newController() {
return new CountingRpcController(super.newController());
}
+ @Override
public PayloadCarryingRpcController newController(final CellScanner
cellScanner) {
return new CountingRpcController(super.newController(cellScanner));
}
+ @Override
public PayloadCarryingRpcController newController(final
List<CellScannable> cellIterables) {
return new CountingRpcController(super.newController(cellIterables));
}
@@ -102,7 +106,7 @@ public class TestRpcControllerFactory {
Configuration conf = UTIL.getConfiguration();
conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
ProtobufCoprocessorService.class.getName());
-
+
UTIL.startMiniCluster();
}
@@ -200,4 +204,15 @@ public class TestRpcControllerFactory {
assertEquals(0, CountingRpcController.INT_PRIORITY.get());
return counter + 1;
}
-}
\ No newline at end of file
+
+ @Test
+ public void testFallbackToDefaultRpcControllerFactory() {
+ Configuration conf = new Configuration(UTIL.getConfiguration());
+ conf.set(RpcControllerFactory.CUSTOM_CONTROLLER_CONF_KEY, "foo.bar.Baz");
+
+ // Should not fail
+ RpcControllerFactory factory = RpcControllerFactory.instantiate(conf);
+ assertNotNull(factory);
+ assertEquals(factory.getClass(), RpcControllerFactory.class);
+ }
+}