You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by je...@apache.org on 2014/03/05 23:54:53 UTC

[07/50] [abbrv] git commit: PHOENIX-93 Add shutdown hook to free any straggling resources (JamesTaylor)

PHOENIX-93 Add shutdown hook to free any straggling resources (JamesTaylor)


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

Branch: refs/heads/4.0
Commit: 8a21896f18750590e6d760ae11c70556aa05d283
Parents: 1511773
Author: James Taylor <ja...@apache.org>
Authored: Sat Mar 1 17:06:30 2014 -0800
Committer: James Taylor <ja...@apache.org>
Committed: Sat Mar 1 17:06:30 2014 -0800

----------------------------------------------------------------------
 .../org/apache/phoenix/cache/GlobalCache.java   |  4 ++
 .../apache/phoenix/compile/FromCompiler.java    | 70 +++++++++-----------
 .../coprocessor/MetaDataEndpointImpl.java       |  4 +-
 .../org/apache/phoenix/jdbc/PhoenixDriver.java  | 34 ++++++++--
 .../phoenix/jdbc/PhoenixEmbeddedDriver.java     |  6 +-
 .../query/ConnectionQueryServicesImpl.java      | 11 ++-
 .../apache/phoenix/schema/MetaDataClient.java   | 11 ++-
 .../org/apache/phoenix/util/PhoenixRuntime.java |  2 +
 .../phoenix/end2end/BaseConnectedQueryTest.java | 24 ++++---
 .../ConnectionQueryServicesTestImpl.java        |  7 +-
 .../phoenix/query/QueryServicesTestImpl.java    |  2 +-
 .../java/org/apache/phoenix/util/TestUtil.java  | 10 ++-
 12 files changed, 117 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8a21896f/phoenix-core/src/main/java/org/apache/phoenix/cache/GlobalCache.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/cache/GlobalCache.java b/phoenix-core/src/main/java/org/apache/phoenix/cache/GlobalCache.java
