jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1238307 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/blobs/ main/java/org/apache/jackrabbit/mk/mem/ test/java/org/apache/jackrabbit/mk/blobs/
Date Tue, 31 Jan 2012 09:18:14 GMT
Author: thomasm
Date: Tue Jan 31 09:18:14 2012
New Revision: 1238307

URL: http://svn.apache.org/viewvc?rev=1238307&view=rev
Log:
BlobStore.close(); MongoBlobStore

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/MongoBlobStore.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/MongoBlobStoreTest.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/BlobStore.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/FileBlobStoreTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/MemoryBlobStoreTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java?rev=1238307&r1=1238306&r2=1238307&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
Tue Jan 31 09:18:14 2012
@@ -168,7 +168,7 @@ public abstract class AbstractBlobStore 
         in.close();
     }
 
-    protected abstract void storeBlock(byte[] blockId, int level, byte[] data) throws Exception;
+    protected abstract void storeBlock(byte[] digest, int level, byte[] data) throws Exception;
 
     public int readBlob(String blobId, long pos, byte[] buff, int off, int length) {
         try {
@@ -271,6 +271,14 @@ public abstract class AbstractBlobStore 
         }
     }
 
+    public void close() {
+        // ignore
+    }
+
+    /**
+     * A block id. Blocks are small enough to fit in memory, so they can be
+     * cached.
+     */
     public static class BlockId {
 
         final byte[] digest;
@@ -301,6 +309,9 @@ public abstract class AbstractBlobStore 
 
     }
 
