jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1581719 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/segment/ main/java/org/apache/jackrabbit/oak/plugins/segment/file/ test/java/org/apache/jackrabbit/oak/plugins/segment/
Date Wed, 26 Mar 2014 07:57:26 GMT
Author: chetanm
Date: Wed Mar 26 07:57:25 2014
New Revision: 1581719

URL: http://svn.apache.org/r1581719
Log:
OAK-1604 - Support for signed references in Blob (WIP)

Update SegmentNodeStore to properly handle references
-- Distinguish between Segment notion of 'reference' which refers to any
   externally stored blob vs Blob#reference which refers to a 'secure reference'
-- Use blobId where raw blobid is required like in ReferenceCollector

Modified:
    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/SegmentBlob.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/SegmentWriter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/ExternalBlobTest.java

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=1581719&r1=1581718&r2=1581719&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
Wed Mar 26 07:57:25 2014
@@ -229,7 +229,7 @@ public class Segment {
         for (int i = 0; i < blobrefcount; i++) {
             int offset = (data.getShort(blobrefpos + i * 2) & 0xffff) << 2;
             SegmentBlob blob = new SegmentBlob(new RecordId(id, offset));
-            collector.addReference(blob.getReference());
+            collector.addReference(blob.getBlobId());
         }
     }
 

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=1581719&r1=1581718&r2=1581719&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 Mar 26 07:57:25 2014
@@ -26,6 +26,7 @@ import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.plugins.memory.AbstractBlob;
+import org.apache.jackrabbit.oak.spi.blob.BlobStore;
 
 import java.io.InputStream;
 
@@ -102,8 +103,24 @@ class SegmentBlob extends Record impleme
         }
     }
 
-    @Override @CheckForNull
+    @Override
+    @CheckForNull
     public String getReference() {
+        String blobId = getBlobId();
+        if (blobId != null) {
+            BlobStore blobStore = getSegment().getSegmentId().getTracker().
+                    getStore().getBlobStore();
+            if (blobStore != null) {
+                return blobStore.getReference(blobId);
+            }else{
+                throw new IllegalStateException("Attempt to read external blob with blobId
[" + blobId + "] " +
+                        "without specifying BlobStore");
+            }
+        }
+        return null;
+    }
+
+    public String getBlobId() {
         Segment segment = getSegment();
         int offset = getOffset();
         byte head = segment.readByte(offset);

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=1581719&r1=1581718&r2=1581719&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 Mar 26 07:57:25 2014
@@ -39,6 +39,7 @@ import javax.annotation.Nullable;
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.plugins.segment.memory.MemoryStore;
+import org.apache.jackrabbit.oak.spi.blob.BlobStore;
 import org.apache.jackrabbit.oak.spi.commit.ChangeDispatcher;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
@@ -176,7 +177,20 @@ public class SegmentNodeStore implements
 
     @Override
     public Blob getBlob(@Nonnull String reference) {
-        return store.readBlob(reference);
+        //Use of 'reference' here is bit overloaded. In terms of NodeStore API
+        //a blob reference refers to the secure reference obtained from Blob#getReference()
+        //However in SegmentStore terminology a blob is referred via 'external reference'
+        //That 'external reference' would map to blobId obtained from BlobStore#getBlobId
+        BlobStore blobStore = store.getBlobStore();
+        if (blobStore != null) {
+            String blobId = blobStore.getBlobId(reference);
+            if (blobId != null) {
+                return store.readBlob(blobId);
+            }
+            return null;
+        }
+        throw new IllegalStateException("Attempt to read external blob with blobId [" + reference
+ "] " +
+                "without specifying BlobStore");
     }
 
     @Override @Nonnull

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=1581719&r1=1581718&r2=1581719&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
Wed Mar 26 07:57:25 2014
@@ -68,6 +68,8 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.io.ByteStreams;
 import com.google.common.io.Closeables;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class SegmentWriter {
 
@@ -97,6 +99,8 @@ public class SegmentWriter {
 
     private final SegmentStore store;
 
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
     /**
      * Cache of recently stored string and template records, used to
      * avoid storing duplicates of frequently occurring data.
@@ -687,9 +691,14 @@ public class SegmentWriter {
         }
 
         String reference = blob.getReference();
-        if (reference != null) {
-            RecordId id = writeValueRecord(reference);
-            return new SegmentBlob(id);
+        if (reference != null && store.getBlobStore() != null) {
+            String blobId = store.getBlobStore().getBlobId(reference);
+            if(blobId != null) {
+                RecordId id = writeValueRecord(blobId);
+                return new SegmentBlob(id);
+            }else{
+                log.debug("No blobId found matching reference [{}]", reference);
+            }
         }
 
         return writeStream(blob.getNewStream());

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java?rev=1581719&r1=1581718&r2=1581719&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
Wed Mar 26 07:57:25 2014
@@ -399,11 +399,11 @@ public class FileStore implements Segmen
     }
 
     @Override
-    public Blob readBlob(String reference) {
-        if(blobStore != null){
-            return new BlobStoreBlob(blobStore, reference);
+    public Blob readBlob(String blobId) {
+        if (blobStore != null) {
+            return new BlobStoreBlob(blobStore, blobId);
         }
-        throw new IllegalStateException("Attempt to read external reference ["+reference+"]
" +
+        throw new IllegalStateException("Attempt to read external blob with blobId [" + blobId
+ "] " +
                 "without specifying BlobStore");
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/ExternalBlobTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/ExternalBlobTest.java?rev=1581719&r1=1581718&r2=1581719&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/ExternalBlobTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/ExternalBlobTest.java
Wed Mar 26 07:57:25 2014
@@ -69,14 +69,15 @@ public class ExternalBlobTest {
         new Random().nextBytes(data);
         Blob b1 = testCreateAndRead(nodeStore.createBlob(new ByteArrayInputStream(data)));
         assertTrue(b1 instanceof SegmentBlob);
-        assertNull(b1.getReference());
+        assertNull(((SegmentBlob) b1).getBlobId());
 
         //Test for Blob which need to be pushed to BlobStore
         byte[] data2 = new byte[Segment.MEDIUM_LIMIT + 1];
         new Random().nextBytes(data2);
         Blob b2 = testCreateAndRead(nodeStore.createBlob(new ByteArrayInputStream(data2)));
+        assertTrue(b2 instanceof SegmentBlob);
         assertNotNull(b2.getReference());
-        assertNotNull(dbs.getRecordIfStored(new DataIdentifier(b2.getReference())));
+        assertNotNull(dbs.getRecordIfStored(new DataIdentifier(((SegmentBlob) b2).getBlobId())));
     }
 
     public Blob testCreateAndRead(Blob blob) throws Exception {
@@ -156,5 +157,15 @@ public class ExternalBlobTest {
             }
             return null;
         }
+
+        @Override
+        public String getBlobId(String reference) {
+            return reference;
+        }
+
+        @Override
+        public String getReference(String blobId) {
+            return blobId;
+        }
     }
 }



Mime
View raw message