jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1547668 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: Record.java SegmentBlob.java SegmentNodeState.java SegmentNodeStore.java SegmentPropertyState.java Template.java
Date Wed, 04 Dec 2013 01:27:40 GMT
Author: jukka
Date: Wed Dec  4 01:27:40 2013
New Revision: 1547668

URL: http://svn.apache.org/r1547668
Log:
OAK-593: Segment-based MK

Generalize the fastEquals() method

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Record.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentBlob.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Record.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Record.java?rev=1547668&r1=1547667&r2=1547668&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Record.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Record.java
Wed Dec  4 01:27:40 2013
@@ -29,6 +29,18 @@ import javax.annotation.Nonnull;
  */
 class Record {
 
+    static boolean fastEquals(Object a, Object b) {
+        return a instanceof Record && fastEquals((Record) a, b);
+    }
+
+    static boolean fastEquals(Record a, Object b) {
+        return b instanceof Record && fastEquals(a, (Record) b);
+    }
+
+    static boolean fastEquals(Record a, Record b) {
+        return equal(a.uuid, b.uuid) && a.offset == b.offset;
+    }
+
     /**
      * The segment that contains this record, or initially some other segment
      * in the same store. The reference is lazily updated when the

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentBlob.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentBlob.java?rev=1547668&r1=1547667&r2=1547668&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentBlob.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentBlob.java
Wed Dec  4 01:27:40 2013
@@ -46,14 +46,12 @@ class SegmentBlob extends Record impleme
 
     @Override
     public boolean equals(Object object) {
-        if (object instanceof SegmentBlob) {
-            SegmentBlob that = (SegmentBlob) object;
-            if (getRecordId().equals(that.getRecordId())) {
-                return true;
-            }
+        if (object == this || fastEquals(this, object)) {
+            return true;
+        } else {
+            return object instanceof Blob
+                    && AbstractBlob.equal(this, (Blob) object);
         }
-        return object instanceof Blob
-                && AbstractBlob.equal(this, (Blob) object);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java?rev=1547668&r1=1547667&r2=1547668&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
Wed Dec  4 01:27:40 2013
@@ -270,17 +270,16 @@ public class SegmentNodeState extends Re
 
     @Override
     public boolean compareAgainstBaseState(NodeState base, NodeStateDiff diff) {
-        if (base == this) {
+        if (this == base || fastEquals(this, base)) {
              return true; // no changes
         } else if (base == EMPTY_NODE || !base.exists()) { // special case
             return getTemplate().compareAgainstEmptyState(
                     getSegment(), getRecordId(), diff);
         } else if (base instanceof SegmentNodeState) {
             SegmentNodeState that = (SegmentNodeState) base;
-            return getRecordId().equals(that.getRecordId())
-                || getTemplate().compareAgainstBaseState(
-                        getSegment(), getRecordId(), that.getTemplate(),
-                        that.getSegment(), that.getRecordId(), diff);
+            return getTemplate().compareAgainstBaseState(
+                    getSegment(), getRecordId(), that.getTemplate(),
+                    that.getSegment(), that.getRecordId(), diff);
         } else {
             // fallback
             return AbstractNodeState.compareAgainstBaseState(this, base, diff);
@@ -289,24 +288,18 @@ public class SegmentNodeState extends Re
 
     @Override
     public boolean equals(Object object) {
-        if (this == object) {
+        if (this == object || fastEquals(this, object)) {
             return true;
         } else if (object instanceof SegmentNodeState) {
             SegmentNodeState that = (SegmentNodeState) object;
-            if (getRecordId().equals(that.getRecordId())
-                    && getStore() == that.getStore()) {
-                return true;
-            } else {
-                Template template = getTemplate();
-                return template.equals(that.getTemplate())
-                        && template.compare(
-                                getSegment(), getRecordId(),
-                                that.getSegment(), that.getRecordId());
-            }
-        } else if (object instanceof NodeState){
-            return AbstractNodeState.equals(this, (NodeState) object); // TODO
+            Template template = getTemplate();
+            return template.equals(that.getTemplate())
+                    && template.compare(
+                            getSegment(), getRecordId(),
+                            that.getSegment(), that.getRecordId());
         } else {
-            return false;
+            return object instanceof NodeState
+                    && AbstractNodeState.equals(this, (NodeState) object); // TODO
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java?rev=1547668&r1=1547667&r2=1547668&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
Wed Dec  4 01:27:40 2013
@@ -16,13 +16,13 @@
  */
 package org.apache.jackrabbit.oak.plugins.segment;
 
-import static com.google.common.base.Objects.equal;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static java.lang.System.currentTimeMillis;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.NANOSECONDS;
 import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.jackrabbit.oak.plugins.segment.Record.fastEquals;
 
 import java.io.Closeable;
 import java.io.IOException;
@@ -355,16 +355,4 @@ public class SegmentNodeStore implements
 
     }
 
-    private static boolean fastEquals(Object a, Object b) {
-        return a instanceof Record && fastEquals((Record) a, b);
-    }
-
-    private static boolean fastEquals(Record a, Object b) {
-        return b instanceof Record && fastEquals(a, (Record) b);
-    }
-
-    private static boolean fastEquals(Record a, Record b) {
-        return equal(a.getRecordId(), b.getRecordId());
-    }
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java?rev=1547668&r1=1547667&r2=1547668&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java
Wed Dec  4 01:27:40 2013
@@ -193,7 +193,7 @@ class SegmentPropertyState extends Recor
     @Override
     public boolean equals(Object object) {
         // optimize for common cases
-        if (this == object) {
+        if (this == object) { // don't use fastEquals here due to value sharing
             return true;
         } else if (object instanceof SegmentPropertyState) {
             SegmentPropertyState that = (SegmentPropertyState) object;

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=1547668&r1=1547667&r2=1547668&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
Wed Dec  4 01:27:40 2013
@@ -20,6 +20,7 @@ import static com.google.common.base.Pre
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
+import static org.apache.jackrabbit.oak.plugins.segment.Record.fastEquals;
 import static org.apache.jackrabbit.oak.plugins.segment.Segment.RECORD_ID_BYTES;
 
 import java.util.Arrays;
@@ -245,7 +246,7 @@ public class Template {
             // TODO: Leverage the HAMT data structure for the comparison
             MapRecord thisMap = getChildNodeMap(thisSegment, thisId);
             MapRecord thatMap = getChildNodeMap(thatSegment, thatId);
-            if (thisMap.getRecordId().equals(thatMap.getRecordId())) {
+            if (fastEquals(thisMap, thatMap)) {
                 return true; // shortcut
             } else if (thisMap.size() != thatMap.size()) {
                 return false; // shortcut
@@ -474,18 +475,6 @@ public class Template {
     }
 
 
-    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) {



Mime
View raw message