jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1166658 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store: AbstractRevisionStore.java H2RevisionStore.java RevisionStore.java
Date Thu, 08 Sep 2011 12:45:01 GMT
Author: stefan
Date: Thu Sep  8 12:45:00 2011
New Revision: 1166658

URL: http://svn.apache.org/viewvc?rev=1166658&view=rev
Log:
h2: store head again in db but cache it for read access

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractRevisionStore.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractRevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractRevisionStore.java?rev=1166658&r1=1166657&r2=1166658&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractRevisionStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractRevisionStore.java
Thu Sep  8 12:45:00 2011
@@ -73,7 +73,7 @@ abstract class AbstractRevisionStore imp
         headRev.set(revId);
     }
 
-    public String computeId(InputStream in) throws Exception {
+    public static String computeId(InputStream in) throws Exception {
         MessageDigest digest = MessageDigest.getInstance("SHA-1");
         int read;
         byte[] buf = new byte[8192];

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=1166658&r1=1166657&r2=1166658&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
Thu Sep  8 12:45:00 2011
@@ -32,11 +32,12 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.Statement;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 /**
  *
  */
-public class H2RevisionStore extends AbstractRevisionStore implements BlobStore {
+public class H2RevisionStore implements RevisionStore, BlobStore {
 
     private static final boolean FAST = Boolean.getBoolean("mk.fastDb");
 
@@ -45,7 +46,13 @@ public class H2RevisionStore extends Abs
     private JdbcConnectionPool cp;
     private DbBlobStore blobStore;
 
+    private String headId;
+    private final ReentrantReadWriteLock headLock;
+
     public H2RevisionStore() throws Exception {
+        headId = null;
+        headLock = new ReentrantReadWriteLock();
+
         initialized = false;
     }
 
@@ -54,8 +61,6 @@ public class H2RevisionStore extends Abs
             throw new IllegalStateException("already initialized");
         }
 
-        super.initialize(homeDir);
-
         File dbDir = new File(homeDir, "db");
         if (!dbDir.exists()) {
             dbDir.mkdir();
@@ -92,24 +97,31 @@ 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) {
             throw new IllegalStateException("not initialized");
         }
 
-        Connection con = cp.getConnection();
+        headLock.readLock().lock();
         try {
-            PreparedStatement stmt = con.prepareStatement("select * from head");
-            ResultSet rs = stmt.executeQuery();
-            rs.next();
-            String head = rs.getString(1);
-            stmt.close();
-            return head;
+            if (headId == null) {
+                Connection con = cp.getConnection();
+                try {
+                    PreparedStatement stmt = con.prepareStatement("select * from head");
+                    ResultSet rs = stmt.executeQuery();
+                    rs.next();
+                    headId = rs.getString(1);
+                    stmt.close();
+                    return headId;
+                } finally {
+                    con.close();
+                }
+            } else {
+                return headId;
+            }
         } finally {
-            con.close();
+            headLock.readLock().unlock();
         }
     }
 
@@ -118,17 +130,23 @@ public class H2RevisionStore extends Abs
             throw new IllegalStateException("not initialized");
         }
 
-        Connection con = cp.getConnection();
+        headLock.writeLock().lock();
         try {
-            PreparedStatement stmt = con.prepareStatement("update head set id=?");
-            stmt.setString(1, revId);
-            stmt.execute();
-            stmt.close();
+            Connection con = cp.getConnection();
+            try {
+                PreparedStatement stmt = con.prepareStatement("update head set id=?");
+                stmt.setString(1, revId);
+                stmt.execute();
+                headId = revId;
+                stmt.close();
+            } finally {
+                con.close();
+            }
         } finally {
-            con.close();
+            headLock.writeLock().unlock();
         }
     }
-*/
+
     public InputStream get(String id) throws Exception {
         if (!initialized) {
             throw new IllegalStateException("not initialized");

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java?rev=1166658&r1=1166657&r2=1166658&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java
Thu Sep  8 12:45:00 2011
@@ -33,8 +33,6 @@ public interface RevisionStore {
 
     String /* id */ put(InputStream in) throws Exception;
 
-    String computeId(InputStream in) throws Exception;
-
     String /* id */ getHeadId() throws Exception;
 
     void setHeadId(String revId) throws Exception;



Mime
View raw message