diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcControllerFactory.java hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcControllerFactory.java index f8ab23f..6ecaebb 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcControllerFactory.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcControllerFactory.java @@ -24,6 +24,7 @@ import org.apache.hadoop.hbase.CellScannable; import org.apache.hadoop.hbase.CellScanner; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.util.ReflectionUtils; +import org.mortbay.log.Log; /** * Factory to create a {@link PayloadCarryingRpcController} @@ -55,7 +56,16 @@ 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 }); + try { + return ReflectionUtils.instantiateWithCustomCtor(rpcControllerFactoryClazz, + new Class[] { Configuration.class }, new Object[] { configuration }); + } catch (UnsupportedOperationException | NoClassDefFoundError ex) { + // 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. + Log.warn("Cannot load configured \"" + CUSTOM_CONTROLLER_CONF_KEY + "\" (" + + rpcControllerFactoryClazz + ") from hbase-site.xml, falling back to use " + + "default RpcControllerFactory"); + return new RpcControllerFactory(configuration); + } } } diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRpcControllerFactory.java hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRpcControllerFactory.java index c087135..656dedc 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRpcControllerFactory.java +++ 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; @@ -54,14 +55,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 cellIterables) { return new CountingRpcController(super.newController(cellIterables)); } @@ -103,7 +107,7 @@ public class TestRpcControllerFactory { Configuration conf = UTIL.getConfiguration(); conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, ProtobufCoprocessorService.class.getName()); - + UTIL.startMiniCluster(); } @@ -202,4 +206,15 @@ public class TestRpcControllerFactory { assertEquals(0, CountingRpcController.INT_PRIORITY.get()); return counter + 1; } + + @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); + } } \ No newline at end of file