jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r648691 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ query/ query/lucene/
Date Wed, 16 Apr 2008 13:32:15 GMT
Author: mreutegg
Date: Wed Apr 16 06:32:11 2008
New Revision: 648691

URL: http://svn.apache.org/viewvc?rev=648691&view=rev
Log:
JCR-1492: Make behaviour configurable when re-indexing detects workspace inconsistency

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/OnWorkspaceInconsistency.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java

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=648691&r1=648690&r2=648691&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
Wed Apr 16 06:32:11 2008
@@ -657,7 +657,7 @@
                 SystemSession defSysSession = getSystemSession(wspName);
                 systemSearchMgr = new SearchManager(repConfig.getSearchConfig(),
                         nsReg, ntReg, defSysSession.getItemStateManager(),
-                        SYSTEM_ROOT_NODE_ID, null, null);
+                        vMgr.getPersistenceManager(), SYSTEM_ROOT_NODE_ID, null, null);
                 ObservationManager obsMgr = defSysSession.getWorkspace().getObservationManager();
                 obsMgr.addEventListener(systemSearchMgr, Event.NODE_ADDED
                         | Event.NODE_REMOVED | Event.PROPERTY_ADDED
@@ -1714,6 +1714,7 @@
                             nsReg,
                             ntReg,
                             itemStateMgr,
+                            persistMgr,
                             rootNodeId,
                             getSystemSearchManager(getName()),
                             SYSTEM_ROOT_NODE_ID);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java?rev=648691&r1=648690&r2=648691&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
Wed Apr 16 06:32:11 2008
@@ -31,6 +31,7 @@
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.NodeStateIterator;
+import org.apache.jackrabbit.core.persistence.PersistenceManager;
 import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
 import org.apache.jackrabbit.spi.commons.query.jsr283.qom.QueryObjectModel;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
@@ -115,6 +116,11 @@
     private final ItemStateManager itemMgr;
 
     /**
+     * The underlying persistence manager.
+     */
+    private final PersistenceManager pm;
+
+    /**
      * Storage for search index
      */
     private final FileSystem fs;
