jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r636774 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/data/ test/java/org/apache/jackrabbit/core/data/
Date Thu, 13 Mar 2008 14:41:34 GMT
Author: thomasm
Date: Thu Mar 13 07:41:29 2008
New Revision: 636774

URL: http://svn.apache.org/viewvc?rev=636774&view=rev
Log:
JCR-1469 Data store garbage collection: ScanEventListener not working

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCEventListenerTest.java
  (with props)
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/GarbageCollectorTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.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=636774&r1=636773&r2=636774&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
Thu Mar 13 07:41:29 2008
@@ -84,6 +84,8 @@
 
     private final Session[] sessionList;
 
+    private boolean persistenceManagerScan;
+
     // TODO It should be possible to stop and restart a garbage collection scan.
 
     /**
@@ -97,6 +99,7 @@
         RepositoryImpl rep = (RepositoryImpl) session.getRepository();
         store = rep.getDataStore();
         this.pmList = list;
+        this.persistenceManagerScan = list != null;
         this.sessionList = sessionList;
     }
 
@@ -150,7 +153,7 @@
             store.updateModifiedDateOnAccess(startScanTimestamp);
         }
 
-        if (pmList == null) {
+        if (pmList == null || !persistenceManagerScan) {
             for (int i = 0; i < sessionList.length; i++) {
                 scanNodes(sessionList[i]);
             }
@@ -171,12 +174,36 @@
         recurse(session.getRootNode(), sleepBetweenNodes);
     }
 
+    /**
+     * Enable or disable using the IterablePersistenceManager interface
+     * to scan the items. This is important for clients that need
+     * the complete Node implementation in the ScanEventListener
+     * callback.
+     *
+     * @param allow true if using the IterablePersistenceManager interface is allowed
+     */
+    public void setPersistenceManagerScan(boolean allow) {
+        persistenceManagerScan = allow;
+    }
+
+    /**
+     * Check if using the IterablePersistenceManager interface is allowed.
+     *
+     * @return true if using IterablePersistenceManager is possible.
+     */
+    public boolean getPersistenceManagerScan() {
+        return persistenceManagerScan;
+    }
+
     private void scanPersistenceManagers() throws ItemStateException, RepositoryException
{
         for (int i = 0; i < pmList.length; i++) {
             IterablePersistenceManager pm = pmList[i];
             Iterator it = pm.getAllNodeIds(null, 0);
             while (it.hasNext()) {
                 NodeId id = (NodeId) it.next();
+                if (callback != null) {
+                    callback.beforeScanning(null);
+                }
                 try {
                     NodeState state = pm.load(id);
                     Set propertyNames = state.getPropertyNames();
@@ -195,6 +222,9 @@
                 } catch (NoSuchItemStateException e) {
                     // the node may have been deleted or moved in the meantime
                     // ignore it
+                }
+                if (callback != null) {
+                    callback.afterScanning(null);
                 }
             }
         }

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCEventListenerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCEventListenerTest.java?rev=636774&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCEventListenerTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCEventListenerTest.java
Thu Mar 13 07:41:29 2008
@@ -0,0 +1,121 @@
+/*
+ * 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.core.data;
+
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayInputStream;
+import java.util.Random;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+/**
+ * Test the DataStore garbage collector.
+ * This tests that the EventListener is called while scanning the repository.
+ *
+ * @author Thomas Mueller
+ */
+public class GCEventListenerTest extends AbstractJCRTest implements ScanEventListener {
+
+    /** logger instance */
+    private static final Logger LOG = LoggerFactory.getLogger(GCEventListenerTest.class);
+
+    private boolean gotNullNode;
+    private boolean gotNode;
+    private int count;
+
+    private static final String TEST_NODE_NAME = "testGCEventListener";
+
+    public void testEventListener() throws Exception {
+        doTestEventListener(true);
+        doTestEventListener(false);
+    }
+
+    private void doTestEventListener(boolean allowPmScan) throws Exception {
+        Node root = testRootNode;
+        Session session = root.getSession();
+        if (root.hasNode(TEST_NODE_NAME)) {
+            root.getNode(TEST_NODE_NAME).remove();
+            session.save();
+        }
+        Node test = root.addNode(TEST_NODE_NAME);
+        Random random = new Random();
+        byte[] data = new byte[10000];
+        for (int i = 0; i < 20; i++) {
+            Node n = test.addNode("x" + i);
+            random.nextBytes(data);
+            n.setProperty("data", new ByteArrayInputStream(data));
+            session.save();
+            if (i % 2 == 0) {
+                n.remove();
+                session.save();
+            }
+        }
+        session.save();
+        SessionImpl si = (SessionImpl) session;
+        GarbageCollector gc = si.createDataStoreGarbageCollector();
+        if (gc.getDataStore() != null) {
+            gc.getDataStore().clearInUse();
+            boolean pmScan = gc.getPersistenceManagerScan();
+            gc.setPersistenceManagerScan(allowPmScan);
+            gotNullNode = false;
+            gotNode = false;
+            gc.setScanEventListener(this);
+            gc.scan();
+            gc.stopScan();
+            if (pmScan && allowPmScan) {
+                assertTrue("PM scan without null Node", gotNullNode);
+                assertFalse("PM scan, but got a real node", gotNode);
+            } else {
+                assertFalse("Not a PM scan - but got a null Node", gotNullNode);
+                assertTrue("Not a PM scan - without a real node", gotNode);
+            }
+            int deleted = gc.deleteUnused();
+            LOG.debug("Deleted " + deleted);
+            assertTrue("Should delete at least one item", deleted >= 0);
+        }
+    }
+
+    public String getNodeName(Node n) throws RepositoryException {
+        if (n == null) {
+            gotNullNode = true;
+            return String.valueOf(count++);
+        } else {
+            gotNode = true;
+            return n.getPath();
+        }
+    }
+
+    public void afterScanning(Node n) throws RepositoryException {
+    }
+
+    public void beforeScanning(Node n) throws RepositoryException {
+        String s = getNodeName(n);
+        if (s != null) {
+            LOG.debug("scanning " + s);
+        }
+    }
+
+    public void done() {
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCEventListenerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java?rev=636774&r1=636773&r2=636774&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java
Thu Mar 13 07:41:29 2008
@@ -151,7 +151,7 @@
     }
 
     public void afterScanning(Node n) throws RepositoryException {
-        if (n.getPath().startsWith("/testroot/node")) {
+        if (n != null && n.getPath().startsWith("/testroot/node")) {
             String path = n.getPath();
             LOG.debug("scanned: " + path);
         }
@@ -166,7 +166,7 @@
     }
 
     public void beforeScanning(Node n) throws RepositoryException {
-        if (n.getPath().equals("/testroot/node2")) {
+        if (n != null && n.getPath().equals("/testroot/node2")) {
             Session session = n.getSession();
             list(session.getRootNode());
             session.move("/testroot/node2/nodeWithBlob", "/testroot/node1/nodeWithBlob");

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java?rev=636774&r1=636773&r2=636774&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
Thu Mar 13 07:41:29 2008
@@ -36,6 +36,7 @@
         suite.addTestSuite(ExportImportTest.class);
         suite.addTestSuite(GarbageCollectorTest.class);
         suite.addTestSuite(GCConcurrentTest.class);
+        suite.addTestSuite(GCEventListenerTest.class);
         suite.addTestSuite(PersistenceManagerIteratorTest.class);
         suite.addTestSuite(CopyValueTest.class);
         return suite;



Mime
View raw message