From 4ff882e4aa9cb7fc585213bca9344fa05d1bec5f Mon Sep 17 00:00:00 2001 From: Mike McCandless Date: Wed, 6 Jul 2016 09:29:30 -0400 Subject: [PATCH] LUCENE-7302: IW.getMaxCompletedSequenceNumber was returning the wrong value after IW.deleteAll --- .../org/apache/lucene/index/DocumentsWriter.java | 4 ++++ .../java/org/apache/lucene/index/IndexWriter.java | 7 ++++--- .../TestControlledRealTimeReopenThread.java | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) 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 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.java index f0d756bdfb5..fd2553671ce 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 { * *

* NOTE: 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.java index 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 ThreadedIndexingAndSearc iw.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); + } }