jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From un...@apache.org
Subject svn commit: r1427374 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/data/ main/java/org/apache/jackrabbit/core/persistence/util/ test/java/org/apache/jackrabbit/core/data/
Date Tue, 01 Jan 2013 11:16:26 GMT
Author: unico
Date: Tue Jan  1 11:16:26 2013
New Revision: 1427374

URL: http://svn.apache.org/viewvc?rev=1427374&view=rev
Log:
JCR-3490 instead of individually loading every node in the repository load batches of node
infos at once. node states are now only loaded when the node in question indeed has a blob
property in the data store

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/NodeInfo.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCEventListenerTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCSubtreeMoveTest.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=1427374&r1=1427373&r2=1427374&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
Tue Jan  1 11:16:26 2013
@@ -23,6 +23,7 @@ import org.apache.jackrabbit.core.id.Nod
 import org.apache.jackrabbit.core.id.PropertyId;
 import org.apache.jackrabbit.core.observation.SynchronousEventListener;
 import org.apache.jackrabbit.core.persistence.IterablePersistenceManager;
+import org.apache.jackrabbit.core.persistence.util.NodeInfo;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.NoSuchItemStateException;
 import org.apache.jackrabbit.core.state.NodeState;
@@ -33,6 +34,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
+import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -79,6 +81,11 @@ public class GarbageCollector implements
     /** logger instance */
     static final Logger LOG = LoggerFactory.getLogger(GarbageCollector.class);
 
+    /**
+     * The number of nodes to fetch at once from the persistence manager. Defaults to 8kb
+     */
+    private static final int NODESATONCE = Integer.getInteger("org.apache.jackrabbit.garbagecollector.nodesatonce",
1024 * 8);
+
     private MarkEventListener callback;
 
     private long sleepBetweenNodes;
@@ -136,24 +143,10 @@ public class GarbageCollector implements
         this.testDelay = testDelay;
     }
 
-    /**
-     * @deprecated use setMarkEventListener().
-     */
-    public void setScanEventListener(ScanEventListener callback) {
-        setMarkEventListener(callback);
-    }
-
     public void setMarkEventListener(MarkEventListener callback) {
         this.callback = callback;
     }
 
