LUCENE-5330: Fix IndexWriter to process all internal events on getReader / close / rollback

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1539332 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Simon Willnauer 2013-11-06 13:17:51 +00:00
parent f165031574
commit 50b5e3ec7c
3 changed files with 22 additions and 0 deletions

View File

@ -191,6 +191,11 @@ Bug Fixes
inside ConstantScoreQuery, which now rewrites to a query removing the inside ConstantScoreQuery, which now rewrites to a query removing the
obsolete QueryWrapperFilter. (Adrien Grand, Uwe Schindler) obsolete QueryWrapperFilter. (Adrien Grand, Uwe Schindler)
* LUCENE-5330: IndexWriter didn't process all internal events on
#getReader(), #close() and #rollback() which causes files to be
deleted at a later point in time. This could cause short-term disk
pollution or OOM if in-memory directories are used. (Simon Willnauer)
API Changes: API Changes:
* LUCENE-5222: Add SortField.needsScores(). Previously it was not possible * LUCENE-5222: Add SortField.needsScores(). Previously it was not possible

View File

@ -394,6 +394,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit{
} }
// Done: finish the full flush! // Done: finish the full flush!
docWriter.finishFullFlush(success); docWriter.finishFullFlush(success);
processEvents(false, true);
doAfterFlush(); doAfterFlush();
} }
} }
@ -929,6 +930,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit{
closeInternal(waitForMerges, true); closeInternal(waitForMerges, true);
} }
} }
assert eventQueue.isEmpty();
} }
} }
@ -1061,6 +1063,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit{
} }
// finally, restore interrupt status: // finally, restore interrupt status:
if (interrupted) Thread.currentThread().interrupt(); if (interrupted) Thread.currentThread().interrupt();
processEvents(false, true);
} }
} }
@ -2020,6 +2023,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit{
rollbackInternal(); rollbackInternal();
} }
} }
assert eventQueue.isEmpty() : eventQueue;
} }
private void rollbackInternal() throws IOException { private void rollbackInternal() throws IOException {

View File

@ -1321,6 +1321,7 @@ public class TestIndexWriter extends LuceneTestCase {
dir.close(); dir.close();
} }
public void testDeleteUnusedFiles() throws Exception { public void testDeleteUnusedFiles() throws Exception {
for(int iter=0;iter<2;iter++) { for(int iter=0;iter<2;iter++) {
Directory dir = newMockDirectory(); // relies on windows semantics Directory dir = newMockDirectory(); // relies on windows semantics
@ -1350,7 +1351,19 @@ public class TestIndexWriter extends LuceneTestCase {
} }
List<String> files = Arrays.asList(dir.listAll()); List<String> files = Arrays.asList(dir.listAll());
assertTrue(files.contains("_0.cfs")); assertTrue(files.contains("_0.cfs"));
assertTrue(files.contains("_0.cfe"));
assertTrue(files.contains("_0.si"));
if (iter == 1) {
// we run a full commit so there should be a segments file etc.
assertTrue(files.contains("segments_1"));
assertTrue(files.contains("segments.gen"));
assertEquals(files.toString(), files.size(), 5);
} else {
// this is an NRT reopen - no segments files yet
assertEquals(files.toString(), files.size(), 3);
}
w.addDocument(doc); w.addDocument(doc);
w.forceMerge(1); w.forceMerge(1);
if (iter == 1) { if (iter == 1) {