@@ -160,22 +166,24 @@
     /**
      * Creates a new <code>SearchManager</code>.
      *
-     * @param config the search configuration.
-     * @param nsReg            the namespace registry.
-     * @param ntReg the node type registry.
-     * @param itemMgr the shared item state manager.
+     * @param config         the search configuration.
+     * @param nsReg          the namespace registry.
+     * @param ntReg          the node type registry.
+     * @param itemMgr        the shared item state manager.
+     * @param pm             the underlying persistence manager.
      * @param rootNodeId     the id of the root node.
-     * @param parentMgr        the parent search manager or <code>null</code>
if
-     *                         there is no parent search manager.
+     * @param parentMgr      the parent search manager or <code>null</code> if
+     *                       there is no parent search manager.
      * @param excludedNodeId id of the node that should be excluded from
-     *                         indexing. Any descendant of that node will also
-     *                         be excluded from indexing.
+     *                       indexing. Any descendant of that node will also be
+     *                       excluded from indexing.
      * @throws RepositoryException if the search manager cannot be initialized
      */
     public SearchManager(SearchConfig config,
                          final NamespaceRegistryImpl nsReg,
                          NodeTypeRegistry ntReg,
                          ItemStateManager itemMgr,
+                         PersistenceManager pm,
                          NodeId rootNodeId,
                          SearchManager parentMgr,
                          NodeId excludedNodeId) throws RepositoryException {
@@ -188,6 +196,7 @@
         this.ntReg = ntReg;
         this.nsReg = nsReg;
         this.itemMgr = itemMgr;
+        this.pm = pm;
         this.rootNodeId = rootNodeId;
         this.parentHandler = (parentMgr != null) ? parentMgr.handler : null;
         this.excludedNodeId = excludedNodeId;
@@ -505,7 +514,7 @@
         try {
             handler = (QueryHandler) config.newInstance();
             QueryHandlerContext context
-                    = new QueryHandlerContext(fs, itemMgr, rootNodeId,
+                    = new QueryHandlerContext(fs, itemMgr, pm, rootNodeId,
                             ntReg, nsReg, parentHandler, excludedNodeId);
             handler.init(context);
         } catch (Exception e) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java?rev=648691&r1=648690&r2=648691&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java
Wed Apr 16 06:32:11 2008
@@ -17,13 +17,9 @@
 package org.apache.jackrabbit.core.query;
 
 import org.apache.jackrabbit.core.NodeIdIterator;
-import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.core.ItemManager;
 import org.apache.jackrabbit.core.state.NodeStateIterator;
-import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
 
 import javax.jcr.RepositoryException;
-import javax.jcr.query.InvalidQueryException;
 import java.io.IOException;
 
 /**
@@ -37,6 +33,11 @@
     private QueryHandlerContext context;
 
     /**
+     * The {@link OnWorkspaceInconsistency} handler. Defaults to 'fail'.
+     */
+    private OnWorkspaceInconsistency owi = OnWorkspaceInconsistency.FAIL;
+
+    /**
      * Initializes this query handler by setting all properties in this class
      * with appropriate parameter values.
      *
@@ -64,7 +65,7 @@
     }
 
     /**
-     * This default implementation calls the individual {@link #deleteNode(NodeId)}
+     * This default implementation calls the individual {@link #deleteNode(org.apache.jackrabbit.core.NodeId)}
      * and {@link #addNode(org.apache.jackrabbit.core.state.NodeState)} methods
      * for each entry in the iterators. First the nodes to remove are processed
      * then the nodes to add.
@@ -82,5 +83,34 @@
         while (add.hasNext()) {
             addNode(add.nextNodeState());
         }
+    }
+
+    /**
+     * @return the {@link OnWorkspaceInconsistency} handler.
+     */
+    public OnWorkspaceInconsistency getOnWorkspaceInconsistencyHandler() {
+        return owi;
+    }
+
+    //--------------------------< properties >----------------------------------
+
+    /**
+     * Sets the {@link OnWorkspaceInconsistency} handler with the given name.
+     * Currently the only valid name is:
+     * <ul>
+     * <li><code>fail</code></li>
+     * </ul>
+     *
+     * @param name the name of a {@link OnWorkspaceInconsistency} handler.
+     */
+    public void setOnWorkspaceInconsistency(String name) {
+        owi = OnWorkspaceInconsistency.fromString(name);
+    }
+
+    /**
+     * @return the name of the currently set {@link OnWorkspaceInconsistency}.
+     */
+    public String getOnWorkspaceInconsistency() {
+        return owi.getName();
     }
 }

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/OnWorkspaceInconsistency.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/OnWorkspaceInconsistency.java?rev=648691&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/OnWorkspaceInconsistency.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/OnWorkspaceInconsistency.java
Wed Apr 16 06:32:11 2008
@@ -0,0 +1,135 @@
+/*
+ * 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.query;
+
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NoSuchItemStateException;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+
+import javax.jcr.RepositoryException;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * <code>OnWorkspaceInconsistency</code> defines an interface to handle
+ * workspace inconsistencies.
+ */
+public abstract class OnWorkspaceInconsistency {
+
+    /**
+     * Logger instance for this class.
+     */
+    private static final Logger log = LoggerFactory.getLogger(OnWorkspaceInconsistency.class);
+
+    /**
+     * An handler that simply logs the path of the parent node and the name
+     * of the missing child node and then re-throws the exception.
+     */
+    public static final OnWorkspaceInconsistency FAIL = new OnWorkspaceInconsistency("fail")
{
+
+        public void handleMissingChildNode(NoSuchItemStateException exception,
+                                           QueryHandler handler,
+                                           Path path,
+                                           NodeState node,
+                                           NodeState.ChildNodeEntry child)
+                throws RepositoryException, ItemStateException {
+            NamePathResolver resolver = new DefaultNamePathResolver(
+                    handler.getContext().getNamespaceRegistry());
+            log.error("Node {} ({}) has missing child '{}' ({})",
+                    new Object[]{
+                        resolver.getJCRPath(path),
+                        node.getNodeId().getUUID().toString(),
+                        resolver.getJCRName(child.getName()),
+                        child.getId().getUUID().toString()
+                    });
+            throw exception;
+        }
+    };
+
+    protected static final Map INSTANCES = new HashMap();
+
+    static {
+        INSTANCES.put(FAIL.name, FAIL);
+    }
+
+    /**
+     * The name of the {@link OnWorkspaceInconsistency} handler.
+     */
+    private final String name;
+
+    /**
+     * Private constructor.
+     */
+    private OnWorkspaceInconsistency(String name) {
+        this.name = name;
+    }
+
+    /**
+     * @return the name of this {@link OnWorkspaceInconsistency}.
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Returns the {@link OnWorkspaceInconsistency} with the given
+     * <code>name</code>.
+     *
+     * @param name the name of a {@link OnWorkspaceInconsistency}.
+     * @return the {@link OnWorkspaceInconsistency} with the given
+     *         <code>name</code>.
+     * @throws IllegalArgumentException if <code>name</code> is not a well-known
+     *                                  {@link OnWorkspaceInconsistency} name.
+     */
+    public static OnWorkspaceInconsistency fromString(String name)
+            throws IllegalArgumentException {
+        OnWorkspaceInconsistency handler = (OnWorkspaceInconsistency) INSTANCES.get(name.toLowerCase());
+        if (handler == null) {
+            throw new IllegalArgumentException("Unknown name: " + name);
+        } else {
+            return handler;
+        }
+    }
+
+    /**
+     * Handle a missing child node state.
+     *
+     * @param exception the exception that was thrown when the query handler
+     *                  tried to load the child node state.
+     * @param handler   the query handler.
+     * @param path      the path of the parent node.
+     * @param node      the parent node state.
+     * @param child     the child node entry, for which no node state could be
+     *                  found.
+     * @throws ItemStateException  if an error occurs while handling the missing
+     *                             child node state. This may also be the passed
+     *                             <code>exception</code> instance.
+     * @throws RepositoryException if another error occurs not related to item
+     *                             state reading.
+     */
+    public abstract void handleMissingChildNode(NoSuchItemStateException exception,
+                                                QueryHandler handler,
+                                                Path path,
+                                                NodeState node,
+                                                NodeState.ChildNodeEntry child)
+            throws ItemStateException, RepositoryException;
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/OnWorkspaceInconsistency.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java?rev=648691&r1=648690&r2=648691&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
Wed Apr 16 06:32:11 2008
@@ -21,6 +21,7 @@
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.NamespaceRegistryImpl;
+import org.apache.jackrabbit.core.persistence.PersistenceManager;
 
 /**
  * Acts as an argument for the {@link QueryHandler} to keep the interface
@@ -40,6 +41,11 @@
     private final ItemStateManager stateMgr;
 
     /**
+     * The underlying persistence manager.
+     */
+    private final PersistenceManager pm;
+
+    /**
      * The node type registry of the repository
      */
     private final NodeTypeRegistry ntRegistry;
@@ -77,6 +83,7 @@
      *                         <code>FileSystem</code> has been configured
      *                         <code>fs</code> is <code>null</code>.
      * @param stateMgr         provides persistent item states.
+     * @param pm               the underlying persistence manager.
      * @param rootId           the id of the root node.
      * @param ntRegistry       the node type registry.
      * @param nsRegistry       the namespace registry.
@@ -88,6 +95,7 @@
      */
     public QueryHandlerContext(FileSystem fs,
                                ItemStateManager stateMgr,
+                               PersistenceManager pm,
                                NodeId rootId,
                                NodeTypeRegistry ntRegistry,
                                NamespaceRegistryImpl nsRegistry,
@@ -95,6 +103,7 @@
                                NodeId excludedNodeId) {
         this.fs = fs;
         this.stateMgr = stateMgr;
+        this.pm = pm;
         this.rootId = rootId;
         this.ntRegistry = ntRegistry;
         this.nsRegistry = nsRegistry;
@@ -113,6 +122,13 @@
      */
     public ItemStateManager getItemStateManager() {
         return stateMgr;
+    }
+
+    /**
+     * @return the underlying persistence manager.
+     */
+    public PersistenceManager getPersistenceManager() {
+        return pm;
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=648691&r1=648690&r2=648691&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
Wed Apr 16 06:32:11 2008
@@ -29,8 +29,6 @@
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.PathFactory;
 import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
-import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
-import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.lucene.document.Document;
@@ -1042,20 +1040,12 @@
             NodeState.ChildNodeEntry child = (NodeState.ChildNodeEntry) it.next();
             Path childPath = PATH_FACTORY.create(path, child.getName(),
                     child.getIndex(), false);
-            NodeState childState;
+            NodeState childState = null;
             try {
                 childState = (NodeState) stateMgr.getItemState(child.getId());
             } catch (NoSuchItemStateException e) {
-                NamePathResolver resolver = new DefaultNamePathResolver(
-                        handler.getContext().getNamespaceRegistry());
-                log.error("Node {} ({}) has missing child '{}' ({})",
-                        new Object[]{
-                            resolver.getJCRPath(path),
-                            node.getNodeId().getUUID().toString(),
-                            resolver.getJCRName(child.getName()),
-                            child.getId().getUUID().toString()
-                        });
-                throw e;
+                handler.getOnWorkspaceInconsistencyHandler().handleMissingChildNode(
+                        e, handler, path, node, child);
             }
             if (childState != null) {
                 createIndex(childState, childPath, stateMgr);



Mime
View raw message