+    /**
+     * The data for a block.
+     */
     public static class Data implements Cache.Value {
 
         final byte[] data;
@@ -317,6 +328,7 @@ public abstract class AbstractBlobStore 
         public int getMemory() {
             return data.length;
         }
+
     }
 
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/BlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/BlobStore.java?rev=1238307&r1=1238306&r2=1238307&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/BlobStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/BlobStore.java
Tue Jan 31 09:18:14 2012
@@ -45,4 +45,7 @@ public interface BlobStore {
     int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws Exception;
 
     long getBlobLength(String blobId) throws Exception;
+
+    void close();
+
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java?rev=1238307&r1=1238306&r2=1238307&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java
Tue Jan 31 09:18:14 2012
@@ -47,8 +47,8 @@ public class FileBlobStore extends Abstr
         try {
             FilePath file = FilePath.get(tempFilePath);
             InputStream in = file.newInputStream();
-            MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM);
-            DigestInputStream din = new DigestInputStream(in, digest);
+            MessageDigest messageDigest = MessageDigest.getInstance(HASH_ALGORITHM);
+            DigestInputStream din = new DigestInputStream(in, messageDigest);
             long length = file.size();
             try {
                 while (true) {
@@ -64,8 +64,8 @@ public class FileBlobStore extends Abstr
             idStream.write(TYPE_HASH);
             IOUtils.writeVarInt(idStream, 0);
             IOUtils.writeVarLong(idStream, length);
-            byte[] blockId = digest.digest();
-            FilePath f = getFile(blockId);
+            byte[] digest = messageDigest.digest();
+            FilePath f = getFile(digest);
             if (f.exists()) {
                 file.delete();
             } else {
@@ -75,8 +75,8 @@ public class FileBlobStore extends Abstr
                 }
                 file.moveTo(f);
             }
-            IOUtils.writeVarInt(idStream, blockId.length);
-            idStream.write(blockId);
+            IOUtils.writeVarInt(idStream, digest.length);
+            idStream.write(digest);
             byte[] id = idStream.toByteArray();
             return StringUtils.convertBytesToHex(id);
         } catch (Exception e) {
@@ -101,8 +101,8 @@ public class FileBlobStore extends Abstr
         temp.moveTo(f);
     }
 
-    private FilePath getFile(byte[] blockId) {
-        String id = StringUtils.convertBytesToHex(blockId);
+    private FilePath getFile(byte[] digest) {
+        String id = StringUtils.convertBytesToHex(digest);
         String sub = id.substring(id.length() - 2);
         return baseDir.resolve(sub).resolve(id + ".dat");
     }

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/MongoBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/MongoBlobStore.java?rev=1238307&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/MongoBlobStore.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/MongoBlobStore.java
Tue Jan 31 09:18:14 2012
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.blobs;
+
+import java.io.IOException;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.Mongo;
+import com.mongodb.MongoException;
+import com.mongodb.WriteConcern;
+
+/**
+ * A blob store that uses MongoDB.
+ */
+public class MongoBlobStore extends AbstractBlobStore {
+
+    private static final String DB = "ds";
+    private static final String DATASTORE_COLLECTION = "dataStore";
+    private static final String DIGEST_FIELD = "digest";
+    private static final String DATA_FIELD = "data";
+
+    private Mongo con;
+    private DB db;
+    private DBCollection dataStore;
+
+    public MongoBlobStore() throws IOException {
+        con = new Mongo();
+        db = con.getDB(DB);
+        db.setWriteConcern(WriteConcern.SAFE);
+        dataStore = db.getCollection(DATASTORE_COLLECTION);
+        dataStore.ensureIndex(
+                new BasicDBObject(DIGEST_FIELD, 1),
+                new BasicDBObject("unique", true));
+    }
+
+    @Override
+    protected byte[] readBlockFromBackend(BlockId id) {
+        BasicDBObject key = new BasicDBObject(DIGEST_FIELD, id.digest);
+        DBObject dataObject = dataStore.findOne(key);
+        return (byte[]) dataObject.get(DATA_FIELD);
+    }
+
+    @Override
+    protected void storeBlock(byte[] digest, int level, byte[] data) {
+        BasicDBObject dataObject = new BasicDBObject(DIGEST_FIELD, digest);
+        dataObject.append(DATA_FIELD, data);
+        try {
+            dataStore.insert(dataObject);
+        } catch (MongoException.DuplicateKey ignore) {
+            // ignore
+        }
+    }
+
+    @Override
+    public void close() {
+        con.close();
+    }
+
+}

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java?rev=1238307&r1=1238306&r2=1238307&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
Tue Jan 31 09:18:14 2012
@@ -586,6 +586,7 @@ public class MemoryKernelImpl extends Wr
             disposed = true;
             gate.commit("end");
             nodeMap.close();
+            ds.close();
             INSTANCES.remove(name);
             if (server != null) {
                 server.stop();

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java?rev=1238307&r1=1238306&r2=1238307&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java
Tue Jan 31 09:18:14 2012
@@ -59,6 +59,7 @@ public class DbBlobStoreTest extends Tes
         if (sentinel != null) {
             sentinel.close();
         }
+        store.close();
     }
 
     public void testAddFile() throws Exception {
@@ -185,6 +186,8 @@ public class DbBlobStoreTest extends Tes
 
         String id = addFiles(store, "~/temp/ds");
         extractFiles(store, id, "target/test");
+
+        store.close();
     }
 
     public static void extractFiles(AbstractBlobStore store, String listingId, String target)
throws IOException {

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/FileBlobStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/FileBlobStoreTest.java?rev=1238307&r1=1238306&r2=1238307&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/FileBlobStoreTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/FileBlobStoreTest.java
Tue Jan 31 09:18:14 2012
@@ -28,8 +28,4 @@ public class FileBlobStoreTest extends D
         this.store = store;
     }
 
-    public void tearDown() throws Exception {
-        // nothing to do
-    }
-
 }

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/MemoryBlobStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/MemoryBlobStoreTest.java?rev=1238307&r1=1238306&r2=1238307&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/MemoryBlobStoreTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/MemoryBlobStoreTest.java
Tue Jan 31 09:18:14 2012
@@ -22,12 +22,7 @@ package org.apache.jackrabbit.mk.blobs;
 public class MemoryBlobStoreTest extends DbBlobStoreTest {
 
     public void setUp() throws Exception {
-        MemoryBlobStore store = new MemoryBlobStore();
-        this.store = store;
-    }
-
-    public void tearDown() throws Exception {
-        // nothing to do
+        store = new MemoryBlobStore();
     }
 
 }

Added: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/MongoBlobStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/MongoBlobStoreTest.java?rev=1238307&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/MongoBlobStoreTest.java
(added)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/MongoBlobStoreTest.java
Tue Jan 31 09:18:14 2012
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.blobs;
+
+/**
+ * Tests the MongoBlobStore implementation.
+ */
+public class MongoBlobStoreTest extends DbBlobStoreTest {
+
+    public void setUp() throws Exception {
+        // store = new MongoBlobStore();
+    }
+
+}



Mime
View raw message