Skip to content

Apache Lucene open-source search software

LUCENE-6205: don't let doc values updates write in one thread at the same time as a merge kicking off in another

Michael McCandless9d5d43ff8661
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 394aff722f8..f455a67aee2 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -470,6 +470,10 @@ Bug Fixes
* LUCENE-6173: NumericTermAttribute and spatial/CellTokenStream do not clone
their BytesRef(Builder)s. Also equals/hashCode was missing. (Uwe Schindler)
+
+* LUCENE-6205: Fixed intermittent concurrency issue that could cause
+ FileNotFoundException when writing doc values updates at the same
+ time that a merge kicks off. (Mike McCandless)
Documentation
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
index 73a40af89f6..7b791dfda00 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
@@ -3927,7 +3927,14 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
// fix the reader's live docs and del count
assert delCount > reader.numDeletedDocs(); // beware of zombies
- SegmentReader newReader = new SegmentReader(info, reader, liveDocs, info.info.getDocCount() - delCount);
+ SegmentReader newReader;
+
+ synchronized (this) {
+ // We must also sync on IW here, because another thread could be writing
+ // new DV updates / remove old gen field infos files causing FNFE:
+ newReader = new SegmentReader(info, reader, liveDocs, info.info.getDocCount() - delCount);
+ }
+
boolean released = false;
try {
rld.release(reader);