From 51fcf97601bf242e0417fd936defcb57826a202d Mon Sep 17 00:00:00 2001 From: vmeka2020 Date: Mon, 22 Feb 2021 14:21:54 -0800 Subject: [PATCH] PHOENIX-6395 Reusing Connection instance object instead of creating everytime in PhoenixAccessController class. --- .../coprocessor/PhoenixAccessController.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/PhoenixAccessController.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/PhoenixAccessController.java index 4ca9ff25851..a2717ce8306 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/PhoenixAccessController.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/PhoenixAccessController.java @@ -30,7 +30,6 @@ import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Connection; -import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.coprocessor.BaseMasterAndRegionObserver; import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment; import org.apache.hadoop.hbase.coprocessor.ObserverContext; @@ -56,6 +55,7 @@ import org.apache.hadoop.hbase.security.access.UserPermission; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; +import org.apache.hadoop.hbase.regionserver.HRegionServer; import org.apache.phoenix.compat.hbase.CompatObserverContext; import org.apache.phoenix.coprocessor.PhoenixMetaDataCoprocessorHost.PhoenixMetaDataControllerEnvironment; import org.apache.phoenix.query.QueryServices; @@ -64,6 +64,7 @@ import org.apache.phoenix.schema.PTable; import org.apache.phoenix.schema.PTableType; import org.apache.phoenix.util.MetaDataUtil; +import org.apache.phoenix.util.ServerUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -277,7 +278,8 @@ private void grantPermissions(final String toUser, final byte[] table, final Act User.runAsLoginUser(new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Connection conn = ConnectionFactory.createConnection(env.getConfiguration())) { + try (Connection conn = ServerUtil.ConnectionFactory.getConnection(ServerUtil.ConnectionType.DEFAULT_SERVER_CONNECTION, + env.getConfiguration(), (HRegionServer)env.getRegionServerServices())) { AccessControlClient.grant(conn, TableName.valueOf(table), toUser , null, null, actions); } catch (Throwable e) { @@ -294,7 +296,7 @@ private void authorizeOrGrantAccessToUsers(final String request, final TableName User.runAsLoginUser(new PrivilegedExceptionAction() { @Override public Void run() throws IOException { - try (Connection conn = ConnectionFactory.createConnection(env.getConfiguration())) { + try { List userPermissions = getUserPermissions(fromTable); List permissionsOnTheTable = getUserPermissions(toTable); if (userPermissions != null) { @@ -339,6 +341,8 @@ public Void run() throws IOException { } } } + } catch (Throwable e) { + throw e; } return null; } @@ -478,7 +482,8 @@ private List getUserPermissions(final TableName tableName) throw public List run() throws Exception { final List userPermissions = new ArrayList(); final RpcServer.Call rpcContext = RpcUtil.getRpcContext(); - try (Connection connection = ConnectionFactory.createConnection(env.getConfiguration())) { + try (Connection connection = ServerUtil.ConnectionFactory.getConnection(ServerUtil.ConnectionType.DEFAULT_SERVER_CONNECTION, + env.getConfiguration(), (HRegionServer)env.getRegionServerServices())) { // Setting RPC context as null so that user can be resetted RpcUtil.setRpcContext(null); // Merge permissions from all accessController coprocessors loaded in memory @@ -512,8 +517,8 @@ private void getUserDefinedPermissions(final TableName tableName, final List run() throws Exception { final RpcServer.Call rpcContext = RpcUtil.getRpcContext(); - try (Connection connection = - ConnectionFactory.createConnection(env.getConfiguration())) { + try (Connection connection = ServerUtil.ConnectionFactory.getConnection(ServerUtil.ConnectionType.DEFAULT_SERVER_CONNECTION, + env.getConfiguration(), (HRegionServer)env.getRegionServerServices())) { // Setting RPC context as null so that user can be resetted RpcUtil.setRpcContext(null); for (BaseMasterAndRegionObserver service : getAccessControllers()) {