From e8d88a5b54b268b370f4bbc6f8a61148a62067c9 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 8 May 2019 11:19:21 +0200 Subject: [PATCH] LUCENE-8785: Ensure threadstates are locked before iterating (#664) Ensure new threadstates are locked before retrieving the number of active threadstates. This causes assertion errors and potentially broken field attributes in the IndexWriter when IndexWriter#deleteAll is called while actively indexing. --- lucene/CHANGES.txt | 6 +++++- .../src/java/org/apache/lucene/index/DocumentsWriter.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 33e83aa30fb..33223e30a79 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -452,7 +452,11 @@ Optimizations (Toke Eskildsen, Adrien Grand) ======================= Lucene 7.7.1 ======================= -(No Changes) +Bug fixes: + +* LUCENE-8785: Ensure new threadstates are locked before retrieving the number of active threadstates. + This causes assertion errors and potentially broken field attributes in the IndexWriter when + IndexWriter#deleteAll is called while actively indexing. (Simon Willnauer) ======================= Lucene 7.7.0 ======================= diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java index 6b7233380e6..fd4f3f65f1e 100644 --- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java @@ -287,8 +287,8 @@ final class DocumentsWriter implements Closeable, Accountable { }; try { deleteQueue.clear(); - final int limit = perThreadPool.getMaxThreadStates(); perThreadPool.lockNewThreadStates(); + final int limit = perThreadPool.getMaxThreadStates(); for (int i = 0; i < limit; i++) { final ThreadState perThread = perThreadPool.getThreadState(i); perThread.lock();