jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1444612 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: SegmentNodeState.java SegmentReader.java SegmentStream.java SegmentWriter.java
Date Sun, 10 Feb 2013 20:45:54 GMT
Author: jukka
Date: Sun Feb 10 20:45:54 2013
New Revision: 1444612

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

Keep the RecordId available for SegmentNodeStates and SegmentStreams so we can avoid storing
duplicate copies of records that already exist.
Also fix MapEntry comparison code.

Modified:
    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/SegmentReader.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStream.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/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=1444612&r1=1444611&r2=1444612&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
Sun Feb 10 20:45:54 2013
@@ -36,16 +36,25 @@ import com.google.common.collect.Iterabl
 
 class SegmentNodeState extends AbstractNodeState {
 
+    public static RecordId getRecordIdIfAvailable(NodeState state) {
+        if (state instanceof SegmentNodeState) {
+            SegmentNodeState sstate = (SegmentNodeState) state;
+            return sstate.recordId;
+        }
+        return null;
+    }
+
     private final SegmentReader reader;
 
+    private final RecordId recordId;
+
     private final MapRecord properties;
 
     private final MapRecord childNodes;
 
     SegmentNodeState(SegmentReader reader, RecordId id) {
         this.reader = checkNotNull(reader);
-
-        checkNotNull(id);
+        this.recordId = checkNotNull(id);
         this.properties = new MapRecord(reader.readRecordId(id, 0));
         this.childNodes = new MapRecord(reader.readRecordId(id, 4));
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentReader.java?rev=1444612&r1=1444611&r2=1444612&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentReader.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentReader.java
Sun Feb 10 20:45:54 2013
@@ -58,7 +58,7 @@ public class SegmentReader {
         int size = (int) ((length + BLOCK_SIZE - 1) / BLOCK_SIZE);
         ListRecord list =
             new ListRecord(segment.readRecordId(offset + 8), size);
-        return new SegmentStream(this, list, length);
+        return new SegmentStream(this, recordId, list, length);
     }
 
     public int readInt(RecordId recordId, int position) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStream.java?rev=1444612&r1=1444611&r2=1444612&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStream.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStream.java
Sun Feb 10 20:45:54 2013
@@ -16,16 +16,33 @@
  */
 package org.apache.jackrabbit.oak.plugins.segment;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkPositionIndexes;
 import static org.apache.jackrabbit.oak.plugins.segment.SegmentWriter.BLOCK_SIZE;
 
 import java.io.InputStream;
 
+import javax.annotation.CheckForNull;
+
 public class SegmentStream extends InputStream {
 
+    @CheckForNull
+    public static RecordId getRecordIdIfAvailable(InputStream stream) {
+        if (stream instanceof SegmentStream) {
+            SegmentStream sstream = (SegmentStream) stream;
+            if (sstream.position == 0) {
+                return sstream.recordId;
+            }
+        }
+        return null;
+    }
+
+
     private final SegmentReader reader;
 
+    private final RecordId recordId;
+
     private final ListRecord blocks;
 
     private final long length;
@@ -34,9 +51,13 @@ public class SegmentStream extends Input
 
     private long mark = 0;
 
-    SegmentStream(SegmentReader reader, ListRecord blocks, long length) {
-        this.reader = reader;
-        this.blocks = blocks;
+    SegmentStream(
+            SegmentReader reader, RecordId recordId,
+            ListRecord blocks, long length) {
+        this.reader = checkNotNull(reader);
+        this.recordId = checkNotNull(recordId);
+        this.blocks = checkNotNull(blocks);
+        checkArgument(length >= 0);
         this.length = length;
     }
 

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=1444612&r1=1444611&r2=1444612&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
Sun Feb 10 20:45:54 2013
@@ -167,7 +167,7 @@ public class SegmentWriter {
 
         @Override
         public int compareTo(MapEntry that) {
-            int diff = hashCode - that.hashCode;
+            int diff = Integer.compare(hashCode, that.hashCode);
             if (diff == 0) {
                 diff = key.compareTo(that.key);
             }
@@ -346,6 +346,11 @@ public class SegmentWriter {
      * @throws IOException if the stream could not be read
      */
     public RecordId writeStream(InputStream stream) throws IOException {
+        RecordId id = SegmentStream.getRecordIdIfAvailable(stream);
+        if (id != null) {
+            return id;
+        }
+
         try {
             List<RecordId> blockIds = new ArrayList<RecordId>();
 
@@ -414,6 +419,11 @@ public class SegmentWriter {
     }
 
     public RecordId writeNode(NodeState state) {
+        RecordId nodeId = SegmentNodeState.getRecordIdIfAvailable(state);
+        if (nodeId != null) {
+            return nodeId;
+        }
+
         Map<String, RecordId> childNodes = Maps.newHashMap();
         for (ChildNodeEntry entry : state.getChildNodeEntries()) {
             childNodes.put(entry.getName(), writeNode(entry.getNodeState()));



Mime
View raw message