Apache Lucene open-source search software
LUCENE-7302: IW.getMaxCompletedSequenceNumber was returning the wrong value after IW.deleteAll
Mike McCandless503da1fcb9fa
diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.javaindex a33d64072c9..2429c330f28 100644--- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java+++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java@@ -148,6 +148,10 @@ final class DocumentsWriter implements Closeable, Accountable {return seqNo;}+ synchronized void setLastSeqNo(long seqNo) {+ lastSeqNo = seqNo;+ }+// TODO: we could check w/ FreqProxTermsWriter: if the// term doesn't exist, don't bother buffering into the// per-DWPT map (but still must go into the global map)diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.javaindex de474d0dac9..91b67e8d73c 100644--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java@@ -765,8 +765,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {** <p>* <b>NOTE:</b> after ths writer is created, the given configuration instance- * cannot be passed to another writer. If you intend to do so, you should- * {@link IndexWriterConfig#clone() clone} it beforehand.+ * cannot be passed to another writer.** @param d* the index directory. The index is either created or appended@@ -2348,7 +2347,9 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {globalFieldNumberMap.clear();success = true;- return docWriter.deleteQueue.getNextSequenceNumber();+ long seqNo = docWriter.deleteQueue.getNextSequenceNumber();+ docWriter.setLastSeqNo(seqNo);+ return seqNo;} finally {docWriter.unlockAllAfterAbortAll(this);diff --git a/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java b/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.javaindex 779c1f21a1f..a1b2a5c2917 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java@@ -534,4 +534,19 @@ public class TestControlledRealTimeReopenThread extends ThreadedIndexingAndSearciw.close();dir.close();}++ public void testDeleteAll() throws Exception {+ Directory dir = newDirectory();+ IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());+ SearcherManager mgr = new SearcherManager(w, new SearcherFactory());+ nrtDeletesThread = new ControlledRealTimeReopenThread<>(w, mgr, 0.1, 0.01);+ nrtDeletesThread.setName("NRTDeletes Reopen Thread");+ nrtDeletesThread.setDaemon(true);+ nrtDeletesThread.start();++ long gen1 = w.addDocument(new Document());+ long gen2 = w.deleteAll();+ nrtDeletesThread.waitForGeneration(gen2);+ IOUtils.close(nrtDeletesThread, nrtDeletes, w, dir);+ }}