jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1464564 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java test/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategyTest.java
Date Thu, 04 Apr 2013 14:16:43 GMT
Author: alexparvulescu
Date: Thu Apr  4 14:16:43 2013
New Revision: 1464564

URL: http://svn.apache.org/r1464564
Log:
OAK-748 ContentMirrorStoreStrategy fails to enforce uniqueness and is slow

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategyTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java?rev=1464564&r1=1464563&r2=1464564&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
Thu Apr  4 14:16:43 2013
@@ -42,7 +42,26 @@ import com.google.common.collect.Queues;
 import com.google.common.collect.Sets;
 
 /**
- * TODO document
+ * An IndexStoreStrategy implementation that saves the nodes under a hierarchy
+ * that mirrors the repository tree. <br>
+ * This should minimize the chance that concurrent updates overlap on the same
+ * content node.<br>
+ * <br>
+ * For example for a node that is under <code>/test/node</code>, the index
+ * structure will be <code>/oak:index/index/test/node</code>:
+ * 
+ * <pre>
+ * <code>
+ * /
+ *   test
+ *     node
+ *   oak:index
+ *     index
+ *       test
+ *         node
+ * </code>
+ * </pre>
+ * 
  */
 public class ContentMirrorStoreStrategy implements IndexStoreStrategy {
 
@@ -118,6 +137,12 @@ public class ContentMirrorStoreStrategy 
     public void insert(NodeBuilder index, String key, boolean unique,
             Iterable<String> values) throws CommitFailedException {
         NodeBuilder child = index.child(key);
+        if (unique
+                && (child.getProperty("match") != null || child
+                        .getChildNodeCount() > 0)) {
+            throw new CommitFailedException(
+                    "Uniqueness constraint violated for key " + key);
+        }
 
         for (String add : values) {
             NodeBuilder indexEntry = child;
@@ -126,16 +151,8 @@ public class ContentMirrorStoreStrategy 
             }
             indexEntry.setProperty("match", true);
         }
-        CountingNodeVisitor v = new CountingNodeVisitor(2);
-        v.visit(child.getNodeState());
-        int matchCount = v.getCount();
-        if (matchCount == 0) {
-            index.removeNode(key);
-        } else if (unique && matchCount > 1) {
-            throw new CommitFailedException("Uniqueness constraint violated for key " + key);
-        }
     }
-    
+
     @Override
     public Iterable<String> query(final Filter filter, final String indexName, 
             final NodeState index, final Iterable<String> values) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategyTest.java?rev=1464564&r1=1464563&r2=1464564&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategyTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategyTest.java
Thu Apr  4 14:16:43 2013
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
 
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 
+import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -111,4 +112,18 @@ public class ContentMirrorStoreStrategyT
         Assert.assertFalse(check.hasChildNode(name));
     }
 
+    @Test
+    public void testUnique() {
+        IndexStoreStrategy store = new ContentMirrorStoreStrategy();
+        NodeState root = EMPTY_NODE;
+        NodeBuilder index = root.builder();
+        try {
+            store.insert(index, "key", true, Sets.newHashSet("a"));
+            store.insert(index, "key", true, Sets.newHashSet("a"));
+            Assert.fail("ContentMirrorStoreStrategy should guarantee uniqueness on insert");
+        } catch (CommitFailedException e) {
+            // expected
+        }
+    }
+
 }



Mime
View raw message