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 2018/03/09 23:03:39 UTC

[2/3] phoenix git commit: PHOENIX-4148 COUNT(DISTINCT(...)) should have a memory size limit (Lars Hofhansl)

PHOENIX-4148 COUNT(DISTINCT(...)) should have a memory size limit (Lars Hofhansl)


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

Branch: refs/heads/4.x-HBase-1.3
Commit: e24b29d282266c0146e1e66dee274416e1921dae
Parents: 7047077
Author: James Taylor <jt...@salesforce.com>
Authored: Tue Mar 6 15:03:36 2018 -0800
Committer: James Taylor <jt...@salesforce.com>
Committed: Fri Mar 9 14:53:35 2018 -0800

----------------------------------------------------------------------
 .../phoenix/end2end/SpillableGroupByIT.java     | 74 ++++++++++++++------
 .../UngroupedAggregateRegionObserver.java       | 13 +++-
 .../phoenix/exception/SQLExceptionCode.java     |  5 +-
 .../expression/aggregator/Aggregators.java      |  3 +-
 .../aggregator/ClientAggregators.java           |  3 +-
 .../DistinctValueWithCountServerAggregator.java | 20 ++----
 .../aggregator/ServerAggregators.java           |  6 +-
 .../phoenix/memory/ChildMemoryManager.java      |  7 +-
 .../phoenix/memory/GlobalMemoryManager.java     | 19 +++--
 .../java/org/apache/phoenix/util/TestUtil.java  |  1 -
 10 files changed, 102 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/e24b29d2/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpillableGroupByIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpillableGroupByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpillableGroupByIT.java
index dc04b53..3689c4c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpillableGroupByIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpillableGroupByIT.java
@@ -17,12 +17,12 @@
  */
 package org.apache.phoenix.end2end;
 
-import static org.apache.phoenix.util.TestUtil.GROUPBYTEST_NAME;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.apache.phoenix.util.TestUtil.createGroupByTestTable;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
@@ -33,6 +33,7 @@ import java.sql.Statement;
 import java.util.Map;
 import java.util.Properties;
 
