You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2014/02/27 03:52:31 UTC

git commit: PHOENIX-79 Change the way QueryServices is initialized to make initialization more performant (SamarthJain)

Repository: incubator-phoenix
Updated Branches:
  refs/heads/master 8cf7eab7c -> 31c322c60


PHOENIX-79 Change the way QueryServices is initialized to make initialization more performant (SamarthJain)


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

Branch: refs/heads/master
Commit: 31c322c606aa1b80a50f4cd654f5f069b02428f1
Parents: 8cf7eab
Author: jamestaylor <ja...@apache.org>
Authored: Wed Feb 26 18:52:16 2014 -0800
Committer: jamestaylor <ja...@apache.org>
Committed: Wed Feb 26 18:52:16 2014 -0800

----------------------------------------------------------------------
 .../phoenix/jdbc/PhoenixDatabaseMetaData.java   |  8 +++++--
 .../org/apache/phoenix/jdbc/PhoenixDriver.java  | 24 ++++++++++++--------
 .../query/ConnectionQueryServicesImpl.java      | 13 ++++++-----
 .../end2end/QueryDatabaseMetaDataTest.java      |  2 ++
 4 files changed, 30 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/31c322c6/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
index 6746080..7fd487f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
@@ -204,6 +204,9 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData, org.apache.pho
     public static final byte[] INCREMENT_BY_BYTES = Bytes.toBytes(INCREMENT_BY);
     public static final String CACHE_SIZE = "CACHE_SIZE";
     public static final byte[] CACHE_SIZE_BYTES = Bytes.toBytes(CACHE_SIZE);
+    public static final String KEY_SEQ = "KEY_SEQ";
+    public static final byte[] KEY_SEQ_BYTES = Bytes.toBytes(KEY_SEQ);
+    		
     
     private final PhoenixConnection connection;
     private final ResultSet emptyResultSet;
@@ -610,11 +613,12 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData, org.apache.pho
                 TABLE_SCHEM_NAME + "," +
                 TABLE_NAME_NAME + " ," +
                 COLUMN_NAME + "," +
-                "null as KEY_SEQ," +
+                "null as " + KEY_SEQ + "," +
                 "PK_NAME" + "," +
                 "CASE WHEN " + SORT_ORDER + " = " + (SortOrder.DESC.getSystemValue()) + " THEN 'D' ELSE 'A' END ASC_OR_DESC," +
                 DATA_TYPE + "," + // include type info, though not in spec
-                SqlTypeNameFunction.NAME + "(" + DATA_TYPE + ") AS " + TYPE_NAME +
+                SqlTypeNameFunction.NAME + "(" + DATA_TYPE + ") AS " + TYPE_NAME + "," +
+                COLUMN_SIZE + 
                 " from " + TYPE_SCHEMA_AND_TABLE + " " + TYPE_SCHEMA_AND_TABLE_ALIAS +
                 " where ");
         buf.append(getTenantIdWhereClause());

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/31c322c6/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
index 836590b..8b75979 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
@@ -61,17 +61,23 @@ public final class PhoenixDriver extends PhoenixEmbeddedDriver {
         super();
     }
 
-    private QueryServices services;
+    private volatile QueryServices services;
 
     @Override
-    public synchronized QueryServices getQueryServices() {
-        // Lazy initialize QueryServices so that we only attempt to create an HBase Configuration
-        // object upon the first attempt to connect to any cluster. Otherwise, an attempt will be
-        // made at driver initialization time which is too early for some systems.
-        if (services == null) {
-            services = new QueryServicesImpl();
-        }
-        return services;
+    public QueryServices getQueryServices() {
+    	// Lazy initialize QueryServices so that we only attempt to create an HBase Configuration
+    	// object upon the first attempt to connect to any cluster. Otherwise, an attempt will be
+    	// made at driver initialization time which is too early for some systems.
+    	QueryServices result = services;
+    	if (result == null) {
+    		synchronized(this) {
+    			result = services;
+    			if(result == null) {
+    				services = result = new QueryServicesImpl();
+    			}
+    		}
+    	}
+    	return result;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/31c322c6/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 d0c9a35..f0c7491 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
@@ -180,13 +180,14 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
     public HTableInterface getTable(byte[] tableName) throws SQLException {
         try {
             return HBaseFactoryProvider.getHTableFactory().getTable(tableName, connection, getExecutor());
-        } catch (org.apache.hadoop.hbase.TableNotFoundException e) {
-            byte[][] schemaAndTableName = new byte[2][];
-            SchemaUtil.getVarChars(tableName, schemaAndTableName);
-            throw new TableNotFoundException(Bytes.toString(schemaAndTableName[0]), Bytes.toString(schemaAndTableName[1]));
         } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
+        	if(e instanceof org.apache.hadoop.hbase.TableNotFoundException || e.getCause() instanceof org.apache.hadoop.hbase.TableNotFoundException) {
+        		byte[][] schemaAndTableName = new byte[2][];
+        		SchemaUtil.getVarChars(tableName, schemaAndTableName);
+        		throw new TableNotFoundException(Bytes.toString(schemaAndTableName[0]), Bytes.toString(schemaAndTableName[1]));
+        	} 
+        	throw new SQLException(e);
+        } 
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/31c322c6/phoenix-core/src/test/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataTest.java
index b4daa19..e5af54d 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataTest.java
@@ -386,12 +386,14 @@ public class QueryDatabaseMetaDataTest extends BaseClientManagedTimeTest {
         assertEquals(CUSTOM_ENTITY_DATA_NAME, rs.getString("TABLE_NAME"));
         assertEquals(null, rs.getString("TABLE_CAT"));
         assertEquals(SchemaUtil.normalizeIdentifier("organization_id"), rs.getString("COLUMN_NAME"));
+        assertEquals(rs.getInt("COLUMN_SIZE"), 15);
         
         assertTrue(rs.next());
         assertEquals(CUSTOM_ENTITY_DATA_SCHEMA_NAME, rs.getString("TABLE_SCHEM"));
         assertEquals(CUSTOM_ENTITY_DATA_NAME, rs.getString("TABLE_NAME"));
         assertEquals(null, rs.getString("TABLE_CAT"));
         assertEquals(SchemaUtil.normalizeIdentifier("key_prefix"), rs.getString("COLUMN_NAME"));
+        assertEquals(rs.getInt("COLUMN_SIZE"), 3);
         
         assertTrue(rs.next());
         assertEquals(CUSTOM_ENTITY_DATA_SCHEMA_NAME, rs.getString("TABLE_SCHEM"));