-    /**
-     * @deprecated use mark().
-     */
-    public void scan() throws RepositoryException {
-        mark();
-    }
-
     public void mark() throws RepositoryException {
         if (store == null) {
             throw new RepositoryException("No DataStore configured.");
@@ -196,39 +189,40 @@ public class GarbageCollector implements
         return persistenceManagerScan;
     }
 
-    /**
-     * @deprecated use isPersistenceManagerScan().
-     */
-    public boolean getPersistenceManagerScan() {
-        return isPersistenceManagerScan();
-    }
-
     private void scanPersistenceManagers() throws RepositoryException, ItemStateException
{
         for (IterablePersistenceManager pm : pmList) {
-            for (NodeId id : pm.getAllNodeIds(null, 0)) {
-                if (callback != null) {
-                    callback.beforeScanning(null);
-                }
-                try {
-                    NodeState state = pm.load(id);
-                    Set<Name> propertyNames = state.getPropertyNames();
-                    for (Name name : propertyNames) {
-                        PropertyId pid = new PropertyId(id, name);
-                        PropertyState ps = pm.load(pid);
-                        if (ps.getType() == PropertyType.BINARY) {
-                            for (InternalValue v : ps.getValues()) {
-                                // getLength will update the last modified date
-                                // if the persistence manager scan is running
-                                v.getLength();
+            Map<NodeId,NodeInfo> batch = pm.getAllNodeInfos(null, NODESATONCE);
+            while (!batch.isEmpty()) {
+                NodeId lastId = null;
+                for (NodeInfo info : batch.values()) {
+                    lastId = info.getId();
+                    if (callback != null) {
+                        callback.beforeScanning(null);
+                    }
+                    if (info.hasBlobsInDataStore()) {
+                        try {
+                            NodeState state = pm.load(info.getId());
+                            Set<Name> propertyNames = state.getPropertyNames();
+                            for (Name name : propertyNames) {
+                                PropertyId pid = new PropertyId(info.getId(), name);
+                                PropertyState ps = pm.load(pid);
+                                if (ps.getType() == PropertyType.BINARY) {
+                                    for (InternalValue v : ps.getValues()) {
+                                        // getLength will update the last modified date
+                                        // if the persistence manager scan is running
+                                        v.getLength();
+                                    }
+                                }
                             }
+                        } catch (NoSuchItemStateException ignored) {
+                            // the node may have been deleted in the meantime
                         }
                     }
-                } catch (NoSuchItemStateException e) {
-                    // the node may have been deleted or moved in the meantime
-                    // ignore it
                 }
+                batch = pm.getAllNodeInfos(lastId, NODESATONCE);
             }
         }
+        NodeInfo.clearPool();
     }
 
     /**
@@ -244,13 +238,6 @@ public class GarbageCollector implements
         checkObservationException();
     }
 
-    /**
-     * @deprecated use sweep().
-     */
-    public int deleteUnused() throws RepositoryException {
-        return sweep();
-    }
-
     public int sweep() throws RepositoryException {
         if (startScanTimestamp == 0) {
             throw new RepositoryException("scan must be called first");

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/NodeInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/NodeInfo.java?rev=1427374&r1=1427373&r2=1427374&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/NodeInfo.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/NodeInfo.java
Tue Jan  1 11:16:26 2013
@@ -31,7 +31,7 @@ import org.apache.jackrabbit.core.value.
 import org.apache.jackrabbit.spi.Name;
 
 /**
- * Holds purely structural information about a node. Used by the consistency checker.
+ * Holds structural information about a node. Used by the consistency checker and garbage
collector.
  */
 public final class NodeInfo {
 
@@ -68,6 +68,11 @@ public final class NodeInfo {
     private boolean isReferenceable;
 
     /**
+     * Whether this node has blob properties in data storage
+     */
+    private boolean hasBlobsInDataStore;
+
+    /**
      * Create a new NodeInfo object from a bundle
      *
      * @param bundle the node bundle
@@ -97,6 +102,15 @@ public final class NodeInfo {
                 }
                 references.put(entry.getName(), values);
             }
+            else if (entry.getType() == PropertyType.BINARY) {
+                for (InternalValue internalValue : entry.getValues()) {
+                    if (internalValue.isInDataStore()) {
+                        hasBlobsInDataStore = true;
+                        break;
+                    }
+                }
+
+            }
         }
 
         if (references == null) {
@@ -141,6 +155,13 @@ public final class NodeInfo {
     }
 
     /**
+     * @return whether the node has blob properties that are inside the data storage
+     */
+    public boolean hasBlobsInDataStore() {
+        return hasBlobsInDataStore;
+    }
+
+    /**
      * Simple pool implementation to minimize memory overhead from node id objects
      * @param nodeId  node id to cache
      * @return  the cached node id

Modified: 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=1427374&r1=1427373&r2=1427374&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCEventListenerTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCEventListenerTest.java
Tue Jan  1 11:16:26 2013
@@ -110,9 +110,6 @@ public class GCEventListenerTest extends
         }
     }
 
-    public void afterScanning(Node n) throws RepositoryException {
-    }
-
     public void beforeScanning(Node n) throws RepositoryException {
         String s = getNodeName(n);
         if (s != null) {

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCSubtreeMoveTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCSubtreeMoveTest.java?rev=1427374&r1=1427373&r2=1427374&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCSubtreeMoveTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCSubtreeMoveTest.java
Tue Jan  1 11:16:26 2013
@@ -172,7 +172,7 @@ public class GCSubtreeMoveTest extends T
 
     private GarbageCollector setupGarbageCollector() {
         try {
-            return ((SessionImpl) sessionGarbageCollector).createDataStoreGarbageCollector();
       
+            return ((SessionImpl) sessionGarbageCollector).createDataStoreGarbageCollector();
         } catch (RepositoryException e) {
             failWithException(e);
         }



Mime
View raw message