jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1585448 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
Date Mon, 07 Apr 2014 10:44:02 GMT
Author: reschke
Date: Mon Apr  7 10:44:02 2014
New Revision: 1585448

URL: http://svn.apache.org/r1585448
Log:
OAK-1266 - make delete() be really best effort (ignore missing documents), unify code path,
add test cases

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1585448&r1=1585447&r2=1585448&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
Mon Apr  7 10:44:02 2014
@@ -26,6 +26,7 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.Types;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
@@ -338,13 +339,12 @@ public class RDBDocumentStore implements
                 insertDocument(collection, doc);
                 addToCache(collection, doc);
                 return oldDoc;
-            }
-            catch (MicroKernelException ex) {
+            } catch (MicroKernelException ex) {
                 // may have failed due to a race condition; try update instead
                 oldDoc = readDocumentCached(collection, update.getId(), Integer.MAX_VALUE);
                 if (oldDoc == null) {
                     // something else went wrong
-                    throw(ex);
+                    throw (ex);
                 }
                 return internalUpdate(collection, update, oldDoc, checkConditions, RETRIES);
             }
@@ -524,11 +524,8 @@ public class RDBDocumentStore implements
         String tableName = getTable(collection);
         try {
             connection = getConnection();
-            boolean success = dbDelete(connection, tableName, id);
+            dbDelete(connection, tableName, Collections.singletonList(id));
             connection.commit();
-            if (!success) {
-                throw new MicroKernelException("not deleted: " + id);
-            }
         } catch (Exception ex) {
             throw new MicroKernelException(ex);
         } finally {
@@ -542,11 +539,8 @@ public class RDBDocumentStore implements
             String tableName = getTable(collection);
             try {
                 connection = getConnection();
-                boolean success = dbDelete(connection, tableName, sublist);
+                dbDelete(connection, tableName, sublist);
                 connection.commit();
-                if (!success) {
-                    throw new MicroKernelException("not deleted: " + ids);
-                }
             } catch (Exception ex) {
                 throw new MicroKernelException(ex);
             } finally {
@@ -749,31 +743,24 @@ public class RDBDocumentStore implements
         }
     }
 
-    private boolean dbDelete(Connection connection, String tableName, String id) throws SQLException
{
-        PreparedStatement stmt = connection.prepareStatement("delete from " + tableName +
" where ID = ?");
-        try {
-            stmt.setString(1, id);
-            int result = stmt.executeUpdate();
-            if (result != 1) {
-                LOG.debug("DB delete failed for " + tableName + "/" + id);
-            }
-            return result == 1;
-        } finally {
-            stmt.close();
-        }
-    }
+    private void dbDelete(Connection connection, String tableName, List<String> ids)
throws SQLException {
 
-    private boolean dbDelete(Connection connection, String tableName, List<String>
ids) throws SQLException {
-        StringBuilder inClause = new StringBuilder();
+        PreparedStatement stmt;
         int cnt = ids.size();
-        for (int i = 0; i < cnt; i++) {
-            inClause.append('?');
-            if (i != cnt - 1) {
-                inClause.append(',');
+
+        if (cnt == 1) {
+            stmt = connection.prepareStatement("delete from " + tableName + " where ID=?");
+        } else {
+            StringBuilder inClause = new StringBuilder();
+            for (int i = 0; i < cnt; i++) {
+                inClause.append('?');
+                if (i != cnt - 1) {
+                    inClause.append(',');
+                }
             }
+            stmt = connection.prepareStatement("delete from " + tableName + " where ID in
(" + inClause.toString() + ")");
         }
-        PreparedStatement stmt = connection.prepareStatement("delete from " + tableName +
" where ID in (" + inClause.toString()
-                + ")");
+
         try {
             for (int i = 0; i < cnt; i++) {
                 stmt.setString(i + 1, ids.get(i));
@@ -782,7 +769,6 @@ public class RDBDocumentStore implements
             if (result != cnt) {
                 LOG.debug("DB delete failed for " + tableName + "/" + ids);
             }
-            return result == cnt;
         } finally {
             stmt.close();
         }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java?rev=1585448&r1=1585447&r2=1585448&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
Mon Apr  7 10:44:02 2014
@@ -19,7 +19,10 @@ package org.apache.jackrabbit.oak.plugin
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
 
 import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
 import org.junit.Assume;
@@ -109,6 +112,30 @@ public class BasicDocumentStoreTest exte
     }
 
     @Test
+    public void testDeleteNonExisting() {
+        String id = this.getClass().getName() + ".testDeleteNonExisting-" + UUID.randomUUID();
+        // delete is best effort
+        ds.remove(Collection.NODES, id);
+    }
+
+    @Test
+    public void testDeleteNonExistingMultiple() {
+        String id = this.getClass().getName() + ".testDeleteNonExistingMultiple-" + UUID.randomUUID();
+        // create a test node
+        UpdateOp up = new UpdateOp(id, true);
+        up.set("_id", id + "-2");
+        boolean success = super.ds.create(Collection.NODES, Collections.singletonList(up));
+        assertTrue(success);
+        List<String> todelete = new ArrayList<String>();
+        todelete.add(id + "-2");
+        todelete.add(id);
+        ds.remove(Collection.NODES, todelete);
+        // id-2 should be removed
+        Document d = ds.find(Collection.NODES, id + "-2");
+        assertTrue(d == null);
+    }
+
+    @Test
     public void testCreatePerfSmall() {
         createPerf(16);
     }



Mime
View raw message