jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1560029 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLBlobStore.java test/java/org/apache/jackrabbit/oak/plugins/mongomk/blob/SQLBlobStoreTest.java
Date Tue, 21 Jan 2014 14:18:18 GMT
Author: reschke
Date: Tue Jan 21 14:18:18 2014
New Revision: 1560029

URL: http://svn.apache.org/r1560029
Log:
OAK-1266 - blob store: add commits and add test

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/blob/SQLBlobStoreTest.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLBlobStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLBlobStore.java?rev=1560029&r1=1560028&r2=1560029&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLBlobStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLBlobStore.java
Tue Jan 21 14:18:18 2014
@@ -73,72 +73,80 @@ public class SQLBlobStore extends Abstra
     private long minLastModified;
 
     @Override
-    protected synchronized void storeBlock(byte[] digest, int level, byte[] data) throws
SQLException {
-        String id = StringUtils.convertBytesToHex(digest);
-        long now = System.currentTimeMillis();
-        PreparedStatement prep = connection.prepareStatement("update datastore_meta set lastMod
= ? where id = ?");
-        int count;
+    protected void storeBlock(byte[] digest, int level, byte[] data) throws SQLException
{
         try {
-            prep.setLong(1, now);
-            prep.setString(2, id);
-            count = prep.executeUpdate();
-        } finally {
-            prep.close();
-        }
-        if (count == 0) {
+            String id = StringUtils.convertBytesToHex(digest);
+            long now = System.currentTimeMillis();
+            PreparedStatement prep = connection.prepareStatement("update datastore_meta set
lastMod = ? where id = ?");
+            int count;
             try {
-                prep = connection.prepareStatement("insert into datastore_data(id, data)
values(?, ?)");
+                prep.setLong(1, now);
+                prep.setString(2, id);
+                count = prep.executeUpdate();
+            } finally {
+                prep.close();
+            }
+            if (count == 0) {
                 try {
-                    prep.setString(1, id);
-                    prep.setBytes(2, data);
-                    prep.execute();
-                } finally {
-                    prep.close();
+                    prep = connection.prepareStatement("insert into datastore_data(id, data)
values(?, ?)");
+                    try {
+                        prep.setString(1, id);
+                        prep.setBytes(2, data);
+                        prep.execute();
+                    } finally {
+                        prep.close();
+                    }
+                } catch (SQLException e) {
+                    // already exists - ok
                 }
-            } catch (SQLException e) {
-                // already exists - ok
-            }
-            try {
-                prep = connection.prepareStatement("insert into datastore_meta(id, level,
lastMod) values(?, ?, ?)");
                 try {
-                    prep.setString(1, id);
-                    prep.setInt(2, level);
-                    prep.setLong(3, now);
-                    prep.execute();
-                } finally {
-                    prep.close();
+                    prep = connection.prepareStatement("insert into datastore_meta(id, level,
lastMod) values(?, ?, ?)");
+                    try {
+                        prep.setString(1, id);
+                        prep.setInt(2, level);
+                        prep.setLong(3, now);
+                        prep.execute();
+                    } finally {
+                        prep.close();
+                    }
+                } catch (SQLException e) {
+                    // already exists - ok
                 }
-            } catch (SQLException e) {
-                // already exists - ok
             }
+        } finally {
+            connection.commit();
         }
     }
 
     @Override
     protected byte[] readBlockFromBackend(BlockId blockId) throws Exception {
-        PreparedStatement prep = connection.prepareStatement("select data from datastore_data
where id = ?");
         try {
-            String id = StringUtils.convertBytesToHex(blockId.getDigest());
-            prep.setString(1, id);
-            ResultSet rs = prep.executeQuery();
-            if (!rs.next()) {
-                throw new IOException("Datastore block " + id + " not found");
+            PreparedStatement prep = connection.prepareStatement("select data from datastore_data
where id = ?");
+            try {
+                String id = StringUtils.convertBytesToHex(blockId.getDigest());
+                prep.setString(1, id);
+                ResultSet rs = prep.executeQuery();
+                if (!rs.next()) {
+                    throw new IOException("Datastore block " + id + " not found");
+                }
+                byte[] data = rs.getBytes(1);
+                // System.out.println("    read block " + id + " blockLen: " +
+                // data.length + " [0]: " + data[0]);
+                if (blockId.getPos() == 0) {
+                    return data;
+                }
+                int len = (int) (data.length - blockId.getPos());
+                if (len < 0) {
+                    return new byte[0];
+                }
+                byte[] d2 = new byte[len];
+                System.arraycopy(data, (int) blockId.getPos(), d2, 0, len);
+                return d2;
+            } finally {
+                prep.close();
             }
-            byte[] data = rs.getBytes(1);
-            // System.out.println("    read block " + id + " blockLen: " +
-            // data.length + " [0]: " + data[0]);
-            if (blockId.getPos() == 0) {
-                return data;
-            }
-            int len = (int) (data.length - blockId.getPos());
-            if (len < 0) {
-                return new byte[0];
-            }
-            byte[] d2 = new byte[len];
-            System.arraycopy(data, (int) blockId.getPos(), d2, 0, len);
-            return d2;
         } finally {
-            prep.close();
+            connection.commit();
         }
     }
 
@@ -155,41 +163,49 @@ public class SQLBlobStore extends Abstra
 
     @Override
     protected void mark(BlockId blockId) throws Exception {
-        if (minLastModified == 0) {
-            return;
+        try {
+            if (minLastModified == 0) {
+                return;
+            }
+            String id = StringUtils.convertBytesToHex(blockId.getDigest());
+            PreparedStatement prep = connection
+                    .prepareStatement("update datastore_meta set lastMod = ? where id = ?
and lastMod < ?");
+            prep.setLong(1, System.currentTimeMillis());
+            prep.setString(2, id);
+            prep.setLong(3, minLastModified);
+            prep.executeUpdate();
+            prep.close();
+        } finally {
+            connection.commit();
         }
-        String id = StringUtils.convertBytesToHex(blockId.getDigest());
-        PreparedStatement prep = connection.prepareStatement("update datastore_meta set lastMod
= ? where id = ? and lastMod < ?");
-        prep.setLong(1, System.currentTimeMillis());
-        prep.setString(2, id);
-        prep.setLong(3, minLastModified);
-        prep.executeUpdate();
-        prep.close();
     }
 
     @Override
     public int sweep() throws Exception {
-        int count = 0;
-        PreparedStatement prep = connection.prepareStatement("select id from datastore_meta
where lastMod < ?");
-        prep.setLong(1, minLastModified);
-        ResultSet rs = prep.executeQuery();
-        ArrayList<String> ids = new ArrayList<String>();
-        while (rs.next()) {
-            ids.add(rs.getString(1));
-        }
-        prep = connection.prepareStatement("delete from datastore_meta where id = ?");
-        PreparedStatement prepData = connection.prepareStatement("delete from datastore_data
where id = ?");
-        for (String id : ids) {
-            prep.setString(1, id);
-            prep.execute();
-            prepData.setString(1, id);
-            prepData.execute();
-            count++;
+        try {
+            int count = 0;
+            PreparedStatement prep = connection.prepareStatement("select id from datastore_meta
where lastMod < ?");
+            prep.setLong(1, minLastModified);
+            ResultSet rs = prep.executeQuery();
+            ArrayList<String> ids = new ArrayList<String>();
+            while (rs.next()) {
+                ids.add(rs.getString(1));
+            }
+            prep = connection.prepareStatement("delete from datastore_meta where id = ?");
+            PreparedStatement prepData = connection.prepareStatement("delete from datastore_data
where id = ?");
+            for (String id : ids) {
+                prep.setString(1, id);
+                prep.execute();
+                prepData.setString(1, id);
+                prepData.execute();
+                count++;
+            }
+            prepData.close();
+            prep.close();
+            minLastModified = 0;
+            return count;
+        } finally {
+            connection.commit();
         }
-        prepData.close();
-        prep.close();
-        minLastModified = 0;
-        return count;
     }
-
 }

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/blob/SQLBlobStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/blob/SQLBlobStoreTest.java?rev=1560029&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/blob/SQLBlobStoreTest.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/blob/SQLBlobStoreTest.java
Tue Jan 21 14:18:18 2014
@@ -0,0 +1,36 @@
+/*
+ * 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.oak.plugins.mongomk.blob;
+
+import org.apache.jackrabbit.oak.plugins.sqlpersistence.SQLBlobStore;
+
+/**
+ * Tests the SQLBlobStore implementation.
+ */
+public class SQLBlobStoreTest extends AbstractBlobStoreTest {
+
+    public void setUp() throws Exception {
+        SQLBlobStore blobStore = new SQLBlobStore();
+        blobStore.setBlockSize(128);
+        blobStore.setBlockSizeMin(48);
+        this.store = blobStore;
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/blob/SQLBlobStoreTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message