jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1449760 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: MemoryStore.java MongoStore.java Segment.java SegmentWriter.java
Date Mon, 25 Feb 2013 16:09:05 GMT
Author: jukka
Date: Mon Feb 25 16:09:05 2013
New Revision: 1449760

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

Use a LinkedHashMap instead of an array of UUIDs to speed up segment identifier lookups in
SegmentWriter.prepare()

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryStore.java?rev=1449760&r1=1449759&r2=1449760&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryStore.java
Mon Feb 25 16:09:05 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.segment;
 
+import java.util.Collections;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentMap;
 
@@ -80,7 +81,7 @@ public class MemoryStore implements Segm
             UUID segmentId, byte[] data, int offset, int length) {
         byte[] segment = new byte[length];
         System.arraycopy(data, offset, segment, 0, length);
-        createSegment(new Segment(this, segmentId, segment, new UUID[0]));
+        createSegment(new Segment(this, segmentId, segment, Collections.<UUID>emptySet()));
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.java?rev=1449760&r1=1449759&r2=1449760&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.java
Mon Feb 25 16:09:05 2013
@@ -117,9 +117,9 @@ public class MongoStore implements Segme
 
         byte[] data = (byte[]) segment.get("data");
         List<?> list = (List<?>) segment.get("uuids");
-        UUID[] uuids = new UUID[list.size()];
-        for (int i = 0; i < uuids.length; i++) {
-            uuids[i] = UUID.fromString(list.get(i).toString());
+        List<UUID> uuids = Lists.newArrayListWithCapacity(list.size());
+        for (Object object : list) {
+            uuids.add(UUID.fromString(object.toString()));
         }
         return new Segment(this, segmentId, data, uuids);
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java?rev=1449760&r1=1449759&r2=1449760&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java
Mon Feb 25 16:09:05 2013
@@ -22,6 +22,7 @@ import static com.google.common.base.Pre
 import static org.apache.jackrabbit.oak.plugins.segment.SegmentWriter.BLOCK_SIZE;
 
 import java.nio.ByteBuffer;
+import java.util.Collection;
 import java.util.UUID;
 
 import com.google.common.base.Charsets;
@@ -125,11 +126,11 @@ class Segment {
         }
     };
 
-    Segment(SegmentStore store, UUID uuid, byte[] data, UUID[] uuids) {
+    Segment(SegmentStore store, UUID uuid, byte[] data, Collection<UUID> uuids) {
         this.store = store;
         this.uuid = uuid;
         this.data = data;
-        this.uuids = uuids;
+        this.uuids = uuids.toArray(new UUID[uuids.size()]);
     }
 
     public UUID getSegmentId() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java?rev=1449760&r1=1449759&r2=1449760&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
Mon Feb 25 16:09:05 2013
@@ -66,8 +66,12 @@ public class SegmentWriter {
 
     private UUID uuid = UUID.randomUUID();
 
-    private final List<UUID> uuids =
-            Lists.newArrayListWithCapacity(Segment.SEGMENT_REFERENCE_LIMIT);
+    /**
+     * Insertion-ordered map from the UUIDs of referenced segments to the
+     * respective single-byte UUID index values used when serializing
+     * record identifiers.
+     */
+    private final Map<UUID, Byte> uuids = Maps.newLinkedHashMap();
 
     /**
      * The segment write buffer, filled from the end to the beginning
@@ -104,8 +108,7 @@ public class SegmentWriter {
                 System.arraycopy(buffer, start, data, 0, data.length);
             }
 
-            store.createSegment(new Segment(
-                    store, uuid, data, uuids.toArray(new UUID[uuids.size()])));
+            store.createSegment(new Segment(store, uuid, data, uuids.keySet()));
 
             uuid = UUID.randomUUID();
             length = 0;
@@ -123,7 +126,7 @@ public class SegmentWriter {
         Set<UUID> segmentIds = new HashSet<UUID>();
         for (RecordId id : checkNotNull(ids)) {
             UUID segmentId = id.getSegmentId();
-            if (!uuids.contains(segmentId)) {
+            if (!uuids.containsKey(segmentId)) {
                 segmentIds.add(segmentId);
             }
         }
@@ -147,18 +150,18 @@ public class SegmentWriter {
         checkNotNull(id);
 
         UUID segmentId = id.getSegmentId();
-        int index = uuids.indexOf(segmentId);
-        if (index == -1) {
-            index = uuids.size();
-            uuids.add(segmentId);
+        Byte segmentIndex = uuids.get(segmentId);
+        if (segmentIndex == null) {
+            checkState(uuids.size() < Segment.SEGMENT_REFERENCE_LIMIT);
+            segmentIndex = Byte.valueOf((byte) uuids.size());
+            uuids.put(segmentId, segmentIndex);
         }
-        int offset = id.getOffset();
 
-        checkState(index < Segment.SEGMENT_REFERENCE_LIMIT);
+        int offset = id.getOffset();
         checkState(0 <= offset && offset < buffer.length);
         checkState((offset & (Segment.RECORD_ALIGN_BYTES - 1)) == 0);
 
-        buffer[position++] = (byte) index;
+        buffer[position++] = segmentIndex.byteValue();
         buffer[position++] = (byte) (offset >> (8 + Segment.RECORD_ALIGN_BITS));
         buffer[position++] = (byte) (offset >> Segment.RECORD_ALIGN_BITS);
     }



Mime
View raw message