jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1528529 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/segment/ test/java/org/apache/jackrabbit/oak/plugins/segment/
Date Wed, 02 Oct 2013 16:00:03 GMT
Author: jukka
Date: Wed Oct  2 16:00:03 2013
New Revision: 1528529

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

Return MapEntry instead of RecordId from MapRecord.getEntry(String) so that we can keep the
correct Segment reference along with the return value

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/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/SegmentNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/RecordTest.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=1528529&r1=1528528&r2=1528529&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
Wed Oct  2 16:00:03 2013
@@ -64,7 +64,7 @@ class MapBranch extends MapRecord {
     }
 
     @Override
-    RecordId getEntry(String key) {
+    MapEntry getEntry(String key) {
         checkNotNull(key);
 
         int mask = BUCKETS_PER_LEVEL - 1;

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=1528529&r1=1528528&r2=1528529&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
Wed Oct  2 16:00:03 2013
@@ -36,7 +36,7 @@ class MapLeaf extends MapRecord {
     }
 
     @Override
-    RecordId getEntry(String key) {
+    MapEntry getEntry(String key) {
         if (size == 0) {
             return null;
         }
@@ -44,16 +44,18 @@ class MapLeaf extends MapRecord {
         Segment segment = getSegment();
         int hash = checkNotNull(key).hashCode();
 
-        for (int i = 0; i < size; i++) {
-            int d = Integer.compare(segment.readInt(getOffset(4 + i * 4)), hash);
-            if (d == 0) {
-                RecordId id = segment.readRecordId(getOffset(4 + size * 4, i));
-                d = segment.readString(id).compareTo(key);
-            }
+        int d = -1;
+        for (int i = 0; i < size && d < 0; i++) {
+            d = Integer.compare(segment.readInt(getOffset(4 + i * 4)), hash);
             if (d == 0) {
-                return segment.readRecordId(getOffset(4 + size * 4, size + i));
-            } else if (d > 0) {
-                return null;
+                RecordId keyId = segment.readRecordId(
+                        getOffset(4 + size * 4, i));
+                d = segment.readString(keyId).compareTo(key);
+                if (d == 0) {
+                    RecordId valueId = segment.readRecordId(
+                            getOffset(4 + size * 4, size + i));
+                    return new MapEntry(segment, key, keyId, valueId);
+                }
             }
         }
 

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=1528529&r1=1528528&r2=1528529&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
Wed Oct  2 16:00:03 2013
@@ -78,7 +78,7 @@ abstract class MapRecord extends Record 
         return size;
     }
 
-    abstract RecordId getEntry(String key);
+    abstract MapEntry getEntry(String key);
 
     abstract Iterable<String> getKeys();
 
@@ -103,14 +103,13 @@ abstract class MapRecord extends Record 
         Set<String> keys = newHashSet();
         for (MapEntry entry : getEntries()) {
             String name = entry.getName();
-            RecordId thisId = entry.getValue();
-            RecordId thatId = that.getEntry(name);
-            if (thatId == null) {
-                if (!diff.entryAdded(name, thisId)) {
+            MapEntry thatEntry = that.getEntry(name);
+            if (thatEntry == null) {
+                if (!diff.entryAdded(name, entry.getValue())) {
                     return false;
                 }
-            } else if (!thisId.equals(thatId)) {
-                if (!diff.entryChanged(name, thatId, thisId)) {
+            } else if (!entry.getValue().equals(thatEntry.getValue())) {
+                if (!diff.entryChanged(name, thatEntry.getValue(), entry.getValue())) {
                     return false;
                 }
             }

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=1528529&r1=1528528&r2=1528529&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 Oct  2 16:00:03 2013
@@ -222,9 +222,9 @@ public class SegmentNodeState extends Re
         if (childName == Template.ZERO_CHILD_NODES) {
             return MISSING_NODE;
         } else if (childName == Template.MANY_CHILD_NODES) {
-            RecordId childNodeId = getChildNodeMap().getEntry(name);
-            if (childNodeId != null) {
-                return new SegmentNodeState(getSegment(), childNodeId);
+            MapEntry child = getChildNodeMap().getEntry(name);
+            if (child != null) {
+                return child.getNodeState();
             } else {
                 return MISSING_NODE;
             }

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=1528529&r1=1528528&r2=1528529&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 Oct  2 16:00:03 2013
@@ -188,9 +188,9 @@ public class Template {
             return MISSING_NODE;
         } else if (childName == MANY_CHILD_NODES) {
             MapRecord map = getChildNodeMap(segment, recordId);
-            RecordId childNodeId = map.getEntry(name);
-            if (childNodeId != null) {
-                return new SegmentNodeState(segment, childNodeId);
+            MapEntry child = map.getEntry(name);
+            if (child != null) {
+                return child.getNodeState();
             } else {
                 return MISSING_NODE;
             }
@@ -253,13 +253,10 @@ public class Template {
                 // TODO: can this be optimized?
                 for (MapEntry entry : thisMap.getEntries()) {
                     String name = entry.getName();
-                    RecordId thisChild = entry.getValue();
-                    RecordId thatChild = thatMap.getEntry(name);
-                    if (thatChild == null) {
+                    MapEntry thatEntry = thatMap.getEntry(name);
+                    if (thatEntry == null) {
                         return false;
-                    } else if (!thisChild.equals(thatChild)
-                            && !new SegmentNodeState(thisSegment, thisChild).equals(
-                                    new SegmentNodeState(thatSegment, thatChild))) {
+                    } else if (!entry.getNodeState().equals(thatEntry.getNodeState())) {
                         return false;
                     }
                 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/RecordTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/RecordTest.java?rev=1528529&r1=1528528&r2=1528529&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/RecordTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/RecordTest.java
Wed Oct  2 16:00:03 2013
@@ -190,7 +190,7 @@ public class RecordTest {
         assertFalse(iterator.hasNext());
 
         assertEquals(1, one.size());
-        assertEquals(blockId, one.getEntry("one"));
+        assertEquals(blockId, one.getEntry("one").getValue());
         assertNull(one.getEntry("two"));
         iterator = one.getEntries().iterator();
         assertTrue(iterator.hasNext());
@@ -198,8 +198,8 @@ public class RecordTest {
         assertFalse(iterator.hasNext());
 
         assertEquals(2, two.size());
-        assertEquals(blockId, two.getEntry("one"));
-        assertEquals(blockId, two.getEntry("two"));
+        assertEquals(blockId, two.getEntry("one").getValue());
+        assertEquals(blockId, two.getEntry("two").getValue());
         assertNull(two.getEntry("three"));
         iterator = two.getEntries().iterator();
         assertTrue(iterator.hasNext());
@@ -213,7 +213,7 @@ public class RecordTest {
         for (int i = 0; i < 1000; i++) {
             assertTrue(iterator.hasNext());
             assertEquals(blockId, iterator.next().getValue());
-            assertEquals(blockId, many.getEntry("key" + i));
+            assertEquals(blockId, many.getEntry("key" + i).getValue());
         }
         assertFalse(iterator.hasNext());
         assertNull(many.getEntry("foo"));
@@ -227,7 +227,7 @@ public class RecordTest {
         for (int i = 1; i <= 1000; i++) {
             assertTrue(iterator.hasNext());
             assertEquals(blockId, iterator.next().getValue());
-            assertEquals(blockId, modified.getEntry("key" + i));
+            assertEquals(blockId, modified.getEntry("key" + i).getValue());
         }
         assertFalse(iterator.hasNext());
         assertNull(many.getEntry("foo"));



Mime
View raw message