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 2014/10/23 17:17:14 UTC

svn commit: r1633838 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java

Author: reschke
Date: Thu Oct 23 15:17:14 2014
New Revision: 1633838

URL: http://svn.apache.org/r1633838
Log:
OAK-1941 - add test case for measuring collection lookup, restrict result set size in SQL queries

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1633838&r1=1633837&r2=1633838&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java Thu Oct 23 15:17:14 2014
@@ -344,6 +344,9 @@ public class RDBDocumentStore implements
     // for DBs that prefer "concat" over "||"
     private boolean needsConcat = false;
 
+    // for DBs that prefer "limit" over "fetch first"
+    private boolean needsLimit = false;
+
     // set of supported indexed properties
     private static Set<String> INDEXEDPROPERTIES = new HashSet<String>(Arrays.asList(new String[] { MODIFIED,
             NodeDocument.HAS_BINARY_FLAG }));
@@ -378,6 +381,7 @@ public class RDBDocumentStore implements
             con.commit();
         } else if ("MySQL".equals(dbtype)) {
             this.needsConcat = true;
+            this.needsLimit = true;
         }
 
         try {
@@ -993,7 +997,7 @@ public class RDBDocumentStore implements
         }
         t += " order by ID";
         if (limit != Integer.MAX_VALUE) {
-            t += " FETCH FIRST " + limit + " ROWS ONLY";
+            t += this.needsConcat ? (" LIMIT " + limit) : (" FETCH FIRST " + limit + " ROWS ONLY");
         }
         PreparedStatement stmt = connection.prepareStatement(t);
         List<RDBRow> result = new ArrayList<RDBRow>();

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java?rev=1633838&r1=1633837&r2=1633838&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java Thu Oct 23 15:17:14 2014
@@ -402,6 +402,60 @@ public class BasicDocumentStoreTest exte
     }
 
     @Test
+    public void testPerfCollectionPaging() {
+        String cid = this.getClass().getName() + ".testPerfCollectionPaging";
+        int nodecount = 20000;
+        int initialFetchCount = 100;
+        int maxFetchCount = 1600;
+        int fetchcount = initialFetchCount;
+        long duration = 2000;
+        int cnt = 0;
+        List<UpdateOp> ups = new ArrayList<UpdateOp>();
+
+        UpdateOp container = new UpdateOp(cid, true);
+        container.set("_id", cid);
+        ups.add(container);
+        removeMe.add(cid);
+        for (int i = 0; i < nodecount; i++) {
+            String id = String.format("%s/%08d", cid, i);
+            removeMe.add(id);
+            UpdateOp u = new UpdateOp(id, true);
+            u.set("_id", id);
+            ups.add(u);
+        }
+
+        boolean success = super.ds.create(Collection.NODES, ups);
+        assertTrue(success);
+
+        long end = System.currentTimeMillis() + duration;
+        String sid = cid;
+        int found = 0;
+        while (System.currentTimeMillis() < end) {
+            List<NodeDocument> result = super.ds.query(Collection.NODES, sid, cid + "X", fetchcount);
+            found += result.size();
+            if (result.size() < fetchcount) {
+                if (sid.equals(cid)) {
+                    fail("first page must not be empty");
+                }
+                sid = cid;
+                assertEquals(nodecount, found);
+                found = 0;
+                fetchcount = initialFetchCount;
+            }
+            else {
+                sid = result.get(result.size() -1).getId();
+                if (fetchcount < maxFetchCount) {
+                    fetchcount *= 2;
+                }
+            }
+            cnt += 1;
+        }
+
+        LOG.info("collection lookups " + super.dsname + " was "
+                + cnt + " in " + duration + "ms (" + (cnt / (duration / 1000f)) + "/s)");
+    }
+
+    @Test
     public void testPerfLastRevBatch() {
         String bid = this.getClass().getName() + ".testPerfLastRevBatch";
         int nodecount = 100;