jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1504448 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/memory/ main/java/org/apache/jackrabbit/oak/plugins/segment/ main/java/org/apache/jackrabbit/oak/spi/commit/ main/java/org/apache/jackrabbit/oak/s...
Date Thu, 18 Jul 2013 12:14:36 GMT
Author: jukka
Date: Thu Jul 18 12:14:36 2013
New Revision: 1504448

URL: http://svn.apache.org/r1504448
Log:
OAK-914: Relax the NodeStateDiff.childNodeChanged() semantics

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/FailingValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateDiff.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompareAgainstBaseStateTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java?rev=1504448&r1=1504447&r2=1504448&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java
Thu Jul 18 12:14:36 2013
@@ -157,7 +157,7 @@ class MemoryNodeState extends AbstractNo
                 if (!diff.childNodeDeleted(name, before)) {
                     return false;
                 }
-            } else if (!after.equals(before)) {
+            } else if (after != before) {
                 if (!diff.childNodeChanged(name, before, after)) {
                     return false;
                 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java?rev=1504448&r1=1504447&r2=1504448&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
Thu Jul 18 12:14:36 2013
@@ -370,7 +370,7 @@ public class ModifiedNodeState extends A
                 if (!diff.childNodeAdded(name, after)) {
                     return false;
                 }
-            } else if (!before.equals(after)
+            } else if (before != after // TODO: fastEquals?
                     && !diff.childNodeChanged(name, before, after)) {
                 return false;
             }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java?rev=1504448&r1=1504447&r2=1504448&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
Thu Jul 18 12:14:36 2013
@@ -469,7 +469,7 @@ public class Template {
                 if (!diff.childNodeAdded(childName, afterNode)) {
                     return false;
                 }
-            } else if (!beforeNode.equals(afterNode)) {
+            } else if (!fastEquals(afterNode, beforeNode)) {
                 if (!diff.childNodeChanged(childName, beforeNode, afterNode)) {
                     return false;
                 }
@@ -502,7 +502,7 @@ public class Template {
                     NodeState beforeChild =
                             beforeTemplate.getChildNode(name, store, beforeId);
                     if (beforeChild.exists()) {
-                        if (!afterChild.equals(beforeChild)
+                        if (!fastEquals(afterChild, beforeChild)
                                 && !diff.childNodeChanged(
                                         childName, beforeChild, afterChild)) {
                             return false;
@@ -544,6 +544,18 @@ public class Template {
         return true;
     }
 
+    private boolean fastEquals(NodeState a, NodeState b) {
+        if (a == b) {
+            return true;
+        } else if (a instanceof SegmentNodeState
+                && b instanceof SegmentNodeState) {
+            return ((SegmentNodeState) a).getRecordId().equals(
+                    ((SegmentNodeState) b).getRecordId());
+        } else {
+            return false;
+        }
+    }
+
     private boolean compareProperties(
             PropertyState before, PropertyState after, NodeStateDiff diff) {
         if (before == null) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/FailingValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/FailingValidator.java?rev=1504448&r1=1504447&r2=1504448&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/FailingValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/FailingValidator.java
Thu Jul 18 12:14:36 2013
@@ -45,15 +45,11 @@ public class FailingValidator implements
     }
 
     @Override
-    public void enter(NodeState before, NodeState after)
-            throws CommitFailedException {
-        throw new CommitFailedException(type, code, message);
+    public void enter(NodeState before, NodeState after) {
     }
 
     @Override
-    public void leave(NodeState before, NodeState after)
-            throws CommitFailedException {
-        throw new CommitFailedException(type, code, message);
+    public void leave(NodeState before, NodeState after) {
     }
 
     @Override
@@ -82,9 +78,8 @@ public class FailingValidator implements
 
     @Override
     public Validator childNodeChanged(
-            String name, NodeState before, NodeState after)
-            throws CommitFailedException {
-        throw new CommitFailedException(type, code, message);
+            String name, NodeState before, NodeState after) {
+        return this; // the subtree might not have changed, so recurse
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java?rev=1504448&r1=1504447&r2=1504448&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java
Thu Jul 18 12:14:36 2013
@@ -162,7 +162,7 @@ public abstract class AbstractNodeState 
                 }
             } else {
                 baseChildNodes.add(name);
-                if (!beforeChild.equals(afterChild)) {
+                if (afterChild != beforeChild) { // TODO: fastEquals?
                     if (!diff.childNodeChanged(name, beforeChild, afterChild)) {
                         return false;
                     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateDiff.java?rev=1504448&r1=1504447&r2=1504448&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateDiff.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateDiff.java
Thu Jul 18 12:14:36 2013
@@ -80,7 +80,10 @@ public interface NodeStateDiff {
     boolean childNodeAdded(String name, NodeState after);
 
     /**
-     * Called for all changed child nodes.
+     * Called for all child nodes that may contain changes between the before
+     * and after states. The comparison implementation is expected to make an
+     * effort to avoid calling this method on child nodes under which nothing
+     * has changed.
      *
      * @param name name of the changed child node
      * @param before child node state before the change

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompareAgainstBaseStateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompareAgainstBaseStateTest.java?rev=1504448&r1=1504447&r2=1504448&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompareAgainstBaseStateTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompareAgainstBaseStateTest.java
Thu Jul 18 12:14:36 2013
@@ -41,7 +41,7 @@ public class CompareAgainstBaseStateTest
     private final NodeStateDiff diff =
             createControl().createMock("diff", NodeStateDiff.class);
 
-    private final NodeBuilder builder = EMPTY_NODE.builder();
+    private NodeBuilder builder = EMPTY_NODE.builder();
 
     @Before
     public void setUp() {
@@ -63,7 +63,7 @@ public class CompareAgainstBaseStateTest
     @Test
     public void testEqualState() {
         NodeState before = persist(builder);
-        NodeState after = persist(builder);
+        NodeState after = persist(before.builder());
 
         replay(diff);
 
@@ -74,6 +74,7 @@ public class CompareAgainstBaseStateTest
     @Test
     public void testPropertyAdded() {
         NodeState before = persist(builder);
+        builder = before.builder();
         builder.setProperty("test", "test");
         NodeState after = persist(builder);
 
@@ -87,6 +88,7 @@ public class CompareAgainstBaseStateTest
     @Test
     public void testPropertyChanged() {
         NodeState before = persist(builder);
+        builder = before.builder();
         builder.setProperty("foo", "test");
         NodeState after = persist(builder);
 
@@ -101,6 +103,7 @@ public class CompareAgainstBaseStateTest
     @Test
     public void testPropertyDeleted() {
         NodeState before = persist(builder);
+        builder = before.builder();
         builder.removeProperty("foo");
         NodeState after = persist(builder);
 
@@ -114,6 +117,7 @@ public class CompareAgainstBaseStateTest
     @Test
     public void testChildNodeAdded() {
         NodeState before = persist(builder);
+        builder = before.builder();
         builder.child("test");
         NodeState after = persist(builder);
 



Mime
View raw message