jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1547017 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java test/java/org/apache/jackrabbit/oak/plugins/mongomk/BackgroundWriteTest.java
Date Mon, 02 Dec 2013 13:43:32 GMT
Author: mreutegg
Date: Mon Dec  2 13:43:31 2013
New Revision: 1547017

URL: http://svn.apache.org/r1547017
Log:
OAK-1190: Limit size of batch update in background write

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/BackgroundWriteTest.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java?rev=1547017&r1=1547016&r2=1547017&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java
Mon Dec  2 13:43:31 2013
@@ -106,6 +106,11 @@ public final class MongoNodeStore
     private static final int REMEMBER_REVISION_ORDER_MILLIS = 60 * 60 * 1000;
 
     /**
+     * The maximum number of document to update at once in a multi update.
+     */
+    static final int BACKGROUND_MULTI_UPDATE_LIMIT = 10000;
+
+    /**
      * The MongoDB store (might be used by multiple MongoMKs).
      */
     protected final DocumentStore store;
@@ -1182,9 +1187,13 @@ public final class MongoNodeStore
                 // use multi update when possible
                 ids.add(Utils.getIdFromPath(p));
             }
-            // update if this is the last path or
-            // revision is not equal to last revision
-            if (i + 1 >= paths.size() || size == ids.size()) {
+            // call update if any of the following is true:
+            // - this is the last path
+            // - revision is not equal to last revision (size of ids didn't change)
+            // - the update limit is reached
+            if (i + 1 >= paths.size()
+                    || size == ids.size()
+                    || ids.size() >= BACKGROUND_MULTI_UPDATE_LIMIT) {
                 store.update(Collection.NODES, ids, updateOp);
                 for (String id : ids) {
                     unsavedLastRevisions.remove(Utils.getPathFromId(id));

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/BackgroundWriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/BackgroundWriteTest.java?rev=1547017&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/BackgroundWriteTest.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/BackgroundWriteTest.java
Mon Dec  2 13:43:31 2013
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.mongomk;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests related to background write operation in MongoNodeStore.
+ */
+public class BackgroundWriteTest {
+
+    @Test // OAK-1190
+    public void limitMultiUpdate() {
+        MongoMK mk = new MongoMK.Builder().setDocumentStore(
+                new TestStore()).setAsyncDelay(0).open();
+        List<String> paths = new ArrayList<String>();
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; paths.size() < MongoNodeStore.BACKGROUND_MULTI_UPDATE_LIMIT *
2; i++) {
+            String child = "node-" + i;
+            sb.append("+\"").append(child).append("\":{}");
+            for (int j = 0; j < 1000; j++) {
+                String p = child + "/node-" + j;
+                paths.add(p);
+                sb.append("+\"").append(p).append("\":{}");
+            }
+        }
+        mk.commit("/", sb.toString(), null, null);
+        mk.runBackgroundOperations();
+        Revision r = mk.getNodeStore().newRevision();
+        UnsavedModifications pending = mk.getNodeStore().getPendingModifications();
+        for (String p : paths) {
+            pending.put(p, r);
+        }
+        mk.runBackgroundOperations();
+    }
+
+    private static final class TestStore extends MemoryDocumentStore {
+
+        @Override
+        public <T extends Document> void update(Collection<T> collection,
+                                                List<String> keys,
+                                                UpdateOp updateOp) {
+            assertTrue(keys.size() <= MongoNodeStore.BACKGROUND_MULTI_UPDATE_LIMIT);
+            super.update(collection, keys, updateOp);
+        }
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/BackgroundWriteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/BackgroundWriteTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message