jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1528702 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: MapBranch.java MapEntry.java MapLeaf.java MapRecord.java Template.java
Date Thu, 03 Oct 2013 02:17:46 GMT
Author: jukka
Date: Thu Oct  3 02:17:45 2013
New Revision: 1528702

URL: http://svn.apache.org/r1528702
Log:
OAK-1031: SegmentMK: Fewer segment lookups

Pass MapEntries to MapDiff in order to keep the local segment reference along with the raw
record identifiers

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapBranch.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapEntry.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapLeaf.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapRecord.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/MapBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapBranch.java?rev=1528702&r1=1528701&r2=1528702&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapBranch.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapBranch.java
Thu Oct  3 02:17:45 2013
@@ -139,7 +139,7 @@ class MapBranch extends MapRecord {
                 if (beforeBuckets[i] != null) {
                     MapRecord map = beforeSegment.readMap(beforeBuckets[i]);
                     for (MapEntry entry : map.getEntries()) {
-                        if (!diff.entryDeleted(entry.getName(), entry.getValue())) {
+                        if (!diff.entryDeleted(entry)) {
                             return false;
                         }
                     }
@@ -147,7 +147,7 @@ class MapBranch extends MapRecord {
             } else if (beforeBuckets[i] == null) {
                 MapRecord map = afterSegment.readMap(afterBuckets[i]);
                 for (MapEntry entry : map.getEntries()) {
-                    if (!diff.entryAdded(entry.getName(), entry.getValue())) {
+                    if (!diff.entryAdded(entry)) {
                         return false;
                     }
                 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapEntry.java?rev=1528702&r1=1528701&r2=1528702&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapEntry.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapEntry.java
Thu Oct  3 02:17:45 2013
@@ -24,7 +24,6 @@ import java.util.Map;
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.spi.state.AbstractChildNodeEntry;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 import com.google.common.collect.ComparisonChain;
 
@@ -61,7 +60,7 @@ class MapEntry extends AbstractChildNode
     }
 
     @Override @Nonnull
-    public NodeState getNodeState() {
+    public SegmentNodeState getNodeState() {
         checkState(value != null);
         return new SegmentNodeState(segment, value);
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapLeaf.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapLeaf.java?rev=1528702&r1=1528701&r2=1528702&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapLeaf.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapLeaf.java
Thu Oct  3 02:17:45 2013
@@ -127,8 +127,7 @@ class MapLeaf extends MapRecord {
                     && (before.getHash(bs, bi) < afterHash
                         || (before.getHash(bs, bi) == afterHash
                             && before.getKey(bs, bi).compareTo(afterKey) < 0)))
{
-                if (!diff.entryDeleted(
-                        before.getKey(bs, bi), before.getValue(bs, bi))) {
+                if (!diff.entryDeleted(before.getEntry(bs, bi))) {
                     return false;
                 }
                 bi++;
@@ -139,11 +138,13 @@ class MapLeaf extends MapRecord {
                     && before.getKey(bs, bi).equals(afterKey)) {
                 RecordId beforeValue = before.getValue(bs, bi);
                 if (!afterValue.equals(beforeValue)
-                        && !diff.entryChanged(afterKey, beforeValue, afterValue))
{
+                        && !diff.entryChanged(
+                                before.getEntry(bs, bi),
+                                after.getEntry(as, ai))) {
                     return false;
                 }
                 bi++;
-            } else if (!diff.entryAdded(afterKey, afterValue)) {
+            } else if (!diff.entryAdded(after.getEntry(as, ai))) {
                 return false;
             }
 
@@ -151,8 +152,7 @@ class MapLeaf extends MapRecord {
         }
 
         while (bi < before.size) {
-            if (!diff.entryDeleted(
-                    before.getKey(bs, bi), before.getValue(bs, bi))) {
+            if (!diff.entryDeleted(before.getEntry(bs, bi))) {
                 return false;
             }
             bi++;
@@ -163,6 +163,15 @@ class MapLeaf extends MapRecord {
 
     //-----------------------------------------------------------< private >--
 
+    private MapEntry getEntry(Segment segment, int index) {
+        checkNotNull(segment);
+        RecordId key =
+                segment.readRecordId(getOffset(4 + size * 4, index));
+        RecordId value =
+                segment.readRecordId(getOffset(4 + size * 4, size + index));
+        return new MapEntry(segment, segment.readString(key), key, value);
+    }
+
     private int getHash(Segment segment, int index) {
         return checkNotNull(segment).readInt(getOffset() + 4 + index * 4);
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapRecord.java?rev=1528702&r1=1528701&r2=1528702&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapRecord.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapRecord.java
Thu Oct  3 02:17:45 2013
@@ -86,7 +86,7 @@ abstract class MapRecord extends Record 
 
     boolean compareAgainstEmptyMap(MapDiff diff) {
         for (MapEntry entry : getEntries()) {
-            if (!diff.entryAdded(entry.getName(), entry.getValue())) {
+            if (!diff.entryAdded(entry)) {
                 return false;
             }
         }
@@ -94,9 +94,9 @@ abstract class MapRecord extends Record 
     }
 
     interface MapDiff {
-        boolean entryAdded(String key, RecordId after);
-        boolean entryChanged(String key, RecordId before, RecordId after);
-        boolean entryDeleted(String key, RecordId before);
+        boolean entryAdded(MapEntry after);
+        boolean entryChanged(MapEntry before, MapEntry after);
+        boolean entryDeleted(MapEntry before);
     }
 
     boolean compare(MapRecord that, MapDiff diff) {
@@ -105,11 +105,11 @@ abstract class MapRecord extends Record 
             String name = entry.getName();
             MapEntry thatEntry = that.getEntry(name);
             if (thatEntry == null) {
-                if (!diff.entryAdded(name, entry.getValue())) {
+                if (!diff.entryAdded(entry)) {
                     return false;
                 }
             } else if (!entry.getValue().equals(thatEntry.getValue())) {
-                if (!diff.entryChanged(name, thatEntry.getValue(), entry.getValue())) {
+                if (!diff.entryChanged(thatEntry, entry)) {
                     return false;
                 }
             }
@@ -118,7 +118,7 @@ abstract class MapRecord extends Record 
         for (MapEntry entry : that.getEntries()) {
             String name = entry.getName();
             if (!keys.contains(name)) {
-                if (!diff.entryDeleted(name, entry.getValue())) {
+                if (!diff.entryDeleted(entry)) {
                     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=1528702&r1=1528701&r2=1528702&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 Oct  3 02:17:45 2013
@@ -396,21 +396,21 @@ public class Template {
             MapRecord beforeMap = beforeTemplate.getChildNodeMap(beforeSegment, beforeId);
             return afterMap.compare(beforeMap, new MapDiff() {
                 @Override
-                public boolean entryAdded(String key, RecordId after) {
+                public boolean entryAdded(MapEntry after) {
                     return diff.childNodeAdded(
-                            key, new SegmentNodeState(afterSegment, after));
+                            after.getName(), after.getNodeState());
                 }
                 @Override
-                public boolean entryChanged(
-                        String key, RecordId before, RecordId after) {
-                    SegmentNodeState b = new SegmentNodeState(beforeSegment, before);
-                    SegmentNodeState a = new SegmentNodeState(afterSegment, after);
-                    return fastEquals(a, b) || diff.childNodeChanged(key, b, a);
+                public boolean entryChanged(MapEntry before, MapEntry after) {
+                    SegmentNodeState b = before.getNodeState();
+                    SegmentNodeState a = after.getNodeState();
+                    return fastEquals(a, b)
+                            || diff.childNodeChanged(before.getName(), b, a);
                 }
                 @Override
-                public boolean entryDeleted(String key, RecordId before) {
+                public boolean entryDeleted(MapEntry before) {
                     return diff.childNodeDeleted(
-                            key, new SegmentNodeState(beforeSegment, before));
+                            before.getName(), before.getNodeState());
                 }
             });
         }
@@ -441,17 +441,16 @@ public class Template {
             final Segment s = segment;
             children.compareAgainstEmptyMap(new MapDiff() {
                 @Override
-                public boolean entryAdded(String key, RecordId after) {
+                public boolean entryAdded(MapEntry after) {
                     return diff.childNodeAdded(
-                            key, new SegmentNodeState(s, after));
+                            after.getName(), after.getNodeState());
                 }
                 @Override
-                public boolean entryChanged(
-                        String key, RecordId before, RecordId after) {
+                public boolean entryChanged(MapEntry before, MapEntry after) {
                     throw new IllegalStateException();
                 }
                 @Override
-                public boolean entryDeleted(String key, RecordId before) {
+                public boolean entryDeleted(MapEntry before) {
                     throw new IllegalStateException();
                 }
             });



Mime
View raw message