jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r801894 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/data/GarbageCollector.java test/java/org/apache/jackrabbit/core/data/GCConcurrentTest.java
Date Fri, 07 Aug 2009 06:49:23 GMT
Author: thomasm
Date: Fri Aug  7 06:49:23 2009
New Revision: 801894

URL: http://svn.apache.org/viewvc?rev=801894&view=rev
Log:
JCR-2241 Data Store: garbage collection should ignore removed items

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCConcurrentTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java?rev=801894&r1=801893&r2=801894&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
Fri Aug  7 06:49:23 2009
@@ -35,6 +35,7 @@
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import javax.jcr.InvalidItemStateException;
 import javax.jcr.Item;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
@@ -305,26 +306,34 @@
         if (callback != null) {
             callback.beforeScanning(n);
         }
-        for (PropertyIterator it = n.getProperties(); it.hasNext();) {
-            Property p = it.nextProperty();
-            if (p.getType() == PropertyType.BINARY) {
-                if (n.hasProperty("jcr:uuid")) {
-                    rememberNode(n.getProperty("jcr:uuid").getString());
-                } else {
-                    rememberNode(n.getPath());
-                }
-                if (p.getDefinition().isMultiple()) {
-                    p.getLengths();
-                } else {
-                    p.getLength();
+        try {
+            for (PropertyIterator it = n.getProperties(); it.hasNext();) {
+                Property p = it.nextProperty();
+                if (p.getType() == PropertyType.BINARY) {
+                    if (n.hasProperty("jcr:uuid")) {
+                        rememberNode(n.getProperty("jcr:uuid").getString());
+                    } else {
+                        rememberNode(n.getPath());
+                    }
+                    if (p.getDefinition().isMultiple()) {
+                        p.getLengths();
+                    } else {
+                        p.getLength();
+                    }
                 }
             }
+        } catch (InvalidItemStateException e) {
+            // the property may have been removed in the meantime - ignore
         }
         if (callback != null) {
             callback.afterScanning(n);
         }
-        for (NodeIterator it = n.getNodes(); it.hasNext();) {
-            recurse(it.nextNode(), sleep);
+        try {
+            for (NodeIterator it = n.getNodes(); it.hasNext();) {
+                recurse(it.nextNode(), sleep);
+            }
+        } catch (InvalidItemStateException e) {
+            // the item may have been removed in the meantime - ignore
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCConcurrentTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCConcurrentTest.java?rev=801894&r1=801893&r2=801894&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCConcurrentTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCConcurrentTest.java
Fri Aug  7 06:49:23 2009
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.data;
 
 import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.test.AbstractJCRTest;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -40,6 +41,35 @@
     /** logger instance */
     private static final Logger LOG = LoggerFactory.getLogger(GCConcurrentTest.class);
 
+    public void testConcurrentDelete() throws Exception {
+        Node root = testRootNode;
+        Session session = root.getSession();
+        RepositoryImpl rep = (RepositoryImpl) session.getRepository();
+        if (rep.getDataStore() == null) {
+            LOG.info("testGC skipped. Data store is not used.");
+            return;
+        }
+        final String testNodeName = "testConcurrentDelete";
+        node(root, testNodeName);
+        session.save();
+        GarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
+        gc.setPersistenceManagerScan(false);
+        gc.setScanEventListener(new ScanEventListener() {
+            public void beforeScanning(Node n) throws RepositoryException {
+                if (n.getName().equals(testNodeName)) {
+                    n.remove();
+                    n.getSession().save();
+                }
+            }
+            public void afterScanning(Node n) throws RepositoryException {
+            }
+            public void done() {
+            }
+        });
+        gc.scan();
+        gc.stopScan();
+    }
+
     public void testGC() throws Exception {
         Node root = testRootNode;
         Session session = root.getSession();



Mime
View raw message