Author: epbernard
Date: 2010-07-20 05:16:49 -0400 (Tue, 20 Jul 2010)
New Revision: 19976
Modified:
search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/WorkQueue.java
search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
Log:
HSEARCH-540 Avoid performing the queue twice when nothing has changed
The double registration leads to double processing of the queue which can be avoided by a
flag.
Modified:
search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/WorkQueue.java
===================================================================
---
search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/WorkQueue.java 2010-07-20
09:16:13 UTC (rev 19975)
+++
search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/WorkQueue.java 2010-07-20
09:16:49 UTC (rev 19976)
@@ -42,8 +42,10 @@
private List<Work> queue;
private List<LuceneWork> sealedQueue;
- //is this class supposed to be
+ //flag indicating if the sealed data has be provided meaning that it should no longer be
modified
private boolean usedSealedData;
+ //flag indicating if data has been sealed and not modified since
+ private boolean sealedAndUnchanged;
public WorkQueue(int size) {
queue = new ArrayList<Work>(size);
@@ -53,6 +55,10 @@
this.queue = queue;
}
+ public boolean isSealedAndUnchanged() {
+ return sealedAndUnchanged;
+ }
+
public WorkQueue() {
this(10);
}
@@ -62,6 +68,7 @@
//something is wrong fail with exception
throw new AssertionFailure( "Attempting to add a work in a used sealed
queue" );
}
+ this.sealedAndUnchanged = false;
queue.add(work);
}
@@ -72,12 +79,13 @@
public WorkQueue splitQueue() {
WorkQueue subQueue = new WorkQueue( queue );
this.queue = new ArrayList<Work>( queue.size() );
+ this.sealedAndUnchanged = false;
return subQueue;
}
public List<LuceneWork> getSealedQueue() {
if (sealedQueue == null) throw new AssertionFailure("Access a Sealed WorkQueue
which has not been sealed");
- usedSealedData = true;
+ this.sealedAndUnchanged = false;
return sealedQueue;
}
@@ -93,11 +101,13 @@
* when the flush ordering is fixed, add the following line
* queue = Collections.EMPTY_LIST;
*/
+ this.sealedAndUnchanged = true;
this.sealedQueue = sealedQueue;
}
public void clear() {
queue.clear();
+ this.sealedAndUnchanged = false;
if (sealedQueue != null) sealedQueue.clear();
}
Modified:
search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
===================================================================
---
search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2010-07-20
09:16:13 UTC (rev 19975)
+++
search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2010-07-20
09:16:49 UTC (rev 19976)
@@ -134,19 +134,22 @@
}
public void prepareWorks(WorkQueue workQueue) {
- List<Work> queue = workQueue.getQueue();
- int initialSize = queue.size();
- List<LuceneWork> luceneQueue = new ArrayList<LuceneWork>( initialSize );
//TODO load factor for containedIn
- /**
- * Collection work type are process second, so if the owner entity has already been
processed for whatever reason
- * the work will be ignored.
- * However if the owner entity has not been processed, an "UPDATE" work is
executed
- *
- * Processing collection works last is mandatory to avoid reindexing a object to be
deleted
- */
- processWorkByLayer( queue, initialSize, luceneQueue, Layer.FIRST );
- processWorkByLayer( queue, initialSize, luceneQueue, Layer.SECOND );
- workQueue.setSealedQueue( optimize( luceneQueue ) );
+ final boolean alreadyProcessedAndUnchanged = workQueue.isSealedAndUnchanged();
+ if ( !alreadyProcessedAndUnchanged ) {
+ List<Work> queue = workQueue.getQueue();
+ int initialSize = queue.size();
+ List<LuceneWork> luceneQueue = new ArrayList<LuceneWork>( initialSize );
//TODO load factor for containedIn
+ /**
+ * Collection work type are process second, so if the owner entity has already been
processed for whatever reason
+ * the work will be ignored.
+ * However if the owner entity has not been processed, an "UPDATE" work is
executed
+ *
+ * Processing collection works last is mandatory to avoid reindexing a object to be
deleted
+ */
+ processWorkByLayer( queue, initialSize, luceneQueue, Layer.FIRST );
+ processWorkByLayer( queue, initialSize, luceneQueue, Layer.SECOND );
+ workQueue.setSealedQueue( optimize( luceneQueue ) );
+ }
}
private List<LuceneWork> optimize(List<LuceneWork> luceneQueue) {
Show replies by date