Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 25104 invoked from network); 15 Jan 2007 10:32:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Jan 2007 10:32:27 -0000 Received: (qmail 61406 invoked by uid 500); 15 Jan 2007 10:32:33 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 61376 invoked by uid 500); 15 Jan 2007 10:32:33 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 61367 invoked by uid 99); 15 Jan 2007 10:32:33 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Jan 2007 02:32:33 -0800 X-ASF-Spam-Status: No, hits=-8.6 required=10.0 tests=ALL_TRUSTED,INFO_TLD,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Jan 2007 02:32:25 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 9FF501A981D; Mon, 15 Jan 2007 02:31:22 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r496271 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ cluster/ observation/ query/lucene/ Date: Mon, 15 Jan 2007 10:31:22 -0000 To: commits@jackrabbit.apache.org From: dpfister@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070115103122.9FF501A981D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dpfister Date: Mon Jan 15 02:31:21 2007 New Revision: 496271 URL: http://svn.apache.org/viewvc?view=rev&rev=496271 Log: JCR-708: SearchManager might throw when handling cluster event Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/AbstractJournal.java jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileRevision.java jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.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/SearchManager.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java?view=diff&rev=496271&r1=496270&r2=496271 ============================================================================== --- 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 Mon Jan 15 02:31:21 2007 @@ -50,6 +50,8 @@ import java.util.NoSuchElementException; import java.util.Properties; import java.util.Set; +import java.util.Map; +import java.util.HashMap; /** * Acts as a global entry point to execute queries and index nodes. @@ -283,7 +285,7 @@ // nodes that need to be removed from the index. final Set removedNodes = new HashSet(); // nodes that need to be added to the index. - final Set addedNodes = new HashSet(); + final Map addedNodes = new HashMap(); // property events List propEvents = new ArrayList(); @@ -298,7 +300,7 @@ } long type = e.getType(); if (type == Event.NODE_ADDED) { - addedNodes.add(e.getChildId()); + addedNodes.put(e.getChildId(), e); } else if (type == Event.NODE_REMOVED) { removedNodes.add(e.getChildId()); } else { @@ -308,29 +310,29 @@ // sort out property events for (int i = 0; i < propEvents.size(); i++) { - EventImpl event = (EventImpl) propEvents.get(i); - NodeId nodeId = event.getParentId(); - if (event.getType() == Event.PROPERTY_ADDED) { - if (addedNodes.add(nodeId)) { + EventImpl e = (EventImpl) propEvents.get(i); + NodeId nodeId = e.getParentId(); + if (e.getType() == Event.PROPERTY_ADDED) { + if (addedNodes.put(nodeId, e) == null) { // only property added // need to re-index removedNodes.add(nodeId); } else { // the node where this prop belongs to is also new } - } else if (event.getType() == Event.PROPERTY_CHANGED) { + } else if (e.getType() == Event.PROPERTY_CHANGED) { // need to re-index - addedNodes.add(nodeId); + addedNodes.put(nodeId, e); removedNodes.add(nodeId); } else { // property removed event is only generated when node still exists - addedNodes.add(nodeId); + addedNodes.put(nodeId, e); removedNodes.add(nodeId); } } NodeStateIterator addedStates = new NodeStateIterator() { - private final Iterator iter = addedNodes.iterator(); + private final Iterator iter = addedNodes.keySet().iterator(); public void remove() { throw new UnsupportedOperationException(); @@ -349,8 +351,15 @@ NodeId id = (NodeId) iter.next(); try { item = (NodeState) itemMgr.getItemState(id); - } catch (ItemStateException e) { - log.error("Unable to index node " + id + ": does not exist"); + } catch (ItemStateException ise) { + // check whether this item state change originated from + // an external event + EventImpl e = (EventImpl) addedNodes.get(id); + if (e == null || !e.isExternal()) { + log.error("Unable to index node " + id + ": does not exist"); + } else { + log.info("Node no longer available " + id + ", skipped."); + } } return item; } Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/AbstractJournal.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/AbstractJournal.java?view=diff&rev=496271&r1=496270&r2=496271 ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/AbstractJournal.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/AbstractJournal.java Mon Jan 15 02:31:21 2007 @@ -577,19 +577,19 @@ switch (type) { case Event.NODE_ADDED: return EventState.childNodeAdded(parentId, parentPath, childId, childRelPath, - ntName, mixins, getOrCreateSession(userId)); + ntName, mixins, getOrCreateSession(userId), true); case Event.NODE_REMOVED: return EventState.childNodeRemoved(parentId, parentPath, childId, childRelPath, - ntName, mixins, getOrCreateSession(userId)); + ntName, mixins, getOrCreateSession(userId), true); case Event.PROPERTY_ADDED: return EventState.propertyAdded(parentId, parentPath, childRelPath, - ntName, mixins, getOrCreateSession(userId)); + ntName, mixins, getOrCreateSession(userId), true); case Event.PROPERTY_CHANGED: return EventState.propertyChanged(parentId, parentPath, childRelPath, - ntName, mixins, getOrCreateSession(userId)); + ntName, mixins, getOrCreateSession(userId), true); case Event.PROPERTY_REMOVED: return EventState.propertyRemoved(parentId, parentPath, childRelPath, - ntName, mixins, getOrCreateSession(userId)); + ntName, mixins, getOrCreateSession(userId), true); default: String msg = "Unexpected event type: " + type; throw new IllegalArgumentException(msg); Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileRevision.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileRevision.java?view=diff&rev=496271&r1=496270&r2=496271 ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileRevision.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileRevision.java Mon Jan 15 02:31:21 2007 @@ -113,11 +113,13 @@ } lock = null; - try { - raf.close(); - } catch (IOException e) { - String msg = "I/O error while closing file: " + e.getMessage(); - log.warn(msg); + if (raf != null) { + try { + raf.close(); + } catch (IOException e) { + String msg = "I/O error while closing file: " + e.getMessage(); + log.warn(msg); + } } raf = null; } Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java?view=diff&rev=496271&r1=496270&r2=496271 ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java Mon Jan 15 02:31:21 2007 @@ -127,6 +127,16 @@ } /** + * Return a flag indicating whether this is an externally generated event. + * + * @return true if this is an external event; + * false otherwise + */ + public boolean isExternal() { + return eventState.isExternal(); + } + + /** * Returns a String representation of this Event. * * @return a String representation of this Event. Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java?view=diff&rev=496271&r1=496270&r2=496271 ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java Mon Jan 15 02:31:21 2007 @@ -105,6 +105,12 @@ * Cached hashCode value for this Event. */ private int hashCode; + + /** + * Flag indicating whether this is an external event, e.g. originating from + * another node in a clustered environment. + */ + private final boolean external; /** * Creates a new EventState instance. @@ -123,14 +129,10 @@ * @param mixins mixins assigned to the parent node. * @param session the {@link javax.jcr.Session} that caused this event. */ - private EventState(int type, - NodeId parentId, - Path parentPath, - NodeId childId, - Path.PathElement childPath, - QName nodeType, - Set mixins, - Session session) { + private EventState(int type, NodeId parentId, Path parentPath, + NodeId childId, Path.PathElement childPath, QName nodeType, + Set mixins, Session session, boolean external) { + int mask = (Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED); if ((type & mask) > 0) { if (childId != null) { @@ -149,6 +151,7 @@ this.nodeType = nodeType; this.mixins = mixins; this.session = session; + this.external = external; } //-----------------< factory methods >-------------------------------------- @@ -175,18 +178,42 @@ QName nodeType, Set mixins, Session session) { - return new EventState(Event.NODE_ADDED, - parentId, - parentPath, - childId, - childPath, - nodeType, - mixins, - session); + + return childNodeAdded(parentId, parentPath, childId, + childPath, nodeType, mixins, session, false); } /** * Creates a new {@link javax.jcr.observation.Event} of type + * {@link javax.jcr.observation.Event#NODE_ADDED}. + * + * @param parentId the id of the parent node associated with + * this EventState. + * @param parentPath the path of the parent node associated with + * this EventState. + * @param childId the id of the child node associated with this event. + * @param childPath the relative path of the child node that was added. + * @param nodeType the node type of the parent node. + * @param mixins mixins assigned to the parent node. + * @param session the session that added the node. + * @param external flag indicating whether this is an external event + * @return an EventState instance. + */ + public static EventState childNodeAdded(NodeId parentId, + Path parentPath, + NodeId childId, + Path.PathElement childPath, + QName nodeType, + Set mixins, + Session session, + boolean external) { + + return new EventState(Event.NODE_ADDED, parentId, parentPath, + childId, childPath, nodeType, mixins, session, external); + } + + /** + * Creates a new {@link javax.jcr.observation.Event} of type * {@link javax.jcr.observation.Event#NODE_REMOVED}. * * @param parentId the id of the parent node associated with @@ -207,18 +234,42 @@ QName nodeType, Set mixins, Session session) { - return new EventState(Event.NODE_REMOVED, - parentId, - parentPath, - childId, - childPath, - nodeType, - mixins, - session); + + return childNodeRemoved(parentId, parentPath, childId, + childPath, nodeType, mixins, session, false); } /** * Creates a new {@link javax.jcr.observation.Event} of type + * {@link javax.jcr.observation.Event#NODE_REMOVED}. + * + * @param parentId the id of the parent node associated with + * this EventState. + * @param parentPath the path of the parent node associated with + * this EventState. + * @param childId the id of the child node associated with this event. + * @param childPath the relative path of the child node that was removed. + * @param nodeType the node type of the parent node. + * @param mixins mixins assigned to the parent node. + * @param session the session that removed the node. + * @param external flag indicating whether this is an external event + * @return an EventState instance. + */ + public static EventState childNodeRemoved(NodeId parentId, + Path parentPath, + NodeId childId, + Path.PathElement childPath, + QName nodeType, + Set mixins, + Session session, + boolean external) { + + return new EventState(Event.NODE_REMOVED, parentId, parentPath, + childId, childPath, nodeType, mixins, session, external); + } + + /** + * Creates a new {@link javax.jcr.observation.Event} of type * {@link javax.jcr.observation.Event#PROPERTY_ADDED}. * * @param parentId the id of the parent node associated with @@ -237,14 +288,36 @@ QName nodeType, Set mixins, Session session) { - return new EventState(Event.PROPERTY_ADDED, - parentId, - parentPath, - null, - childPath, - nodeType, - mixins, - session); + + return propertyAdded(parentId, parentPath, childPath, + nodeType, mixins, session, false); + } + + /** + * Creates a new {@link javax.jcr.observation.Event} of type + * {@link javax.jcr.observation.Event#PROPERTY_ADDED}. + * + * @param parentId the id of the parent node associated with + * this EventState. + * @param parentPath the path of the parent node associated with + * this EventState. + * @param childPath the relative path of the property that was added. + * @param nodeType the node type of the parent node. + * @param mixins mixins assigned to the parent node. + * @param session the session that added the property. + * @param external flag indicating whether this is an external event + * @return an EventState instance. + */ + public static EventState propertyAdded(NodeId parentId, + Path parentPath, + Path.PathElement childPath, + QName nodeType, + Set mixins, + Session session, + boolean external) { + + return new EventState(Event.PROPERTY_ADDED, parentId, parentPath, + null, childPath, nodeType, mixins, session, external); } /** @@ -267,14 +340,36 @@ QName nodeType, Set mixins, Session session) { - return new EventState(Event.PROPERTY_REMOVED, - parentId, - parentPath, - null, - childPath, - nodeType, - mixins, - session); + + return propertyRemoved(parentId, parentPath, childPath, + nodeType, mixins, session, false); + } + + /** + * Creates a new {@link javax.jcr.observation.Event} of type + * {@link javax.jcr.observation.Event#PROPERTY_REMOVED}. + * + * @param parentId the id of the parent node associated with + * this EventState. + * @param parentPath the path of the parent node associated with + * this EventState. + * @param childPath the relative path of the property that was removed. + * @param nodeType the node type of the parent node. + * @param mixins mixins assigned to the parent node. + * @param session the session that removed the property. + * @param external flag indicating whether this is an external event + * @return an EventState instance. + */ + public static EventState propertyRemoved(NodeId parentId, + Path parentPath, + Path.PathElement childPath, + QName nodeType, + Set mixins, + Session session, + boolean external) { + + return new EventState(Event.PROPERTY_REMOVED, parentId, parentPath, + null, childPath, nodeType, mixins, session, external); } /** @@ -297,14 +392,36 @@ QName nodeType, Set mixins, Session session) { - return new EventState(Event.PROPERTY_CHANGED, - parentId, - parentPath, - null, - childPath, - nodeType, - mixins, - session); + + return propertyChanged(parentId, parentPath, childPath, + nodeType, mixins, session, false); + } + + /** + * Creates a new {@link javax.jcr.observation.Event} of type + * {@link javax.jcr.observation.Event#PROPERTY_CHANGED}. + * + * @param parentId the id of the parent node associated with + * this EventState. + * @param parentPath the path of the parent node associated with + * this EventState. + * @param childPath the relative path of the property that changed. + * @param nodeType the node type of the parent node. + * @param mixins mixins assigned to the parent node. + * @param session the session that changed the property. + * @param external flag indicating whether this is an external event + * @return an EventState instance. + */ + public static EventState propertyChanged(NodeId parentId, + Path parentPath, + Path.PathElement childPath, + QName nodeType, + Set mixins, + Session session, + boolean external) { + + return new EventState(Event.PROPERTY_CHANGED, parentId, parentPath, + null, childPath, nodeType, mixins, session, external); } /** @@ -432,6 +549,16 @@ // node event return childId; } + } + + /** + * Return a flag indicating whether this is an externally generated event. + * + * @return true if this is an external event; + * false otherwise + */ + boolean isExternal() { + return external; } /** 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?view=diff&rev=496271&r1=496270&r2=496271 ============================================================================== --- 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 Mon Jan 15 02:31:21 2007 @@ -316,9 +316,11 @@ } while (add.hasNext()) { NodeIndexer nodeIdx = (NodeIndexer) add.next(); - executeAndLog(new AddNode(transactionId, nodeIdx)); - // commit volatile index if needed - flush |= checkVolatileCommit(); + if (nodeIdx != null) { + executeAndLog(new AddNode(transactionId, nodeIdx)); + // commit volatile index if needed + flush |= checkVolatileCommit(); + } } executeAndLog(new Commit(transactionId));