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 mr...@apache.org on 2013/12/12 09:56:43 UTC
svn commit: r1550377 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/mongomk/
test/java/org/apache/jackrabbit/oak/plugins/mongomk/
Author: mreutegg
Date: Thu Dec 12 08:56:43 2013
New Revision: 1550377
URL: http://svn.apache.org/r1550377
Log:
OAK-1281: Incorrect path sorting in background write
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/PathComparator.java (with props)
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/PathComparatorTest.java (with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/BackgroundWriteTest.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=1550377&r1=1550376&r2=1550377&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 Thu Dec 12 08:56:43 2013
@@ -27,7 +27,6 @@ import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -1183,19 +1182,7 @@ public final class MongoNodeStore
}
ArrayList<String> paths = new ArrayList<String>(unsavedLastRevisions.getPaths());
// sort by depth (high depth first), then path
- Collections.sort(paths, new Comparator<String>() {
-
- @Override
- public int compare(String o1, String o2) {
- int d1 = Utils.pathDepth(o1);
- int d2 = Utils.pathDepth(o1);
- if (d1 != d2) {
- return Integer.signum(d1 - d2);
- }
- return o1.compareTo(o2);
- }
-
- });
+ Collections.sort(paths, PathComparator.INSTANCE);
UpdateOp updateOp = null;
Revision lastRev = null;
@@ -1219,10 +1206,11 @@ public final class MongoNodeStore
ids.add(Utils.getIdFromPath(p));
}
// call update if any of the following is true:
- // - this is the last path
+ // - this is the second-to-last or last path (update last path, the
+ // root document, individually)
// - revision is not equal to last revision (size of ids didn't change)
// - the update limit is reached
- if (i + 1 >= paths.size()
+ if (i + 2 >= paths.size()
|| size == ids.size()
|| ids.size() >= BACKGROUND_MULTI_UPDATE_LIMIT) {
store.update(Collection.NODES, ids, updateOp);
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/PathComparator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/PathComparator.java?rev=1550377&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/PathComparator.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/PathComparator.java Thu Dec 12 08:56:43 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.Comparator;
+
+import org.apache.jackrabbit.oak.plugins.mongomk.util.Utils;
+
+/**
+ * Implements a comparator, which sorts path string according to 1) their
+ * depth (highest first) and 2) the path string itself.
+ */
+class PathComparator implements Comparator<String> {
+
+ static final Comparator<String> INSTANCE = new PathComparator();
+
+ private PathComparator() {
+ }
+
+ @Override
+ public int compare(String o1, String o2) {
+ int d1 = Utils.pathDepth(o1);
+ int d2 = Utils.pathDepth(o2);
+ if (d1 != d2) {
+ return Integer.signum(d2 - d1);
+ }
+ return o1.compareTo(o2);
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/PathComparator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/PathComparator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified: 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=1550377&r1=1550376&r2=1550377&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/BackgroundWriteTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/BackgroundWriteTest.java Thu Dec 12 08:56:43 2013
@@ -47,6 +47,7 @@ public class BackgroundWriteTest {
mk.runBackgroundOperations();
Revision r = mk.getNodeStore().newRevision();
UnsavedModifications pending = mk.getNodeStore().getPendingModifications();
+ paths.add("/");
for (String p : paths) {
pending.put(p, r);
}
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/PathComparatorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/PathComparatorTest.java?rev=1550377&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/PathComparatorTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/PathComparatorTest.java Thu Dec 12 08:56:43 2013
@@ -0,0 +1,52 @@
+/*
+ * 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.Collections;
+import java.util.List;
+
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for {@link PathComparator}.
+ */
+public class PathComparatorTest {
+
+ @Test
+ public void sort() {
+ List<String> paths = new ArrayList<String>();
+ paths.add("/foo");
+ paths.add("/foo/bar");
+ paths.add("/bar/qux");
+ paths.add("/");
+ paths.add("/bar");
+
+ Collections.sort(paths, PathComparator.INSTANCE);
+
+ List<String> expected = Lists.newArrayList(
+ "/bar/qux", "/foo/bar", "/bar", "/foo", "/");
+
+ assertEquals(expected, paths);
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/PathComparatorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/PathComparatorTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL