Apache Lucene open-source search software
LUCENE-1703: add IndexWriter.waitForMerges
Michael McCandless629c7ed4c7f7
diff --git a/CHANGES.txt b/CHANGES.txtindex 57677416c64..8199c965add 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -262,6 +262,9 @@ API Changesof characters before tokenizers run. (Koji Sekiguchi via MikeMcCandless)+26. LUCENE-1703: Add IndexWriter.waitForMerges. (Tim Smith via Mike+ McCandless)+Bug fixes1. LUCENE-1415: MultiPhraseQuery has incorrect hashCode() and equals()diff --git a/src/java/org/apache/lucene/index/IndexWriter.java b/src/java/org/apache/lucene/index/IndexWriter.javaindex dd2d0febead..1f2851da8fc 100644--- a/src/java/org/apache/lucene/index/IndexWriter.java+++ b/src/java/org/apache/lucene/index/IndexWriter.java@@ -3286,19 +3286,34 @@ public class IndexWriter {message("all running merges have aborted");} else {- // Ensure any running addIndexes finishes. It's fine- // if a new one attempts to start because from our+ // waitForMerges() will ensure any running addIndexes finishes.+ // It's fine if a new one attempts to start because from our// caller above the call will see that we are in the// process of closing, and will throw an// AlreadyClosedException.- acquireRead();- releaseRead();- while(pendingMerges.size() > 0 || runningMerges.size() > 0)- doWait();- assert 0 == mergingSegments.size();+ waitForMerges();}}-++ /**+ * Wait for any currently outstanding merges to finish.+ *+ * <p>It is guaranteed that any merges started prior to calling this method+ * will have completed once this method completes.</p>+ */+ public synchronized void waitForMerges() {+ // Ensure any running addIndexes finishes.+ acquireRead();+ releaseRead();++ while(pendingMerges.size() > 0 || runningMerges.size() > 0) {+ doWait();+ }++ // sanity check+ assert 0 == mergingSegments.size();+ }+/** Called whenever the SegmentInfos has been updated and* the index files referenced exist (correctly) in the