index dd9c275..e98ff69 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/cache/GlobalCache.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/cache/GlobalCache.java
@@ -58,6 +58,10 @@ public class GlobalCache extends TenantCacheImpl {
     // Cache for lastest PTable for a given Phoenix table
     private Cache<ImmutableBytesPtr,PTable> metaDataCache;
     
+    public void clearTenantCache() {
+        perTenantCacheMap.clear();
+    }
+    
     public Cache<ImmutableBytesPtr,PTable> getMetaDataCache() {
         // 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

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8a21896f/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
index cfac375..2ca61e2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
@@ -262,56 +262,48 @@ public class FromCompiler {
         }
 
         protected TableRef createTableRef(NamedTableNode tableNode, boolean updateCacheImmediately) throws SQLException {
-            String alias = tableNode.getAlias();
             String tableName = tableNode.getName().getTableName();
             String schemaName = tableNode.getName().getSchemaName();
-            List<ColumnDef> dynamicColumns = tableNode.getDynamicColumns();
-            SQLException sqlE = null;
             long timeStamp = QueryConstants.UNSET_TIMESTAMP;
-            TableRef tableRef = null;
-            boolean retry = true;
-            boolean didRetry = false;
-            MetaDataMutationResult result = null;
             String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
             PName tenantId = connection.getTenantId();
-            while (true) {
+            PTable theTable = null;
+            if (updateCacheImmediately || connection.getAutoCommit()) {
+                MetaDataMutationResult result = client.updateCache(schemaName, tableName);
+                timeStamp = result.getMutationTime();
+                theTable = result.getTable();
+                if (theTable == null) {
+                    throw new TableNotFoundException(schemaName, tableName, timeStamp);
+                }
+            } else {
                 try {
-                    PTable theTable = null;
-                    if (updateCacheImmediately || connection.getAutoCommit()) {
-                        retry = false; // No reason to retry after this
-                        result = client.updateCache(schemaName, tableName);
+                    theTable = connection.getMetaDataCache().getTable(new PTableKey(tenantId, fullTableName));
+                } catch (TableNotFoundException e1) {
+                    if (tenantId != null) { // Check with null tenantId next
+                        try {
+                            theTable = connection.getMetaDataCache().getTable(new PTableKey(null, fullTableName));
+                        } catch (TableNotFoundException e2) {
+                        }
+                    }
+                }
+                // We always attempt to update the cache in the event of a TableNotFoundException
+                if (theTable == null) {
+                    MetaDataMutationResult result = client.updateCache(schemaName, tableName);
+                    if (result.wasUpdated()) {
                         timeStamp = result.getMutationTime();
                         theTable = result.getTable();
-                    } 
-                    if (theTable == null) {
-                        theTable = connection.getMetaDataCache().getTable(new PTableKey(tenantId, fullTableName));
                     }
-                    // If dynamic columns have been specified add them to the table declaration
-                    if (!dynamicColumns.isEmpty()) {
-                        theTable = this.addDynamicColumns(dynamicColumns, theTable);
-                    }
-                    tableRef = new TableRef(alias, theTable, timeStamp, !dynamicColumns.isEmpty());
-                    if (didRetry && logger.isDebugEnabled()) {
-                        logger.debug("Re-resolved stale table " + fullTableName + " with seqNum " + tableRef.getTable().getSequenceNumber() + " at timestamp " + tableRef.getTable().getTimeStamp() + " with " + tableRef.getTable().getColumns().size() + " columns: " + tableRef.getTable().getColumns());
-                    }
-                    break;
-                } catch (TableNotFoundException e) {
-                    if (tenantId != null) { // Check with null tenantId next
-                        tenantId = null;
-                        continue;
-                    }
-                    sqlE = new TableNotFoundException(e,timeStamp);
                 }
-                // If we haven't already tried, update our cache and retry.
-                // We always attempt to update the cache in the event of a retry (i.e. TableNotFoundException)
-                // Only loop back if the cache was updated
-                if (retry && (result = client.updateCache(schemaName, tableName)).wasUpdated()) {
-                    timeStamp = result.getMutationTime();
-                    retry = false;
-                    didRetry = true;
-                    continue;
+                if (theTable == null) {
+                    throw new TableNotFoundException(schemaName, tableName, timeStamp);
                 }
-                throw sqlE;
+            }
+            // Add any dynamic columns to the table declaration
+            List<ColumnDef> dynamicColumns = tableNode.getDynamicColumns();
+            theTable = addDynamicColumns(dynamicColumns, theTable);
+            TableRef tableRef = new TableRef(tableNode.getAlias(), theTable, timeStamp, !dynamicColumns.isEmpty());
+            if (logger.isDebugEnabled() && timeStamp != QueryConstants.UNSET_TIMESTAMP) {
+                logger.debug("Re-resolved stale table " + fullTableName + " with seqNum " + tableRef.getTable().getSequenceNumber() + " at timestamp " + tableRef.getTable().getTimeStamp() + " with " + tableRef.getTable().getColumns().size() + " columns: " + tableRef.getTable().getColumns());
             }
             return tableRef;
         }

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8a21896f/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index 9ba9dac..0f22f27 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -1087,8 +1087,10 @@ public class MetaDataEndpointImpl extends BaseEndpointCoprocessor implements Met
 
     @Override
     public void clearCache() {
-        Cache<ImmutableBytesPtr,PTable> metaDataCache = GlobalCache.getInstance(this.getEnvironment()).getMetaDataCache();
+        GlobalCache cache = GlobalCache.getInstance(this.getEnvironment());
+        Cache<ImmutableBytesPtr,PTable> metaDataCache = cache.getMetaDataCache();
         metaDataCache.invalidateAll();
+        cache.clearTenantCache();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8a21896f/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 b952ab5..6660124 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
@@ -19,6 +19,7 @@ package org.apache.phoenix.jdbc;
 
 import java.sql.DriverManager;
 import java.sql.SQLException;
+import java.util.Collection;
 import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -29,6 +30,8 @@ import org.apache.phoenix.query.ConnectionlessQueryServicesImpl;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesImpl;
 import org.apache.phoenix.util.SQLCloseables;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -46,10 +49,23 @@ import org.apache.phoenix.util.SQLCloseables;
  * @since 0.1
  */
 public final class PhoenixDriver extends PhoenixEmbeddedDriver {
+    private static final Logger logger = LoggerFactory.getLogger(PhoenixDriver.class);
     public static final PhoenixDriver INSTANCE;
     static {
         try {
             DriverManager.registerDriver( INSTANCE = new PhoenixDriver() );
+            // Add shutdown hook to release any resources that were never closed
+            // In theory not necessary, but it won't hurt anything
+            Runtime.getRuntime().addShutdownHook(new Thread() {
+                @Override
+                public void run() {
+                    try {
+                        INSTANCE.close();
+                    } catch (SQLException e) {
+                        logger.warn("Unable to close PhoenixDriver on shutdown", e);
+                    }
+                }
+            });
         } catch (SQLException e) {
             throw new IllegalStateException("Untable to register " + PhoenixDriver.class.getName() + ": "+ e.getMessage());
         }
@@ -109,10 +125,18 @@ public final class PhoenixDriver extends PhoenixEmbeddedDriver {
 
     @Override
     public void close() throws SQLException {
-        try {
-            SQLCloseables.closeAll(connectionQueryServicesMap.values());
-        } finally {
-            connectionQueryServicesMap.clear();            
-        }
+        Collection<ConnectionQueryServices> connectionQueryServices = connectionQueryServicesMap.values();
+            if (!connectionQueryServices.isEmpty()) {
+                try {
+                    try {
+                        SQLCloseables.closeAll(connectionQueryServices);
+                    } finally {
+                        // We know there's a services object if any connections were made
+                        services.getExecutor().shutdownNow();
+                    }
+                } finally {
+                    connectionQueryServices.clear();            
+                }
+            }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8a21896f/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
index 2f28962..8cfe3c2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
@@ -17,6 +17,8 @@
  */
 package org.apache.phoenix.jdbc;
 
+import static org.apache.phoenix.util.PhoenixRuntime.PHOENIX_TEST_DRIVER_URL_PARAM;
+
 import java.sql.Connection;
 import java.sql.Driver;
 import java.sql.DriverPropertyInfo;
@@ -54,6 +56,8 @@ public abstract class PhoenixEmbeddedDriver implements Driver, org.apache.phoeni
     private final static String DNC_JDBC_PROTOCOL_SUFFIX = "//";
     private static final String TERMINATOR = "" + PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR;
     private static final String DELIMITERS = TERMINATOR + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR;
+    private static final String TEST_URL_AT_END =  "" + PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR + PHOENIX_TEST_DRIVER_URL_PARAM;
+    private static final String TEST_URL_IN_MIDDLE = TEST_URL_AT_END + PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR;
 
     private final static DriverPropertyInfo[] EMPTY_INFO = new DriverPropertyInfo[0];
     public final static String MAJOR_VERSION_PROP = "DriverMajorVersion";
@@ -321,6 +325,6 @@ public abstract class PhoenixEmbeddedDriver implements Driver, org.apache.phoeni
     }
 
     public static boolean isTestUrl(String url) {
-        return url.endsWith(";test=true") || url.contains(";test=true;");
+        return url.endsWith(TEST_URL_AT_END) || url.contains(TEST_URL_IN_MIDDLE);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8a21896f/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 6fc4661..f8faf34 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
@@ -225,8 +225,15 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
     public void close() throws SQLException {
         SQLException sqlE = null;
         try {
-            // Clear Phoenix metadata cache before closing HConnection
-            clearCache();
+            try {
+                // Clear Phoenix metadata cache before closing HConnection
+                clearCache();
+            } finally {
+                // Should not be necessary, but at test time in particular
+                // there seems to be a memory leak and this can't hurt.
+                childServices.clear();
+                latestMetaData = null;
+            }
         } catch (SQLException e) {
             sqlE = e;
         } finally {

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8a21896f/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index ea2847a..6026afd 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -256,15 +256,12 @@ public class MetaDataClient {
         return updateCache(schemaName, tableName, false);
     }
     
-    private static final MetaDataMutationResult SYSTEM_TABLE_RESULT = new MetaDataMutationResult(MutationCode.TABLE_ALREADY_EXISTS,QueryConstants.UNSET_TIMESTAMP,null);
-    
     private MetaDataMutationResult updateCache(String schemaName, String tableName, boolean alwaysHitServer) throws SQLException { // TODO: pass byte[] here
         Long scn = connection.getSCN();
-        PName tenantId = connection.getTenantId();
+        boolean systemTable = TYPE_SCHEMA.equals(schemaName);
+        // System tables must always have a null tenantId
+        PName tenantId = systemTable ? null : connection.getTenantId();
         long clientTimeStamp = scn == null ? HConstants.LATEST_TIMESTAMP : scn;
-        if (TYPE_SCHEMA.equals(schemaName) && !alwaysHitServer) {
-            return SYSTEM_TABLE_RESULT;
-        }
         PTable table = null;
         String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
         long tableTimestamp = HConstants.LATEST_TIMESTAMP;
@@ -276,7 +273,7 @@ public class MetaDataClient {
             // a global multi-tenant table
         }
         // Don't bother with server call: we can't possibly find a newer table
-        if (table != null && tableTimestamp == clientTimeStamp - 1 && !alwaysHitServer) {
+        if (table != null && !alwaysHitServer && (systemTable || tableTimestamp == clientTimeStamp - 1)) {
             return new MetaDataMutationResult(MutationCode.TABLE_ALREADY_EXISTS,QueryConstants.UNSET_TIMESTAMP,table);
         }
         

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8a21896f/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
index 8108bdd..d9947ee 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
@@ -227,6 +227,8 @@ public class PhoenixRuntime {
         }
     }
 
+    public static final String PHOENIX_TEST_DRIVER_URL_PARAM = "test=true";
+
     private PhoenixRuntime() {
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8a21896f/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseConnectedQueryTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseConnectedQueryTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseConnectedQueryTest.java
index 0942287..c33b12f 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseConnectedQueryTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseConnectedQueryTest.java
@@ -17,6 +17,11 @@
  */
 package org.apache.phoenix.end2end;
 
+import static org.apache.phoenix.util.PhoenixRuntime.CURRENT_SCN_ATTRIB;
+import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL;
+import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR;
+import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR;
+import static org.apache.phoenix.util.PhoenixRuntime.PHOENIX_TEST_DRIVER_URL_PARAM;
 import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB;
 import static org.apache.phoenix.util.TestUtil.ATABLE_NAME;
 import static org.apache.phoenix.util.TestUtil.A_VALUE;
@@ -34,6 +39,7 @@ import static org.apache.phoenix.util.TestUtil.ENTITYHISTID9;
 import static org.apache.phoenix.util.TestUtil.ENTITY_HISTORY_SALTED_TABLE_NAME;
 import static org.apache.phoenix.util.TestUtil.ENTITY_HISTORY_TABLE_NAME;
 import static org.apache.phoenix.util.TestUtil.E_VALUE;
+import static org.apache.phoenix.util.TestUtil.LOCALHOST;
 import static org.apache.phoenix.util.TestUtil.MILLIS_IN_DAY;
 import static org.apache.phoenix.util.TestUtil.PARENTID1;
 import static org.apache.phoenix.util.TestUtil.PARENTID2;
@@ -73,7 +79,6 @@ import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.query.BaseTest;
 import org.apache.phoenix.query.HBaseFactoryProvider;
 import org.apache.phoenix.schema.PTableType;
-import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.TestUtil;
 import org.junit.BeforeClass;
@@ -107,11 +112,12 @@ public abstract class BaseConnectedQueryTest extends BaseTest {
       }
       // reconstruct url when running against a live cluster
       if (isDistributedCluster) {
-        return "jdbc:phoenix:" + conf.get(HConstants.ZOOKEEPER_QUORUM, "localhost") + ":"
+        return JDBC_PROTOCOL + JDBC_PROTOCOL_SEPARATOR + conf.get(HConstants.ZOOKEEPER_QUORUM, LOCALHOST) 
+            + JDBC_PROTOCOL_SEPARATOR
             + conf.getInt(HConstants.ZOOKEEPER_CLIENT_PORT, HConstants.DEFAULT_ZOOKEPER_CLIENT_PORT)
-            + ":"
+            + JDBC_PROTOCOL_SEPARATOR
             + conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT)
-            + ";test=true";
+            + JDBC_PROTOCOL_TERMINATOR + PHOENIX_TEST_DRIVER_URL_PARAM;
       } else {
         return TestUtil.PHOENIX_JDBC_URL;
       }
@@ -129,7 +135,7 @@ public abstract class BaseConnectedQueryTest extends BaseTest {
     protected static void deletePriorTables(long ts, String tenantId) throws Exception {
         Properties props = new Properties();
         if (ts != HConstants.LATEST_TIMESTAMP) {
-            props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
+            props.setProperty(CURRENT_SCN_ATTRIB, Long.toString(ts));
         }
         Connection conn = null;
         if (tenantId != null) {
@@ -252,7 +258,7 @@ public abstract class BaseConnectedQueryTest extends BaseTest {
     protected static void initTablesWithArrays(String tenantId, Date date, Long ts, boolean useNull) throws Exception {
     	 Properties props = new Properties();
          if (ts != null) {
-             props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, ts.toString());
+             props.setProperty(CURRENT_SCN_ATTRIB, ts.toString());
          }
          Connection conn = DriverManager.getConnection(getUrl(), props);
          try {
@@ -336,7 +342,7 @@ public abstract class BaseConnectedQueryTest extends BaseTest {
         
         Properties props = new Properties();
         if (ts != null) {
-            props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts-3));
+            props.setProperty(CURRENT_SCN_ATTRIB, Long.toString(ts-3));
         }
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
@@ -549,7 +555,7 @@ public abstract class BaseConnectedQueryTest extends BaseTest {
         
         Properties props = new Properties();
         if (ts != null) {
-            props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, ts.toString());
+            props.setProperty(CURRENT_SCN_ATTRIB, ts.toString());
         }
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
@@ -653,7 +659,7 @@ public abstract class BaseConnectedQueryTest extends BaseTest {
         
         Properties props = new Properties();
         if (ts != null) {
-            props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, ts.toString());
+            props.setProperty(CURRENT_SCN_ATTRIB, ts.toString());
         }
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8a21896f/phoenix-core/src/test/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
index 8a2f304..3800261 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
@@ -99,7 +99,12 @@ public class ConnectionQueryServicesTestImpl extends ConnectionQueryServicesImpl
     public void close() throws SQLException {
         SQLException sqlE = null;
         try {
-            super.close();
+            try {
+                // Attempt to fix apparent memory leak...
+                clearCache();
+            } finally {
+                super.close();
+            }
         } catch (SQLException e)  {
             sqlE = e;
         } finally {

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8a21896f/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
index e2a55bc..090b675 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
@@ -34,7 +34,7 @@ public final class QueryServicesTestImpl extends BaseQueryServicesImpl {
     private static final int DEFAULT_THREAD_POOL_SIZE = 8;
     private static final int DEFAULT_QUEUE_SIZE = 0;
     // TODO: setting this down to 5mb causes insufficient memory exceptions. Need to investigate why
-    private static final int DEFAULT_MAX_MEMORY_PERC = 20; // 20% of heap
+    private static final int DEFAULT_MAX_MEMORY_PERC = 30; // 30% of heap
     private static final int DEFAULT_THREAD_TIMEOUT_MS = 60000*5; //5min
     private static final int DEFAULT_SPOOL_THRESHOLD_BYTES = 1024 * 1024; // 1m
     private static final int DEFAULT_MAX_MEMORY_WAIT_MS = 0;

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8a21896f/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
index d840125..ab3d3f4 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
@@ -17,6 +17,11 @@
  */
 package org.apache.phoenix.util;
 
+import static org.apache.phoenix.util.PhoenixRuntime.CONNECTIONLESS;
+import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL;
+import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR;
+import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR;
+import static org.apache.phoenix.util.PhoenixRuntime.PHOENIX_TEST_DRIVER_URL_PARAM;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
@@ -128,8 +133,9 @@ public class TestUtil {
     public final static List<String> ENTITYHISTIDS = Lists.newArrayList(ENTITYHISTID1, ENTITYHISTID2, ENTITYHISTID3, ENTITYHISTID4, ENTITYHISTID5, ENTITYHISTID6, ENTITYHISTID7, ENTITYHISTID8, ENTITYHISTID9);
     
     public static final long MILLIS_IN_DAY = 1000 * 60 * 60 * 24;
-    public static final String PHOENIX_JDBC_URL = "jdbc:phoenix:localhost;test=true";
-    public static final String PHOENIX_CONNECTIONLESS_JDBC_URL = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + PhoenixRuntime.CONNECTIONLESS  + ";test=true";
+    public static final String LOCALHOST = "localhost";
+    public static final String PHOENIX_JDBC_URL = JDBC_PROTOCOL + JDBC_PROTOCOL_SEPARATOR + LOCALHOST + JDBC_PROTOCOL_TERMINATOR + PHOENIX_TEST_DRIVER_URL_PARAM;
+    public static final String PHOENIX_CONNECTIONLESS_JDBC_URL = JDBC_PROTOCOL + JDBC_PROTOCOL_SEPARATOR + CONNECTIONLESS  + JDBC_PROTOCOL_TERMINATOR  + PHOENIX_TEST_DRIVER_URL_PARAM;
 
     public static final String TEST_SCHEMA_FILE_NAME = "config" + File.separator + "test-schema.xml";
     public static final String CED_SCHEMA_FILE_NAME = "config" + File.separator + "schema.xml";