+import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
@@ -54,8 +55,10 @@ public class SpillableGroupByIT extends BaseOwnClusterIT {
     
     // covers: COUNT, COUNT(DISTINCT) SUM, AVG, MIN, MAX 
     private static String GROUPBY1 = "select "
-            + "count(*), count(distinct uri), sum(appcpu), avg(appcpu), uri, min(id), max(id) from "
-            + GROUPBYTEST_NAME + " group by uri";
+            + "count(*), count(distinct uri), sum(appcpu), avg(appcpu), uri, min(id), max(id) from %s "
+            + "group by uri";
+    
+    private static String GROUPBY2 = "select count(distinct uri) from %s";
     
     private int id;
 
@@ -84,10 +87,21 @@ public class SpillableGroupByIT extends BaseOwnClusterIT {
         createGroupByTestTable(conn, tableName);
     }
 
-    private void loadData(Connection conn) throws SQLException {
+    private void loadData(Connection conn, String tableName) throws SQLException {
         int groupFactor = NUM_ROWS_INSERTED / 2;
         for (int i = 0; i < NUM_ROWS_INSERTED; i++) {
-            insertRow(conn, Integer.toString(i % (groupFactor)), 10);
+            insertRow(conn, tableName, Integer.toString(i % (groupFactor)), 10);
+
+            if ((i % 1000) == 0) {
+                conn.commit();
+            }
+        }
+        conn.commit();
+    }
+
+    private void loadUniqueURIData(Connection conn, String tableName, int rowsToInsert) throws SQLException {
+        for (int i = 0; i < rowsToInsert; i++) {
+            insertRow(conn, tableName, Integer.toString(i), 10);
 
             if ((i % 1000) == 0) {
                 conn.commit();
@@ -96,10 +110,10 @@ public class SpillableGroupByIT extends BaseOwnClusterIT {
         conn.commit();
     }
 
-    private void insertRow(Connection conn, String uri, int appcpu)
+    private void insertRow(Connection conn, String tableName, String uri, int appcpu)
             throws SQLException {
         PreparedStatement statement = conn.prepareStatement("UPSERT INTO "
-                + GROUPBYTEST_NAME + "(id, uri, appcpu) values (?,?,?)");
+                + tableName + "(id, uri, appcpu) values (?,?,?)");
         statement.setString(1, String.valueOf(id));
         statement.setString(2, uri);
         statement.setInt(3, appcpu);
@@ -110,14 +124,14 @@ public class SpillableGroupByIT extends BaseOwnClusterIT {
     
     @Test
     public void testScanUri() throws Exception {
-        SpillableGroupByIT spGpByT = new SpillableGroupByIT();
+        String tableName = generateUniqueName();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
-        createTable(conn, GROUPBYTEST_NAME);
-        spGpByT.loadData(conn);
+        createTable(conn, tableName);
+        loadData(conn, tableName);
         props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Statement stmt = conn.createStatement();
-        ResultSet rs = stmt.executeQuery(GROUPBY1);
+        ResultSet rs = stmt.executeQuery(String.format(GROUPBY1, tableName));
 
         int count = 0;
         while (rs.next()) {
@@ -135,14 +149,14 @@ public class SpillableGroupByIT extends BaseOwnClusterIT {
         assertEquals(NUM_ROWS_INSERTED / 2, count);
         
         conn.createStatement();
-        rs = stmt.executeQuery("SELECT appcpu FROM " + GROUPBYTEST_NAME + " group by appcpu limit 1");
+        rs = stmt.executeQuery("SELECT appcpu FROM " + tableName + " group by appcpu limit 1");
 
         assertTrue(rs.next());
         assertEquals(10,rs.getInt(1));
         assertFalse(rs.next());
         
         stmt = conn.createStatement();
-        rs = stmt.executeQuery("SELECT to_number(uri) FROM " + GROUPBYTEST_NAME + " group by to_number(uri) limit 100");
+        rs = stmt.executeQuery("SELECT to_number(uri) FROM " + tableName + " group by to_number(uri) limit 100");
         count = 0;
         while (rs.next()) {
             count++;
@@ -152,24 +166,44 @@ public class SpillableGroupByIT extends BaseOwnClusterIT {
 
     @Test
     public void testStatisticsAreNotWritten() throws SQLException {
+        String tableName = generateUniqueName();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         Statement stmt = conn.createStatement();
-        stmt.execute("CREATE TABLE T1 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR)");
-        stmt.execute("UPSERT INTO T1 VALUES (1, 'NAME1')");
-        stmt.execute("UPSERT INTO T1 VALUES (2, 'NAME2')");
-        stmt.execute("UPSERT INTO T1 VALUES (3, 'NAME3')");
+        stmt.execute("CREATE TABLE " + tableName + " (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR)");
+        stmt.execute("UPSERT INTO " + tableName + " VALUES (1, 'NAME1')");
+        stmt.execute("UPSERT INTO " + tableName + " VALUES (2, 'NAME2')");
+        stmt.execute("UPSERT INTO " + tableName + " VALUES (3, 'NAME3')");
         conn.commit();
-        stmt.execute("UPDATE STATISTICS T1");
+        stmt.execute("UPDATE STATISTICS " + tableName);
         ResultSet rs = stmt.executeQuery("SELECT * FROM \"SYSTEM\".STATS");
         assertFalse(rs.next());
         rs.close();
         stmt.close();
-        rs = conn.createStatement().executeQuery("EXPLAIN SELECT * FROM T1");
+        rs = conn.createStatement().executeQuery("EXPLAIN SELECT * FROM " + tableName);
         String explainPlan = QueryUtil.getExplainPlan(rs);
         assertEquals(
-                "CLIENT 1-CHUNK PARALLEL 1-WAY FULL SCAN OVER T1",
+                "CLIENT 1-CHUNK PARALLEL 1-WAY FULL SCAN OVER " + tableName,
                 explainPlan);
        conn.close();
     }
+    
+    @Test
+    public void testDistinctCountFails() throws Exception {
+        String tableName = generateUniqueName();
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        createTable(conn, tableName);
+        loadUniqueURIData(conn, tableName, 1000);
+        props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Statement stmt = conn.createStatement();
+        ResultSet rs = stmt.executeQuery(String.format(GROUPBY2, tableName));
+        try {
+            rs.next();
+            fail();
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.INSUFFICIENT_MEMORY.getErrorCode(),e.getErrorCode());
+        }
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e24b29d2/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
index 6108aca..72ca58d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
@@ -76,7 +76,9 @@ import org.apache.hadoop.hbase.security.User;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.hadoop.io.WritableUtils;
+import org.apache.phoenix.cache.GlobalCache;
 import org.apache.phoenix.cache.ServerCacheClient;
+import org.apache.phoenix.cache.TenantCache;
 import org.apache.phoenix.coprocessor.generated.PTableProtos;
 import org.apache.phoenix.exception.DataExceedsCapacityException;
 import org.apache.phoenix.exception.SQLExceptionCode;
@@ -98,6 +100,7 @@ import org.apache.phoenix.index.PhoenixIndexFailurePolicy;
 import org.apache.phoenix.index.PhoenixIndexFailurePolicy.MutateCommand;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.join.HashJoinInfo;
+import org.apache.phoenix.memory.MemoryManager.MemoryChunk;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
@@ -515,7 +518,8 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
         byte[] clientVersionBytes = scan.getAttribute(PhoenixIndexCodec.CLIENT_VERSION);
         boolean acquiredLock = false;
         boolean incrScanRefCount = false;
-        try {
+        final TenantCache tenantCache = GlobalCache.getTenantCache(env, ScanUtil.getTenantId(scan));
+        try (MemoryChunk em = tenantCache.getMemoryManager().allocate(0)) {
             if(needToWrite) {
                 synchronized (lock) {
                     if (isRegionClosingOrSplitting) {
@@ -528,6 +532,7 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
             }
             region.startRegionOperation();
             acquiredLock = true;
+            long size = 0;
             synchronized (innerScanner) {
                 do {
                     List<Cell> results = useQualifierAsIndex ? new EncodedColumnQualiferCellsList(minMaxQualifiers.getFirst(), minMaxQualifiers.getSecond(), encodingScheme) : new ArrayList<Cell>();
@@ -759,7 +764,11 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
                             commitBatch(region, indexMutations, blockingMemStoreSize);
                             indexMutations.clear();
                         }
-                        aggregators.aggregate(rowAggregators, result);
+                        size += aggregators.aggregate(rowAggregators, result);
+                        while(size > em.getSize()) {
+                            logger.info("Request: {}, resizing {} by 1024*1024", size, em.getSize());
+                            em.resize(em.getSize() + 1024*1024);
+                        }
                         hasAny = true;
                     }
                 } while (hasMore);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e24b29d2/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
index dcf761a..9cbc67e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
@@ -434,14 +434,15 @@ public enum SQLExceptionCode {
     SCHEMA_NOT_ALLOWED(724, "43M07", "Schema name not allowed!!"),
     CREATE_SCHEMA_NOT_ALLOWED(725, "43M08", "Cannot create schema because config "
             + QueryServices.IS_NAMESPACE_MAPPING_ENABLED + " for enabling name space mapping isn't enabled."),
-    INCONSISTENT_NAMESPACE_MAPPING_PROPERTIES(726, "43M10", " Inconsistent namespace mapping properties.."),
-    ASYNC_NOT_ALLOWED(727, "43M11", " ASYNC option is not allowed.. "),
+    INCONSISTENT_NAMESPACE_MAPPING_PROPERTIES(726, "43M10", " Inconsistent namespace mapping properties."),
+    ASYNC_NOT_ALLOWED(727, "43M11", " ASYNC option is not allowed."),
     NEW_CONNECTION_THROTTLED(728, "410M1", "Could not create connection " +
         "because this client already has the maximum number" +
         " of connections to the target cluster."),
     
     MAX_MUTATION_SIZE_EXCEEDED(729, "LIM01", "MutationState size is bigger than maximum allowed number of rows"),
     MAX_MUTATION_SIZE_BYTES_EXCEEDED(730, "LIM02", "MutationState size is bigger than maximum allowed number of bytes"), 
+    INSUFFICIENT_MEMORY(999, "50M01", "Unable to allocate enough memory."),
     HASH_JOIN_CACHE_NOT_FOUND(900, "HJ01", "Hash Join cache not found");
 
     private final int errorCode;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e24b29d2/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/Aggregators.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/Aggregators.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/Aggregators.java
index b1dc658..2f6e6ee 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/Aggregators.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/Aggregators.java
@@ -19,6 +19,7 @@ package org.apache.phoenix.expression.aggregator;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.function.SingleAggregateFunction;
+import org.apache.phoenix.memory.MemoryManager.MemoryChunk;
 import org.apache.phoenix.schema.KeyValueSchema;
 import org.apache.phoenix.schema.KeyValueSchema.KeyValueSchemaBuilder;
 import org.apache.phoenix.schema.ValueBitSet;
@@ -82,7 +83,7 @@ abstract public class Aggregators {
      * Aggregate over aggregators
      * @param result the single row Result from scan iteration
      */
-    abstract public void aggregate(Aggregator[] aggregators, Tuple result);
+    abstract public long aggregate(Aggregator[] aggregators, Tuple result);
 
     protected static int calculateSize(Aggregator[] aggregators) {
         

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e24b29d2/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ClientAggregators.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ClientAggregators.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ClientAggregators.java
index 54d5690..f1ed2a9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ClientAggregators.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ClientAggregators.java
@@ -50,7 +50,7 @@ public class ClientAggregators extends Aggregators {
     }
     
     @Override
-    public void aggregate(Aggregator[] aggregators, Tuple result) {
+    public long aggregate(Aggregator[] aggregators, Tuple result) {
         TupleUtil.getAggregateValue(result, ptr);
         tempValueSet.clear();
         tempValueSet.or(ptr);
@@ -64,6 +64,7 @@ public class ClientAggregators extends Aggregators {
             }
             i++;
         }
+        return 0;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e24b29d2/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountServerAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountServerAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountServerAggregator.java
index 4801a9d..ea7474f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountServerAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountServerAggregator.java
@@ -52,6 +52,7 @@ public class DistinctValueWithCountServerAggregator extends BaseAggregator {
     private static final int FIXED_COPY_THRESHOLD = SizedUtil.ARRAY_SIZE * 2;
 
     private int compressThreshold;
+    private int heapSize = 0;
     private byte[] buffer = null;
     protected Map<ImmutableBytesPtr, Integer> valueVsCount = new HashMap<ImmutableBytesPtr, Integer>();
 
@@ -75,6 +76,9 @@ public class DistinctValueWithCountServerAggregator extends BaseAggregator {
         Integer count = this.valueVsCount.get(key);
         if (count == null) {
             this.valueVsCount.put(key, 1);
+            heapSize += SizedUtil.MAP_ENTRY_SIZE + // entry
+                    Bytes.SIZEOF_INT + // key size
+                    key.getLength() + SizedUtil.ARRAY_SIZE; // value size
         } else {
             this.valueVsCount.put(key, ++count);
         }
@@ -130,20 +134,7 @@ public class DistinctValueWithCountServerAggregator extends BaseAggregator {
 
     // The heap size which will be taken by the count map.
     private int countMapHeapSize() {
-        int size = 0;
-        if (this.valueVsCount.size() > 0) {
-            for (ImmutableBytesPtr key : this.valueVsCount.keySet()) {
-                size += SizedUtil.MAP_ENTRY_SIZE + // entry
-                        Bytes.SIZEOF_INT + // key size
-                        key.getLength() + SizedUtil.ARRAY_SIZE; // value size
-            }
-        } else {
-            // Initially when the getSize() is called, we dont have any entries in the map so as to
-            // tell the exact heap need. Let us approximate the #entries
-            SizedUtil.sizeOfMap(DEFAULT_ESTIMATED_DISTINCT_VALUES,
-                    SizedUtil.IMMUTABLE_BYTES_PTR_SIZE, Bytes.SIZEOF_INT);
-        }
-        return size;
+        return heapSize;
     }
 
     @Override
@@ -154,6 +145,7 @@ public class DistinctValueWithCountServerAggregator extends BaseAggregator {
     @Override
     public void reset() {
         valueVsCount = new HashMap<ImmutableBytesPtr, Integer>();
+        heapSize = 0;
         buffer = null;
         super.reset();
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e24b29d2/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ServerAggregators.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ServerAggregators.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ServerAggregators.java
index 366bbc6..790939c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ServerAggregators.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ServerAggregators.java
@@ -52,13 +52,17 @@ public class ServerAggregators extends Aggregators {
     }
     
     @Override
-    public void aggregate(Aggregator[] aggregators, Tuple result) {
+    public long aggregate(Aggregator[] aggregators, Tuple result) {
+        long dsize = 0;
         for (int i = 0; i < expressions.length; i++) {
             if (expressions[i].evaluate(result, ptr) && ptr.getLength() != 0) {
+                dsize -= aggregators[i].getSize();
                 aggregators[i].aggregate(result, ptr);
+                dsize += aggregators[i].getSize();
             }
             expressions[i].reset();
         }
+        return dsize;
     }
     
     /**

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e24b29d2/phoenix-core/src/main/java/org/apache/phoenix/memory/ChildMemoryManager.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/memory/ChildMemoryManager.java b/phoenix-core/src/main/java/org/apache/phoenix/memory/ChildMemoryManager.java
index 8f7571b..da009fb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/memory/ChildMemoryManager.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/memory/ChildMemoryManager.java
@@ -19,6 +19,8 @@ package org.apache.phoenix.memory;
 
 import org.apache.http.annotation.GuardedBy;
 import org.apache.http.annotation.ThreadSafe;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.exception.SQLExceptionInfo;
 
 /**
  * 
@@ -54,7 +56,10 @@ public class ChildMemoryManager extends DelegatingMemoryManager {
         long availBytes = getAvailableMemory();
         // Check if this memory managers percentage of allocated bytes exceeds its allowed maximum
         if (minBytes > availBytes) {
-            throw new InsufficientMemoryException("Attempt to allocate more memory than the max allowed of " + maxPercOfTotal + "%");
+            throw new InsufficientMemoryException(
+                    new SQLExceptionInfo.Builder(SQLExceptionCode.INSUFFICIENT_MEMORY)
+                    .setMessage("Attempt to allocate more memory than the max allowed of " + maxPercOfTotal + "%")
+                    .build().buildException());
         }
         // Revise reqBytes down to available memory if necessary
         return Math.min(reqBytes,availBytes);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e24b29d2/phoenix-core/src/main/java/org/apache/phoenix/memory/GlobalMemoryManager.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/memory/GlobalMemoryManager.java b/phoenix-core/src/main/java/org/apache/phoenix/memory/GlobalMemoryManager.java
index 651526f..fe0d6d7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/memory/GlobalMemoryManager.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/memory/GlobalMemoryManager.java
@@ -18,6 +18,8 @@
 package org.apache.phoenix.memory;
 
 import org.apache.http.annotation.GuardedBy;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 /**
@@ -55,7 +57,6 @@ public class GlobalMemoryManager implements MemoryManager {
         return maxMemoryBytes;
     }
 
-
     // TODO: Work on fairness: One big memory request can cause all others to fail here.
     private long allocateBytes(long minBytes, long reqBytes) {
         if (minBytes < 0 || reqBytes < 0) {
@@ -63,15 +64,21 @@ public class GlobalMemoryManager implements MemoryManager {
                     + ") and requested bytes (" + reqBytes + ") must be greater than zero");
         }
         if (minBytes > maxMemoryBytes) {
-            throw new InsufficientMemoryException("Requested memory of " + minBytes
-                    + " bytes is larger than global pool of " + maxMemoryBytes + " bytes.");
+            throw new InsufficientMemoryException(
+                    new SQLExceptionInfo.Builder(SQLExceptionCode.INSUFFICIENT_MEMORY)
+                    .setMessage("Requested memory of " + minBytes
+                              + " bytes is larger than global pool of " + maxMemoryBytes + " bytes.")
+                    .build().buildException());
         }
         long nBytes;
         synchronized(sync) {
             if (usedMemoryBytes + minBytes > maxMemoryBytes) {
-                throw new InsufficientMemoryException("Requested memory of " + minBytes
-                        + " bytes could not be allocated. Using memory of " + usedMemoryBytes
-                        + " bytes from global pool of " + maxMemoryBytes);
+                throw new InsufficientMemoryException(
+                        new SQLExceptionInfo.Builder(SQLExceptionCode.INSUFFICIENT_MEMORY)
+                        .setMessage("Requested memory of " + minBytes
+                                + " bytes could not be allocated. Using memory of " + usedMemoryBytes
+                                + " bytes from global pool of " + maxMemoryBytes)
+                        .build().buildException());
             }
             // Allocate at most reqBytes, but at least minBytes
             nBytes = Math.min(reqBytes, maxMemoryBytes - usedMemoryBytes);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e24b29d2/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 d50589f..1ec07b6 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
@@ -228,7 +228,6 @@ public class TestUtil {
     public static final String STABLE_NAME = "STABLE";
     public static final String STABLE_PK_NAME = "ID";
     public static final String STABLE_SCHEMA_NAME = "";
-    public static final String GROUPBYTEST_NAME = "GROUPBYTEST";
     public static final String CUSTOM_ENTITY_DATA_FULL_NAME = "CORE.CUSTOM_ENTITY_DATA";
     public static final String CUSTOM_ENTITY_DATA_NAME = "CUSTOM_ENTITY_DATA";
     public static final String CUSTOM_ENTITY_DATA_SCHEMA_NAME = "CORE";