You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2009/12/12 21:55:59 UTC
svn commit: r889976 - in
/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene:
IndexingQueue.java MultiIndex.java SearchIndex.java
Author: mreutegg
Date: Sat Dec 12 20:55:59 2009
New Revision: 889976
URL: http://svn.apache.org/viewvc?rev=889976&view=rev
Log:
JCR-2434: Occasional IndexingQueueTest failure
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueue.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueue.java?rev=889976&r1=889975&r2=889976&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueue.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueue.java Sat Dec 12 20:55:59 2009
@@ -17,11 +17,13 @@
package org.apache.jackrabbit.core.query.lucene;
import java.io.IOException;
-import java.util.Map;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.ArrayList;
+import java.util.Map;
+
+import javax.jcr.RepositoryException;
import org.apache.jackrabbit.core.id.NodeId;
import org.apache.lucene.document.Document;
@@ -30,8 +32,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.jcr.RepositoryException;
-
/**
* <code>IndexingQueue</code> implements a queue which contains all the
* documents with pending text extractor jobs.
@@ -150,7 +150,6 @@
queueStore.removeUUID(uuid);
log.debug("removed node {}. New size of indexing queue: {}",
uuid, pendingDocuments.size());
- notifyIfEmpty();
}
return doc;
}
@@ -190,7 +189,6 @@
it.remove();
}
queueStore.close();
- notifyIfEmpty();
}
/**
@@ -204,29 +202,6 @@
}
/**
- * Notifies all threads waiting for this queue to become empty.
- * The notification is only sent if this queue actually is empty.
- */
- private synchronized void notifyIfEmpty() {
- if (pendingDocuments.isEmpty()) {
- notifyAll();
- }
- }
-
- /**
- * Waits until this queue is empty.
- */
- synchronized void waitUntilEmpty() {
- while (!pendingDocuments.isEmpty()) {
- try {
- wait();
- } catch (InterruptedException e) {
- // Interrupted, check again if we're empty
- }
- }
- }
-
- /**
* Returns the number of pending documents.
*
* @return the number of the currently pending documents.
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=889976&r1=889975&r2=889976&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 Sat Dec 12 20:55:59 2009
@@ -204,6 +204,14 @@
private IndexingQueue indexingQueue;
/**
+ * Only used for testing purpose. Set to <code>true</code> after finished
+ * extraction jobs have been removed from the queue and set to
+ * <code>false</code> again after the affected nodes have been updated in
+ * the index.
+ */
+ private boolean indexingQueueCommitPending;
+
+ /**
* Identifiers of nodes that should not be indexed.
*/
private final Set<NodeId> excludedIDs;
@@ -1008,6 +1016,33 @@
}
}
+ //-------------------------< testing only >---------------------------------
+
+ void waitUntilIndexingQueueIsEmpty() {
+ IndexingQueue iq = getIndexingQueue();
+ synchronized (iq) {
+ while (iq.getNumPendingDocuments() > 0 || indexingQueueCommitPending) {
+ try {
+ log.info("waiting for indexing queue to become empty");
+ iq.wait();
+ log.info("notified");
+ } catch (InterruptedException e) {
+ // interrupted, check again if queue is empty
+ }
+ }
+ }
+ }
+
+ void notifyIfIndexingQueueIsEmpty() {
+ IndexingQueue iq = getIndexingQueue();
+ synchronized (iq) {
+ indexingQueueCommitPending = false;
+ if (iq.getNumPendingDocuments() == 0) {
+ iq.notifyAll();
+ }
+ }
+ }
+
//-------------------------< internal >-------------------------------------
/**
@@ -1286,27 +1321,38 @@
log.debug("updating index with {} nodes from indexing queue.",
finished.size());
- // remove documents from the queue
- for (NodeId id : finished.keySet()) {
- indexingQueue.removeDocument(id.toString());
+ // Only useful for testing
+ synchronized (getIndexingQueue()) {
+ indexingQueueCommitPending = true;
}
try {
- if (transactionPresent) {
- synchronized (this) {
- for (NodeId id : finished.keySet()) {
- executeAndLog(new DeleteNode(getTransactionId(), id));
- }
- for (Document document : finished.values()) {
- executeAndLog(new AddNode(getTransactionId(), document));
+ // remove documents from the queue
+ for (NodeId id : finished.keySet()) {
+ indexingQueue.removeDocument(id.toString());
+ }
+
+ try {
+ if (transactionPresent) {
+ synchronized (this) {
+ for (NodeId id : finished.keySet()) {
+ executeAndLog(new DeleteNode(getTransactionId(), id));
+ }
+ for (Document document : finished.values()) {
+ executeAndLog(new AddNode(getTransactionId(), document));
+ }
}
+ } else {
+ update(finished.keySet(), finished.values());
}
- } else {
- update(finished.keySet(), finished.values());
+ } catch (IOException e) {
+ // update failed
+ log.warn("Failed to update index with deferred text extraction", e);
}
- } catch (IOException e) {
- // update failed
- log.warn("Failed to update index with deferred text extraction", e);
+ } finally {
+ // the following method also resets
+ // indexingQueueCommitPending back to false
+ notifyIfIndexingQueueIsEmpty();
}
}
}
@@ -1930,6 +1976,7 @@
Document doc = index.indexingQueue.removeDocument(uuidString);
if (doc != null) {
Util.disposeDocument(doc);
+ index.notifyIfIndexingQueueIsEmpty();
}
Term idTerm = new Term(FieldNames.UUID, uuidString);
// if the document cannot be deleted from the volatile index
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=889976&r1=889975&r2=889976&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java Sat Dec 12 20:55:59 2009
@@ -744,11 +744,11 @@
*/
public void flush() throws RepositoryException {
try {
- index.getIndexingQueue().waitUntilEmpty();
+ index.waitUntilIndexingQueueIsEmpty();
index.flush();
// flush may have pushed nodes into the indexing queue
// -> wait again
- index.getIndexingQueue().waitUntilEmpty();
+ index.waitUntilIndexingQueueIsEmpty();
} catch (IOException e) {
throw new RepositoryException("Failed to flush the index", e);
}