Author: reschke
Date: Thu Apr 25 13:54:16 2019
New Revision: 1858139

URL: http://svn.apache.org/viewvc?rev=1858139&view=rev
Log:
OAK-8273: RDBDocumentStore: createOrUpdate with less than 3 ops suboptimal

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

Modified: 
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1858139&r1=1858138&r2=1858139&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
 Thu Apr 25 13:54:16 2019
@@ -369,14 +369,22 @@ public class RDBDocumentStore implements
 
     @Override
     public <T extends Document> List<T> createOrUpdate(Collection<T> 
collection, List<UpdateOp> updateOps) {
-        if (!BATCHUPDATES) {
+        // fall back to sequential mode if batches are turned off using system
+        // property, or the number of update operations is small
+        if (!BATCHUPDATES || updateOps.size() < MINIMALBULKUPDATESIZE) {
             List<T> results = new ArrayList<T>(updateOps.size());
             for (UpdateOp update : updateOps) {
                 results.add(createOrUpdate(collection, update));
             }
             return results;
+        } else {
+            return internalCreateOrUpdate(collection, updateOps);
         }
+    }
 
+    private static int MINIMALBULKUPDATESIZE = 3;
+
+    private <T extends Document> List<T> internalCreateOrUpdate(Collection<T> 
collection, List<UpdateOp> updateOps) {
         final Stopwatch watch = startWatch();
         Map<UpdateOp, T> results = new LinkedHashMap<UpdateOp, T>();
         Map<String, UpdateOp> operationsToCover = new LinkedHashMap<String, 
UpdateOp>();
@@ -402,9 +410,7 @@ public class RDBDocumentStore implements
 
         int i = 0; // iteration count
 
-        // bulk update requires two DB requests, so if we have <= 2 operations
-        // it's better to send them sequentially
-        while (operationsToCover.size() > 2) {
+        while (operationsToCover.size() >= MINIMALBULKUPDATESIZE) {
             // We should try to insert documents only during the first
             // iteration. In the 2nd and 3rd iterations we only deal with
             // conflicting documents, so they already exist in the database


Reply via email to