jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1166205 - in /jackrabbit/sandbox/microkernel: ./ src/main/java/org/apache/jackrabbit/mk/ src/main/java/org/apache/jackrabbit/mk/blobs/ src/main/java/org/apache/jackrabbit/mk/store/
Date Wed, 07 Sep 2011 14:48:44 GMT
Author: stefan
Date: Wed Sep  7 14:48:43 2011
New Revision: 1166205

URL: http://svn.apache.org/viewvc?rev=1166205&view=rev
Log:
add bdb support (for testing/comparison only)
some minor performance tweaks

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbRevisionStore.java
Modified:
    jackrabbit/sandbox/microkernel/pom.xml
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java

Modified: jackrabbit/sandbox/microkernel/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/pom.xml?rev=1166205&r1=1166204&r2=1166205&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/pom.xml (original)
+++ jackrabbit/sandbox/microkernel/pom.xml Wed Sep  7 14:48:43 2011
@@ -36,6 +36,12 @@
             <version>1.3.158</version>
         </dependency>
 
+        <dependency>
+          <groupId>com.sleepycat</groupId>
+          <artifactId>je</artifactId>
+          <version>4.1.10</version>
+        </dependency>
+
         <!--Test Dependencies-->
         <dependency>
             <groupId>com.googlecode.json-simple</groupId>

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java?rev=1166205&r1=1166204&r2=1166205&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
Wed Sep  7 14:48:43 2011
@@ -18,12 +18,14 @@ package org.apache.jackrabbit.mk;
 
 import org.apache.jackrabbit.mk.blobs.BlobStore;
 import org.apache.jackrabbit.mk.blobs.FileBlobStore;
+import org.apache.jackrabbit.mk.store.BDbRevisionStore;
 import org.apache.jackrabbit.mk.store.Commit;
 import org.apache.jackrabbit.mk.store.CommitBuilder;
 import org.apache.jackrabbit.mk.store.H2RevisionStore;
 import org.apache.jackrabbit.mk.store.Node;
 import org.apache.jackrabbit.mk.store.PersistenceManager;
 import org.apache.jackrabbit.mk.store.RevisionStore;
+import org.apache.jackrabbit.mk.store.SimpleRevisionStore;
 import org.apache.jackrabbit.mk.util.PathUtils;
 
 import java.io.File;
