From 726654c1ab46a37588d0dd74e848a784eff620c8 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Thu, 28 Apr 2011 15:39:52 +0000 Subject: [PATCH] LUCENE-3023: push global deletes if no document was flushed during global flush git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/realtime_search@1097510 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/DocumentsWriter.java | 4 ++-- .../java/org/apache/lucene/index/IndexWriter.java | 12 +++++++----- .../apache/lucene/index/TestPerSegmentDeletes.java | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java b/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java index 9a28d4374cb..5e316c21fee 100644 --- a/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java +++ b/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java @@ -488,7 +488,7 @@ final class DocumentsWriter { * two stage operation; the caller must ensure (in try/finally) that finishFlush * is called after this method, to release the flush lock in DWFlushControl */ - final boolean flushAllThreads(final boolean flushDeletes) + final boolean flushAllThreads() throws IOException { final DocumentsWriterDeleteQueue flushingDeleteQueue; @@ -514,7 +514,7 @@ final class DocumentsWriter { while (flushControl.anyFlushing()) { flushControl.waitForFlush(); } - if (!anythingFlushed && flushDeletes) { + if (!anythingFlushed) { // apply deletes if we did not flush any document synchronized (ticketQueue) { ticketQueue.add(new FlushTicket(flushingDeleteQueue.freezeGlobalBuffer(null), false)); } diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.java index 056c8071927..9478b939da3 100644 --- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java @@ -356,7 +356,7 @@ public class IndexWriter implements Closeable { poolReaders = true; final IndexReader r; doBeforeFlush(); - final boolean maybeMerge; + final boolean anySegmentFlushed; /* * for releasing a NRT reader we must ensure that * DW doesn't add any segments or deletes until we are @@ -367,8 +367,10 @@ public class IndexWriter implements Closeable { synchronized (fullFlushLock) { boolean success = false; try { - maybeMerge = docWriter.flushAllThreads(applyAllDeletes); - if (!maybeMerge) { + anySegmentFlushed = docWriter.flushAllThreads(); + if (!anySegmentFlushed) { + // prevent double increment since docWriter#doFlush increments the flushcount + // if we flushed anything. flushCount.incrementAndGet(); } success = true; @@ -391,7 +393,7 @@ public class IndexWriter implements Closeable { doAfterFlush(); } } - if(maybeMerge) { + if(anySegmentFlushed) { maybeMerge(); } if (infoStream != null) { @@ -2614,7 +2616,7 @@ public class IndexWriter implements Closeable { synchronized (fullFlushLock) { try { - maybeMerge = docWriter.flushAllThreads(applyAllDeletes); + maybeMerge = docWriter.flushAllThreads(); success = true; } finally { docWriter.finishFullFlush(success); diff --git a/lucene/src/test/org/apache/lucene/index/TestPerSegmentDeletes.java b/lucene/src/test/org/apache/lucene/index/TestPerSegmentDeletes.java index 85ae6e2f40b..7110d1a4c35 100644 --- a/lucene/src/test/org/apache/lucene/index/TestPerSegmentDeletes.java +++ b/lucene/src/test/org/apache/lucene/index/TestPerSegmentDeletes.java @@ -85,7 +85,7 @@ public class TestPerSegmentDeletes extends LuceneTestCase { // merge segments 0 and 1 // which should apply the delete id:2 writer.deleteDocuments(new Term("id", "2")); - writer.flush(false, true); + writer.flush(false, false); fsmp.doMerge = true; fsmp.start = 0; fsmp.length = 2;