Apache Lucene open-source search software
LUCENE-2618: allow optimize to complete during IW.close, take 2
Michael McCandless82126d534143
diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.javaindex 4e892c9d720..0a90a1889b0 100644--- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java@@ -1064,6 +1064,12 @@ public class IndexWriter implements Closeable {boolean success = false;+ // TODO: we should check whether this index is too old,+ // and throw an IndexFormatTooOldExc up front, here,+ // instead of later when merge, applyDeletes, getReader+ // is attempted. I think to do this we should store the+ // oldest segment's version in segments_N.+try {if (create) {// Try to read first. This is to allow create@@ -3662,7 +3668,7 @@ public class IndexWriter implements Closeable {// This merge (and, generally, any change to the// segments) may now enable new merges, so we call// merge policy & update pending merges.- if (success && !merge.isAborted() && !closed && !closing) {+ if (success && !merge.isAborted() && (merge.optimize || (!closed && !closing))) {updatePendingMerges(merge.maxNumSegmentsOptimize, merge.optimize);}}diff --git a/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.javaindex 237add65556..9b8eae8fe34 100644--- a/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java+++ b/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java@@ -183,7 +183,15 @@ public class TestBackwardsCompatibility extends LuceneTestCase {} finally {if (reader != null) reader.close();reader = null;- if (writer != null) writer.close();+ if (writer != null) {+ try {+ writer.close();+ } catch (IndexFormatTooOldException e) {+ // OK -- since IW gives merge scheduler a chance+ // to merge at close, it's possible and fine to+ // hit this exc here+ }+ }writer = null;}