@@ -57,6 +59,7 @@ public class Repository {
 
         RevisionStore revStore = new H2RevisionStore();
         //RevisionStore revStore = new SimpleRevisionStore();
+        //RevisionStore revStore = new BDbRevisionStore();
         revStore.initialize(home);
 
         BlobStore blobStore;
@@ -167,7 +170,7 @@ public class Repository {
         // get root node
         ids[0] = commit.getRootNodeId();
         Node parent = pm.getNode(ids[0]);
-        // traverse path and pm id of each element
+        // traverse path and remember id of each element
         for (int i = 0; i < names.length; i++) {
             String id = parent.getChildNodeEntries().get(names[i]);
             if (id == null) {

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=1166205&r1=1166204&r2=1166205&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
Wed Sep  7 14:48:43 2011
@@ -18,8 +18,8 @@ package org.apache.jackrabbit.mk.blobs;
 
 import org.apache.jackrabbit.mk.util.ExceptionFactory;
 import org.apache.jackrabbit.mk.util.IOUtils;
+import org.apache.jackrabbit.mk.util.SimpleLRUCache;
 import org.apache.jackrabbit.mk.util.StringUtils;
-import org.h2.util.SmallLRUCache;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -73,7 +73,8 @@ public abstract class AbstractBlobStore 
      */
     private int blockSize = 2 * 1024 * 1024;
 
-    private SmallLRUCache<String, byte[]> cache = SmallLRUCache.newInstance(5);
+    private SimpleLRUCache<String, byte[]> cache = SimpleLRUCache
+            .newInstance(5);
 
     public void setBlockSizeMin(int x) {
         this.blockSizeMin = x;

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbRevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbRevisionStore.java?rev=1166205&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbRevisionStore.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbRevisionStore.java
Wed Sep  7 14:48:43 2011
@@ -0,0 +1,162 @@
+/*
+ * 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.store;
+
+import com.sleepycat.je.Database;
+import com.sleepycat.je.DatabaseConfig;
+import com.sleepycat.je.DatabaseEntry;
+import com.sleepycat.je.Durability;
+import com.sleepycat.je.Environment;
+import com.sleepycat.je.EnvironmentConfig;
+import com.sleepycat.je.EnvironmentMutableConfig;
+import com.sleepycat.je.LockMode;
+import com.sleepycat.je.OperationStatus;
+import org.apache.jackrabbit.mk.util.StringUtils;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.security.DigestOutputStream;
+import java.security.MessageDigest;
+
+/**
+ *
+ */
+public class BDbRevisionStore extends AbstractRevisionStore {
+
+    private boolean initialized;
+
+    private Environment dbEnv;
+    private Database db;
+
+    public BDbRevisionStore() throws Exception {
+        initialized = false;
+    }
+
+    public void initialize(File homeDir) throws Exception {
+        if (initialized) {
+            throw new IllegalStateException("already initialized");
+        }
+
+        super.initialize(homeDir);
+
+        File dbDir = new File(homeDir, "db");
+        if (!dbDir.exists()) {
+            dbDir.mkdir();
+        }
+
+        EnvironmentConfig envConfig = new EnvironmentConfig();
+        //envConfig.setTransactional(true);
+        envConfig.setAllowCreate(true);
+        dbEnv = new Environment(dbDir, envConfig);
+
+        EnvironmentMutableConfig envMutableConfig = new EnvironmentMutableConfig();
+        //envMutableConfig.setDurability(Durability.COMMIT_SYNC);
+        //envMutableConfig.setDurability(Durability.COMMIT_NO_SYNC);
+        envMutableConfig.setDurability(Durability.COMMIT_WRITE_NO_SYNC);
+        dbEnv.setMutableConfig(envMutableConfig);
+
+        DatabaseConfig dbConfig = new DatabaseConfig();
+        dbConfig.setAllowCreate(true);
+        //dbConfig.setDeferredWrite(true);
+        db = dbEnv.openDatabase(null, "revs", dbConfig);
+
+        // TODO FIXME workaround in case we're not closed properly
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            public void run() {
+                close();
+            }
+        });
+
+        initialized = true;
+    }
+
+    public void close() {
+        if (!initialized) {
+            return;
+        }
+        try {
+            if (db.getConfig().getDeferredWrite()) {
+                db.sync();
+            }
+            db.close();
+            dbEnv.close();
+
+            db = null;
+            dbEnv = null;
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+
+        initialized = false;
+    }
+
+    public InputStream get(String id) throws Exception {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
+        DatabaseEntry key = new DatabaseEntry(StringUtils.convertHexToBytes(id));
+        DatabaseEntry data = new DatabaseEntry();
+
+        if (db.get(null, key, data, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
+            return new ByteArrayInputStream(data.getData());
+        } else {
+            throw new Exception("not found: " + id);
+        }
+    }
+
+    public String put(InputStream in) throws Exception {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
+        MessageDigest digest = MessageDigest.getInstance("SHA-1");
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        DigestOutputStream dos = new DigestOutputStream(baos, digest);
+
+        try {
+            int read;
+            byte[] buf = new byte[8192];
+            while ((read = in.read(buf, 0, buf.length)) != -1) {
+                dos.write(buf, 0, read);
+            }
+        } finally {
+            dos.flush();
+            // baos.close();
+            in.close();
+        }
+
+        DatabaseEntry key = new DatabaseEntry(digest.digest());
+        DatabaseEntry data = new DatabaseEntry(baos.toByteArray());
+
+        db.put(null, key, data);
+
+        return StringUtils.convertBytesToHex(key.getData());
+    }
+
+    @Override
+    public void setHeadId(String revId) throws Exception {
+/*
+        if (db.getConfig().getDeferredWrite()) {
+            db.sync();
+        }
+*/
+        super.setHeadId(revId);
+    }
+}

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java?rev=1166205&r1=1166204&r2=1166205&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java
Wed Sep  7 14:48:43 2011
@@ -92,6 +92,8 @@ public class H2RevisionStore extends Abs
 
         initialized = false;
     }
+/*
+    // don't stpre HEAD revision in db in order to minimize lock contention on persistecne
layer
 
     public String getHeadId() throws Exception {
         if (!initialized) {
@@ -126,7 +128,7 @@ public class H2RevisionStore extends Abs
             con.close();
         }
     }
-
+*/
     public InputStream get(String id) throws Exception {
         if (!initialized) {
             throw new IllegalStateException("not initialized");



Mime
View raw message