phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sama...@apache.org
Subject phoenix git commit: PHOENIX-1726 Phoenix connection initialization makes multiple hbase connections
Date Tue, 26 Jan 2016 05:58:08 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 d1ee4ce9c -> c54b7c031


PHOENIX-1726 Phoenix connection initialization makes multiple hbase connections


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/c54b7c03
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/c54b7c03
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/c54b7c03

Branch: refs/heads/4.x-HBase-0.98
Commit: c54b7c0315b8c82aef4f602cfa5128455dcedc72
Parents: d1ee4ce
Author: Samarth <samarth.jain@salesforce.com>
Authored: Mon Jan 25 21:57:54 2016 -0800
Committer: Samarth <samarth.jain@salesforce.com>
Committed: Mon Jan 25 21:57:54 2016 -0800

----------------------------------------------------------------------
 .../query/ConnectionQueryServicesImpl.java      | 101 ++++---------------
 1 file changed, 21 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/c54b7c03/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index afcd7cd..f686975 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -59,6 +59,12 @@ import java.util.concurrent.TimeoutException;
 
 import javax.annotation.concurrent.GuardedBy;
 
+import co.cask.tephra.TransactionSystemClient;
+import co.cask.tephra.TxConstants;
+import co.cask.tephra.distributed.PooledClientProvider;
+import co.cask.tephra.distributed.TransactionServiceClient;
+import co.cask.tephra.hbase98.coprocessor.TransactionProcessor;
+
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.HConstants;
@@ -200,12 +206,6 @@ import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 
-import co.cask.tephra.TransactionSystemClient;
-import co.cask.tephra.TxConstants;
-import co.cask.tephra.distributed.PooledClientProvider;
-import co.cask.tephra.distributed.TransactionServiceClient;
-import co.cask.tephra.hbase98.coprocessor.TransactionProcessor;
-
 public class ConnectionQueryServicesImpl extends DelegateQueryServices implements ConnectionQueryServices
{
     private static final Logger logger = LoggerFactory.getLogger(ConnectionQueryServicesImpl.class);
     private static final int INITIAL_CHILD_SERVICES_CAPACITY = 100;
@@ -961,16 +961,14 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
      * @throws SQLException
      */
     private HTableDescriptor ensureTableCreated(byte[] tableName, PTableType tableType ,
Map<String,Object> props, List<Pair<byte[],Map<String,Object>>> families,
byte[][] splits, boolean modifyExistingMetaData) throws SQLException {
-        HBaseAdmin admin = null;
         SQLException sqlE = null;
         HTableDescriptor existingDesc = null;
         boolean isMetaTable = SchemaUtil.isMetaTable(tableName);
         boolean tableExist = true;
-        try {
+        try (HBaseAdmin admin = getAdmin()) {
             final String quorum = ZKConfig.getZKQuorumServersString(config);
             final String znode = this.props.get(HConstants.ZOOKEEPER_ZNODE_PARENT);
             logger.debug("Found quorum: " + quorum + ":" + znode);
-            admin = new HBaseAdmin(config);
             try {
                 existingDesc = admin.getTableDescriptor(tableName);
             } catch (org.apache.hadoop.hbase.TableNotFoundException e) {
@@ -1064,28 +1062,16 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
         } catch (TimeoutException e) {
             sqlE = new SQLExceptionInfo.Builder(SQLExceptionCode.OPERATION_TIMED_OUT).setRootCause(e.getCause()
!= null ? e.getCause() : e).build().buildException();
         } finally {
-            try {
-                if (admin != null) {
-                    admin.close();
-                }
-            } catch (IOException e) {
-                if (sqlE == null) {
-                    sqlE = ServerUtil.parseServerException(e);
-                } else {
-                    sqlE.setNextException(ServerUtil.parseServerException(e));
-                }
-            } finally {
-                if (sqlE != null) {
-                    throw sqlE;
-                }
+            if (sqlE != null) {
+                throw sqlE;
             }
         }
         return null; // will never make it here
     }
 
     private void modifyTable(byte[] tableName, HTableDescriptor newDesc, boolean shouldPoll)
throws IOException,
-    InterruptedException, TimeoutException {
-    	try (HBaseAdmin admin = new HBaseAdmin(config)) {
+    InterruptedException, TimeoutException, SQLException {
+    	try (HBaseAdmin admin = getAdmin()) {
     		if (!allowOnlineTableSchemaUpdate()) {
     			admin.disableTable(tableName);
     			admin.modifyTable(tableName, newDesc);
@@ -1307,10 +1293,8 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
     private boolean ensureViewIndexTableDropped(byte[] physicalTableName, long timestamp)
throws SQLException {
         byte[] physicalIndexName = MetaDataUtil.getViewIndexPhysicalName(physicalTableName);
         HTableDescriptor desc = null;
-        HBaseAdmin admin = null;
         boolean wasDeleted = false;
-        try {
-            admin = new HBaseAdmin(config);
+        try (HBaseAdmin admin= getAdmin()) {
             try {
                 desc = admin.getTableDescriptor(physicalIndexName);
                 if (Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(desc.getValue(MetaDataUtil.IS_VIEW_INDEX_TABLE_PROP_BYTES))))
{
@@ -1329,12 +1313,6 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
             }
         } catch (IOException e) {
             throw ServerUtil.parseServerException(e);
-        } finally {
-            try {
-                if (admin != null) admin.close();
-            } catch (IOException e) {
-                logger.warn("",e);
-            }
         }
         return wasDeleted;
     }
@@ -1342,10 +1320,8 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
     private boolean ensureLocalIndexTableDropped(byte[] physicalTableName, long timestamp)
throws SQLException {
         byte[] physicalIndexName = MetaDataUtil.getLocalIndexPhysicalName(physicalTableName);
         HTableDescriptor desc = null;
-        HBaseAdmin admin = null;
         boolean wasDeleted = false;
-        try {
-            admin = new HBaseAdmin(config);
+        try (HBaseAdmin admin = getAdmin()) {
             try {
                 desc = admin.getTableDescriptor(physicalIndexName);
                 if (Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(desc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES))))
{
@@ -1364,12 +1340,6 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
             }
         } catch (IOException e) {
             throw ServerUtil.parseServerException(e);
-        } finally {
-            try {
-                if (admin != null) admin.close();
-            } catch (IOException e) {
-                logger.warn("",e);
-            }
         }
         return wasDeleted;
     }
@@ -1573,10 +1543,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
     }
 
     private void dropTables(final List<byte[]> tableNamesToDelete) throws SQLException
{
-        HBaseAdmin admin = null;
-        SQLException sqlE = null;
-        try{
-            admin = new HBaseAdmin(config);
+        try (HBaseAdmin admin = getAdmin()){
             if (tableNamesToDelete != null){
                 for ( byte[] tableName : tableNamesToDelete ) {
                     if ( admin.tableExists(tableName) ) {
@@ -1588,24 +1555,8 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
             }
 
         } catch (IOException e) {
-            sqlE = ServerUtil.parseServerException(e);
-        } finally {
-            try {
-                if (admin != null) {
-                    admin.close();
-                }
-            } catch (IOException e) {
-                if (sqlE == null) {
-                    sqlE = ServerUtil.parseServerException(e);
-                } else {
-                    sqlE.setNextException(ServerUtil.parseServerException(e));
-                }
-            } finally {
-                if (sqlE != null) {
-                    throw sqlE;
-                }
-            }
-        }
+            throw ServerUtil.parseServerException(e);
+        } 
     }
 
     private static Map<String,Object> createPropertiesMap(Map<ImmutableBytesWritable,ImmutableBytesWritable>
htableProps) {
@@ -1789,10 +1740,8 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
     }
     private void updateDescriptorForTx(PTable table, Map<String, Object> tableProps,
HTableDescriptor tableDescriptor,
             String txValue, Set<HTableDescriptor> descriptorsToUpdate, Set<HTableDescriptor>
origDescriptors) throws SQLException {
-        HBaseAdmin admin = null;
         byte[] physicalTableName = table.getPhysicalName().getBytes();
-        try {
-            admin = new HBaseAdmin(config);
+        try (HBaseAdmin admin = getAdmin()) {
             setTransactional(tableDescriptor, table.getType(), txValue, tableProps);
             Map<String, Object> indexTableProps;
             if (txValue == null) {
@@ -1847,12 +1796,6 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
             }
         } catch (IOException e) {
             throw ServerUtil.parseServerException(e);
-        } finally {
-            try {
-                if (admin != null) admin.close();
-            } catch (IOException e) {
-                logger.warn("Could not close admin",e);
-            }
         }
     }
     private void setSharedIndexMaxVersion(PTable table, HTableDescriptor tableDescriptor,
@@ -2335,9 +2278,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
                                 if(currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_3_0)
{
                                     // We know that we always need to add the STORE_NULLS
column for 4.3 release
                                     columnsToAdd += "," + PhoenixDatabaseMetaData.STORE_NULLS
+ " " + PBoolean.INSTANCE.getSqlTypeName();
-                                    HBaseAdmin admin = null;
-                                    try {
-                                        admin = getAdmin();
+                                    try (HBaseAdmin admin = getAdmin()) {
                                         HTableDescriptor[] localIndexTables = admin.listTables(MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX+".*");
                                         for (HTableDescriptor table : localIndexTables) {
                                             if (table.getValue(MetaDataUtil.PARENT_TABLE_KEY)
== null
@@ -2353,8 +2294,6 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
                                                 admin.enableTable(table.getTableName());
                                             }
                                         }
-                                    } finally {
-                                        if (admin != null) admin.close();
                                     }
                                 }
                                 
@@ -2730,7 +2669,9 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
     @Override
     public HBaseAdmin getAdmin() throws SQLException {
         try {
-            return new HBaseAdmin(config);
+            // do not use the HBaseAdmin(this.config) constructor
+            // since it always establishes a new HConnection which is expensive.
+            return new HBaseAdmin(connection);
         } catch (IOException e) {
             throw new PhoenixIOException(e);
         }


Mime
View raw message