You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2015/05/29 15:21:14 UTC

svn commit: r1682456 - in /jackrabbit/oak/branches/1.2: ./ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java

Author: reschke
Date: Fri May 29 13:21:14 2015
New Revision: 1682456

URL: http://svn.apache.org/r1682456
Log:
OAK-2931 - RDBDocumentStore: mitigate effects of large query result sets (ported to 1.2)

Modified:
    jackrabbit/oak/branches/1.2/   (props changed)
    jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java

Propchange: jackrabbit/oak/branches/1.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri May 29 13:21:14 2015
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414,1673436,1673644,1673662-1673664,1673669,1673695,1674046,1674065,1674075,1674107,1674228,1674880,1675054-1675055,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677939,1677991,1678173,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679235,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680805-1680806,1680903,1681282,1681767,1681918,1682218,1682235
+/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414,1673436,1673644,1673662-1673664,1673669,1673695,1674046,1674065,1674075,1674107,1674228,1674880,1675054-1675055,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677939,1677991,1678173,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679235,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680805-1680806,1680903,1681282,1681767,1681918,1682218,1682235,1682437
 /jackrabbit/trunk:1345480

Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1682456&r1=1682455&r2=1682456&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java Fri May 29 13:21:14 2015
@@ -1198,7 +1198,7 @@ public class RDBDocumentStore implements
             String indexedProperty, long startValue, int limit) {
         Connection connection = null;
         String tableName = getTable(collection);
-        List<T> result = new ArrayList<T>();
+        List<T> result = Collections.emptyList();
         if (indexedProperty != null && (!INDEXEDPROPERTIES.contains(indexedProperty))) {
             String message = "indexed property " + indexedProperty + " not supported, query was '>= '" + startValue
                     + "'; supported properties are " + INDEXEDPROPERTIES;
@@ -1210,8 +1210,12 @@ public class RDBDocumentStore implements
             connection = this.ch.getROConnection();
             List<RDBRow> dbresult = dbQuery(connection, tableName, fromKey, toKey, indexedProperty, startValue, limit);
             connection.commit();
-            for (RDBRow r : dbresult) {
-                T doc = runThroughCache(collection, r, now);
+
+            int size = dbresult.size();
+            result = new ArrayList<T>(size);
+            for (int i = 0; i < size; i++) {
+                RDBRow row = dbresult.set(i, null); // free RDBRow ASAP
+                T doc = runThroughCache(collection, row, now);
                 result.add(doc);
             }
         } catch (Exception ex) {
@@ -1442,6 +1446,9 @@ public class RDBDocumentStore implements
     // Number of documents to insert at once for batch create
     private static final int CHUNKSIZE = Integer.getInteger(
             "org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.CHUNKSIZE", 64);
+    // Number of query hits above which a diagnostic warning is generated
+    private static final int QUERYHITSLIMIT = Integer.getInteger(
+            "org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QUERYHITSLIMIT", 4096);
 
     private static byte[] asBytes(String data) {
         byte[] bytes;
@@ -1558,6 +1565,7 @@ public class RDBDocumentStore implements
 
     private List<RDBRow> dbQuery(Connection connection, String tableName, String minId, String maxId, String indexedProperty,
             long startValue, int limit) throws SQLException {
+        long start = System.currentTimeMillis();
         String t = "select ";
         if (limit != Integer.MAX_VALUE && this.db.getFetchFirstSyntax() == FETCHFIRSTSYNTAX.TOP) {
             t += "TOP " + limit +  " ";
@@ -1629,6 +1637,14 @@ public class RDBDocumentStore implements
         } finally {
             stmt.close();
         }
+
+        if (result.size() > QUERYHITSLIMIT) {
+            long elapsed = System.currentTimeMillis() - start;
+            String message = String.format("Potentially excessive query with %d hits, limit was %d, elapsed time %dms, check calling method.",
+                    result.size(), limit, elapsed);
+            LOG.info(message, new Exception("call stack"));
+        }
+
         return result;
     }