jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1327926 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: RepositoryChecker.java RepositoryImpl.java
Date Thu, 19 Apr 2012 12:27:34 GMT
Author: reschke
Date: Thu Apr 19 12:27:33 2012
New Revision: 1327926

URL: http://svn.apache.org/viewvc?rev=1327926&view=rev
Log:
JCR-3298: RepositoryChecker - apply changes in smaller chunks, augment logging information

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryChecker.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryChecker.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryChecker.java?rev=1327926&r1=1327925&r2=1327926&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryChecker.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryChecker.java
Thu Apr 19 12:27:33 2012
@@ -72,8 +72,20 @@ class RepositoryChecker {
 
     private final InternalVersionManagerImpl versionManager;
 
-    public RepositoryChecker(
-            PersistenceManager workspace,
+    // maximum size of changelog when running in "fixImmediately" mode
+    private final static long CHUNKSIZE = 256;
+
+    // number of nodes affected by pending changes
+    private long dirtyNodes = 0;
+
+    // total nodes checked, with problems
+    private long totalNodes = 0;
+    private long brokenNodes = 0;
+
+    // start time
+    private long startTime;
+
+    public RepositoryChecker(PersistenceManager workspace,
             InternalVersionManagerImpl versionManager) {
         this.workspace = workspace;
         this.workspaceChanges = new ChangeLog();
@@ -81,17 +93,41 @@ class RepositoryChecker {
         this.versionManager = versionManager;
     }
 
-    public void check(NodeId id, boolean recurse)
+    public void check(NodeId id, boolean recurse, boolean fixImmediately)
             throws RepositoryException {
+
+        log.info("Starting RepositoryChecker");
+
+        startTime = System.currentTimeMillis();
+
+        internalCheck(id, recurse, fixImmediately);
+
+        if (fixImmediately) {
+            internalFix(true);
+        }
+
+        log.info("RepositoryChecker finished; checked " + totalNodes
+                + " nodes in " + (System.currentTimeMillis() - startTime)
+                + "ms, problems found: " + brokenNodes);
+    }
+
+    private void internalCheck(NodeId id, boolean recurse,
+            boolean fixImmediately) throws RepositoryException {
         try {
             log.debug("Checking consistency of node {}", id);
+            totalNodes += 1;
+
             NodeState state = workspace.load(id);
             checkVersionHistory(state);
 
+            if (fixImmediately && dirtyNodes > CHUNKSIZE) {
+                internalFix(false);
+            }
+
             if (recurse) {
                 for (ChildNodeEntry child : state.getChildNodeEntries()) {
                     if (!SYSTEM_ROOT_NODE_ID.equals(child.getId())) {
-                        check(child.getId(), recurse);
+                        internalCheck(child.getId(), recurse, fixImmediately);
                     }
                 }
             }
@@ -100,26 +136,38 @@ class RepositoryChecker {
         }
     }
 
-    private void fix(PersistenceManager pm, ChangeLog changes, String store)
-            throws RepositoryException {
+    private void fix(PersistenceManager pm, ChangeLog changes, String store,
+            boolean verbose) throws RepositoryException {
         if (changes.hasUpdates()) {
-            log.warn("Fixing " + store + " inconsistencies");
+            if (log.isWarnEnabled()) {
+                log.warn("Fixing " + store + " inconsistencies: "
+                        + changes.toString());
+            }
             try {
                 pm.store(changes);
+                changes.reset();
             } catch (ItemStateException e) {
-                String message = "Failed to fix " + store + " inconsistencies (aborting)";
+                String message = "Failed to fix " + store
+                        + " inconsistencies (aborting)";
                 log.error(message, e);
                 throw new RepositoryException(message, e);
             }
         } else {
-            log.info("No " + store + "  inconsistencies found");
+            if (verbose) {
+                log.info("No " + store + " inconsistencies found");
+            }
         }
     }
 
     public void fix() throws RepositoryException {
-        fix(workspace, workspaceChanges, "workspace");
+        internalFix(true);
+    }
+
+    private void internalFix(boolean verbose) throws RepositoryException {
+        fix(workspace, workspaceChanges, "workspace", verbose);
         fix(versionManager.getPersistenceManager(), vworkspaceChanges,
-                "versioning workspace");
+                "versioning workspace", verbose);
+        dirtyNodes = 0;
     }
 
     private void checkVersionHistory(NodeState node) {
@@ -212,6 +260,10 @@ class RepositoryChecker {
 
     // un-versions the node, and potentially moves the version history away
     private void removeVersionHistoryReferences(NodeState node,  NodeId vhid) {
+
+        dirtyNodes += 1;
+        brokenNodes += 1;
+
         NodeState modified =
             new NodeState(node, NodeState.STATUS_EXISTING_MODIFIED, true);
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=1327926&r1=1327925&r2=1327926&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Thu Apr 19 12:27:33 2012
@@ -2062,8 +2062,7 @@ public class RepositoryImpl extends Abst
             if (Boolean.getBoolean("org.apache.jackrabbit.version.recovery")) {
                 RepositoryChecker checker = new RepositoryChecker(
                         persistMgr, context.getInternalVersionManager());
-                checker.check(ROOT_NODE_ID, true);
-                checker.fix();
+                checker.check(ROOT_NODE_ID, true, true);
             }
         }
 



Mime
View raw message