Skip to content

Apache Lucene open-source search software

add comment

Michael McCandless9f973b6988e8
diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.java
index a3baa2e2b37..2833f6533df 100644
--- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java
@@ -4401,6 +4401,15 @@ public class IndexWriter implements Closeable {
if (mergeDocStores && !merge.mergeDocStores) {
merge.mergeDocStores = true;
synchronized(this) {
+
+ // If 1) we must now merge doc stores, and 2) at
+ // least one of the segments we are merging uses
+ // the doc store we are now writing to, we must at
+ // this point force this doc store closed (by
+ // calling flush). If we didn't do this then the
+ // readers will attempt to open an IndexInput
+ // on files that have still-open IndexOutputs
+ // against them:
if (dss.contains(docWriter.getDocStoreSegment())) {
if (infoStream != null)
message("now flush at mergeMiddle");