You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2008/03/17 12:37:43 UTC

svn commit: r637847 - in /jackrabbit/branches/1.3/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java test/java/org/apache/jackrabbit/core/persistence/ConsistencyCheckTest.java

Author: jukka
Date: Mon Mar 17 04:37:42 2008
New Revision: 637847

URL: http://svn.apache.org/viewvc?rev=637847&view=rev
Log:
JCR-1428: Add API for selective bundle consistency check (Jackrabbit-specific)
    - 1.3: Applied patches by Alexander Klimetschek:
      jackrabbit-core.JCR-1428-print-node-path.patch
      jackrabbit-core.JCR-1428-test-improvement.patch

Modified:
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
    jackrabbit/branches/1.3/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/ConsistencyCheckTest.java

Modified: jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java?rev=637847&r1=637846&r2=637847&view=diff
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java (original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java Mon Mar 17 04:37:42 2008
@@ -42,6 +42,7 @@
 
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.jackrabbit.core.fs.local.LocalFileSystem;
@@ -53,6 +54,7 @@
 import org.apache.jackrabbit.core.persistence.bundle.util.ErrorHandling;
 import org.apache.jackrabbit.core.persistence.bundle.util.NodePropBundle;
 import org.apache.jackrabbit.core.persistence.bundle.util.StringIndex;
+import org.apache.jackrabbit.core.persistence.bundle.util.NodePropBundle.ChildNodeEntry;
 import org.apache.jackrabbit.core.persistence.util.BLOBStore;
 import org.apache.jackrabbit.core.persistence.util.FileSystemBLOBStore;
 import org.apache.jackrabbit.core.persistence.util.Serializer;
@@ -654,6 +656,76 @@
     }
     
     /**
+     * Helper method that returns the jcr path for a node bundle.
+     * 
+     * <p>
+     * Resolves the special root nodes (eg. <code>/jcr:system</code>). If a
+     * node cannot be found in the list of child nodes of its parent (ie. has no
+     * name), <code>{{missing}}</code> will be used instead.
+     * 
+     * @param id
+     *            NodeId for which the path should be displayed
+     * @param bundle
+     *            bundle for id, optional (if <code>null</code>, will be
+     *            loaded via given id)
+     * @return the path of the node identified by id, with namespaces not
+     *         resolved (eg. <code>{http://www.jcp.org/jcr/1.0}</code> instead
+     *         of <code>jcr:</code>)
+     * @throws ItemStateException
+     *             if loading one of the parent nodes failed
+     */
+    protected String getBundlePath(NodeId id, NodePropBundle bundle) throws ItemStateException {
+        // load bundle on demand
+        if (bundle == null) {
+            bundle = loadBundle(id);
+            if (bundle == null) {
+                return "{{missing}}";
+            }
+        }
+        
+        // check for the various special root nodes
+        if (id.equals(RepositoryImpl.VERSION_STORAGE_NODE_ID)) {
+            return "/jcr:system/jcr:versionStorage";
+        } else if (id.equals(RepositoryImpl.NODETYPES_NODE_ID)) {
+            return "/jcr:system/jcr:nodeTypes";
+        } else if (id.equals(RepositoryImpl.SYSTEM_ROOT_NODE_ID)) {
+            return "/jcr:system";
+        } else if (id.equals(RepositoryImpl.ROOT_NODE_ID)) {
+            return "";
+        } else if (bundle.getParentId() == null) {
+            return "";
+        } else if (bundle.getParentId().equals(id)) {
+            return "";
+        }
+        
+        // get the name of this bundle by looking at the parent
+        NodePropBundle parentBundle = loadBundle(bundle.getParentId());
+        if (parentBundle == null) {
+            return "{{missing}}";
+        }
+        
+        String name = "{{missing}}";
+        Iterator iter = parentBundle.getChildNodeEntries().iterator();
+        while (iter.hasNext()) {
+            ChildNodeEntry entry = (ChildNodeEntry) iter.next();
+            if (entry.getId().equals(id)) {
+                String uri = entry.getName().getNamespaceURI();
+                // hide the empty {}ĂŠnamespace if none is present
+                if (uri == null || uri.equals("")) {
+                    name = entry.getName().getLocalName();
+                } else {
+                    // pattern: {uri}localName
+                    name = entry.getName().toString();
+                }
+                break;
+            }
+        }
+        
+        // recursive call (building the path from right-to-left)
+        return getBundlePath(parentBundle.getId(), parentBundle) + "/" + name;
+    }
+
+    /**
      * Checks a single bundle for inconsistencies, ie. inexistent child nodes
      * and inexistent parents.
      * 
@@ -688,14 +760,14 @@
                 // analyze child node bundles
                 NodePropBundle child = loadBundle(entry.getId(), true);
                 if (child == null) {
-                    log.error("NodeState '" + id + "' references inexistent child '" + entry.getName() + "' with id '" + entry.getId() + "'");
+                    log.error("NodeState '" + getBundlePath(id, bundle) + "' ('" + id + "') references inexistent child '" + entry.getName() + "' with id '" + entry.getId() + "'");
                     missingChildren.add(entry);
                 } else {
                     NodeId cp = child.getParentId();
                     if (cp == null) {
-                        log.error("ChildNode has invalid parent uuid: <null>");
+                        log.error("ChildNode '" + entry.getName() + "' has invalid parent uuid: <null>");
                     } else if (!cp.equals(id)) {
-                        log.error("ChildNode has invalid parent uuid: '" + cp + "' (instead of '" + id + "')");
+                        log.error("ChildNode '" + entry.getName() + "' has invalid parent uuid: '" + cp + "' (instead of '" + id + "')");
                     }
                 }
             } catch (ItemStateException e) {
@@ -724,7 +796,7 @@
             log.error("Error reading node '" + parentId + "' (parent of '" + id + "'): " + e);
         }
     }
-
+    
     /**
      * {@inheritDoc}
      */

Modified: jackrabbit/branches/1.3/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/ConsistencyCheckTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/ConsistencyCheckTest.java?rev=637847&r1=637846&r2=637847&view=diff
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/ConsistencyCheckTest.java (original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/ConsistencyCheckTest.java Mon Mar 17 04:37:42 2008
@@ -170,7 +170,6 @@
         
         if (JCR_SYSTEM.equals(workspace)) {
             conn = DriverManager.getConnection(PROTOCOL + DIRECTORY.getPath() + VERSIONING_DB_PATH, props);
-            log.debug(conn.getMetaData().getURL());
         } else {
             String basePath = DIRECTORY.getPath() + File.separatorChar + "workspaces" + File.separatorChar;
             conn = DriverManager.getConnection(PROTOCOL + basePath + workspace + DB_PATH, props);
@@ -305,7 +304,7 @@
         session.save();
         node.checkin();
         
-        displayTree(session.getRootNode().getNode("jcr:system/jcr:versionStorage"));
+        //displayTree(session.getRootNode().getNode("jcr:system/jcr:versionStorage"));
         
         brokenVersion = "1.1";
         Version v = node.getVersionHistory().getVersion(brokenVersion);
@@ -439,6 +438,6 @@
     
     public void testRepositoryShutdown() {
         // last test, stop (not necessarily needed, but cleans up file system)
-        //deleteRepository();
+        deleteRepository();
     }
 }