From 7c704d5258b3be8c383ccb96bf4a30be441f091c Mon Sep 17 00:00:00 2001 From: Mike McCandless Date: Wed, 5 Jul 2017 16:53:05 -0400 Subject: [PATCH] LUCENE-7868: fix race condition when reader pooling is disabled --- .../core/src/java/org/apache/lucene/index/IndexWriter.java | 2 +- .../java/org/apache/lucene/index/ReadersAndUpdates.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) 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 c2cded7ae4f..05608b48d66 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java @@ -3758,7 +3758,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable { // and re-resolve against the newly merged segment: Map> mergingDVUpdates = rld.getMergingDVUpdates(); - for (Map.Entry> ent : mergingDVUpdates.entrySet()) { String field = ent.getKey(); @@ -4356,6 +4355,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable { // Hold onto the "live" reader; we will use this to // commit merged deletes final ReadersAndUpdates rld = readerPool.get(info, true); + rld.setIsMerging(); SegmentReader reader = rld.getReaderForMerge(context); int delCount = reader.numDeletedDocs(); diff --git a/lucene/core/src/java/org/apache/lucene/index/ReadersAndUpdates.java b/lucene/core/src/java/org/apache/lucene/index/ReadersAndUpdates.java index dd49fcb9437..0e322562268 100644 --- a/lucene/core/src/java/org/apache/lucene/index/ReadersAndUpdates.java +++ b/lucene/core/src/java/org/apache/lucene/index/ReadersAndUpdates.java @@ -811,9 +811,10 @@ class ReadersAndUpdates { synchronized public void setIsMerging() { // This ensures any newly resolved doc value updates while we are merging are // saved for re-applying after this segment is done merging: - isMerging = true; - - assert mergingDVUpdates.isEmpty(); + if (isMerging == false) { + isMerging = true; + assert mergingDVUpdates.isEmpty(); + } } /** Returns a reader for merge, with the latest doc values updates and deletions. */