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 ch...@apache.org on 2015/03/11 11:40:24 UTC
svn commit: r1665835 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/document/
main/java/org/apache/jackrabbit/oak/plugins/document/util/
test/java/org/apache/jackrabbit/oak/plugins/document/
test/java/org/apache/ja...
Author: chetanm
Date: Wed Mar 11 10:40:24 2015
New Revision: 1665835
URL: http://svn.apache.org/r1665835
Log:
OAK-2603 - Failure in one of the batch in VersionGC might lead to orphaned nodes
Adding a comparator for NodeDocument ID and using that in GC
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentIdComparator.java (with props)
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentIdComparatorTest.java (with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentIdComparator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentIdComparator.java?rev=1665835&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentIdComparator.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentIdComparator.java Wed Mar 11 10:40:24 2015
@@ -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.document;
+
+import java.util.Comparator;
+
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
+
+/**
+ * Implements a comparator, which sorts NodeDocumentId string according to 1) their
+ * depth (highest first) and 2) the id string itself.
+ */
+public class NodeDocumentIdComparator implements Comparator<String> {
+ public static final Comparator<String> INSTANCE = new NodeDocumentIdComparator();
+
+ private NodeDocumentIdComparator() {
+ }
+
+ @Override
+ public int compare(String o1, String o2) {
+ int d1 = Utils.getDepthFromId(o1);
+ int d2 = Utils.getDepthFromId(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/document/NodeDocumentIdComparator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java?rev=1665835&r1=1665834&r2=1665835&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java Wed Mar 11 10:40:24 2015
@@ -110,7 +110,7 @@ public class VersionGarbageCollector {
Utils.closeIfCloseable(itr);
}
- Collections.sort(docIdsToDelete, PathComparator.INSTANCE);
+ Collections.sort(docIdsToDelete, NodeDocumentIdComparator.INSTANCE);
if(log.isDebugEnabled()) {
StringBuilder sb = new StringBuilder("Deleted document with following ids were deleted as part of GC \n");
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java?rev=1665835&r1=1665834&r2=1665835&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java Wed Mar 11 10:40:24 2015
@@ -329,6 +329,12 @@ public class Utils {
return id.substring(index + 1);
}
+ public static int getDepthFromId(String id) {
+ int index = id.indexOf(':');
+ assert index > 0 : "Invalid id " + id;
+ return Integer.parseInt(id.substring(0, index));
+ }
+
public static String getPreviousPathFor(String path, Revision r, int height) {
if (!PathUtils.isAbsolute(path)) {
throw new IllegalArgumentException("path must be absolute: " + path);
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentIdComparatorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentIdComparatorTest.java?rev=1665835&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentIdComparatorTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentIdComparatorTest.java Wed Mar 11 10:40:24 2015
@@ -0,0 +1,53 @@
+/*
+ * 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.document;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import com.google.common.collect.Lists;
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for {@link org.apache.jackrabbit.oak.plugins.document.PathComparator}.
+ */
+public class NodeDocumentIdComparatorTest {
+
+ @Test
+ public void sort() {
+ List<String> paths = new ArrayList<String>();
+ paths.add(Utils.getIdFromPath("/foo"));
+ paths.add(Utils.getIdFromPath("/foo/bar"));
+ paths.add(Utils.getIdFromPath("/bar/qux"));
+ paths.add(Utils.getIdFromPath("/"));
+ paths.add(Utils.getIdFromPath("/bar"));
+
+ Collections.sort(paths, NodeDocumentIdComparator.INSTANCE);
+
+ List<String> expected = Lists.newArrayList(
+ "2:/bar/qux", "2:/foo/bar", "1:/bar", "1:/foo", "0:/");
+
+ assertEquals(expected, paths);
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentIdComparatorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java?rev=1665835&r1=1665834&r2=1665835&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java Wed Mar 11 10:40:24 2015
@@ -68,6 +68,13 @@ public class UtilsTest {
assertEquals("1:/foo",Utils.getParentId("2:/foo/bar"));
}
+ @Test
+ public void getDepthFromId() throws Exception{
+ assertEquals(1, Utils.getDepthFromId("1:/x"));
+ assertEquals(2, Utils.getDepthFromId("2:/x"));
+ assertEquals(10, Utils.getDepthFromId("10:/x"));
+ }
+
@Ignore("Performance test")
@Test
public void performance_getPreviousIdFor() {