From 57461996e2fe1a50444600df25fcb7224826fbf7 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 7 Nov 2011 20:14:23 +0000 Subject: [PATCH] LUCENE-3528: singal waiting threads even when IS#close throws an exception git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1198911 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/NRTManager.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/index/NRTManager.java b/lucene/contrib/misc/src/java/org/apache/lucene/index/NRTManager.java index 86cfcb8ac1a..6eeca996f92 100644 --- a/lucene/contrib/misc/src/java/org/apache/lucene/index/NRTManager.java +++ b/lucene/contrib/misc/src/java/org/apache/lucene/index/NRTManager.java @@ -51,6 +51,7 @@ import org.apache.lucene.util.ThreadInterruptedException; */ public class NRTManager implements Closeable { + private static final long MAX_SEARCHER_GEN = Long.MAX_VALUE; private final IndexWriter writer; private final SearcherManagerRef withoutDeletes; private final SearcherManagerRef withDeletes; @@ -275,6 +276,10 @@ public class NRTManager implements Closeable { // Mark gen as of when reopen started: final long newSearcherGen = indexingGen.getAndIncrement(); boolean setSearchGen = false; + if (reference.generation == MAX_SEARCHER_GEN) { + newGeneration.signalAll(); // wake up threads if we have a new generation + return false; + } if (!(setSearchGen = reference.manager.isSearcherCurrent())) { setSearchGen = reference.manager.maybeReopen(); } @@ -298,13 +303,17 @@ public class NRTManager implements Closeable { *

* NOTE: caller must separately close the writer. */ - public synchronized void close() throws IOException { + public void close() throws IOException { reopenLock.lock(); try { - IOUtils.close(withDeletes, withoutDeletes); - newGeneration.signalAll(); + try { + IOUtils.close(withDeletes, withoutDeletes); + } finally { // make sure we signal even if close throws an exception + newGeneration.signalAll(); + } } finally { reopenLock.unlock(); + assert withDeletes.generation == MAX_SEARCHER_GEN && withoutDeletes.generation == MAX_SEARCHER_GEN; } } @@ -339,7 +348,7 @@ public class NRTManager implements Closeable { } public void close() throws IOException { - generation = Long.MAX_VALUE; // max it out to make sure nobody can wait on another gen + generation = MAX_SEARCHER_GEN; // max it out to make sure nobody can wait on another gen manager.close(); } }