LUCENE-4521: make sure we commit new del file if tryDeleteDocument succeeds but IW has no other pending changes

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1404229 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2012-10-31 16:22:53 +00:00
parent 6c45b24b48
commit c898b44722
3 changed files with 39 additions and 0 deletions

View File

@ -104,6 +104,12 @@ Bug Fixes
* LUCENE-4511: TermsFilter might return wrong results if a field is not
indexed or doesn't exist in the index. (Simon Willnauer)
* LUCENE-4521: IndexWriter.tryDeleteDocument could return true
(successfully deleting the document) but then on IndexWriter
close/commit fail to write the new deletions, if no other changes
happened in the IndexWriter instance. (Ivan Vasilev via Mike
McCandless)
Optimizations
* LUCENE-4512: Additional memory savings for CompressingStoredFieldsIndex.MEMORY_CHUNK

View File

@ -1317,6 +1317,10 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
checkpoint();
}
}
// Must bump changeCount so if no other changes
// happened, we still commit this change:
changeCount++;
}
//System.out.println(" yes " + info.info.name + " " + docID);
return true;

View File

@ -39,6 +39,7 @@ import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util._TestUtil;
@ -1116,4 +1117,32 @@ public class TestIndexWriterDelete extends LuceneTestCase {
assertFalse(s.contains("has deletions"));
dir.close();
}
public void testTryDeleteDocument() throws Exception {
Directory d = newDirectory();
IndexWriterConfig iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
IndexWriter w = new IndexWriter(d, iwc);
Document doc = new Document();
w.addDocument(doc);
w.addDocument(doc);
w.addDocument(doc);
w.close();
iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
iwc.setOpenMode(IndexWriterConfig.OpenMode.APPEND);
w = new IndexWriter(d, iwc);
IndexReader r = DirectoryReader.open(w, false);
assertTrue(w.tryDeleteDocument(r, 1));
assertTrue(w.tryDeleteDocument(r.leaves().get(0).reader(), 0));
r.close();
w.close();
r = DirectoryReader.open(d);
assertEquals(2, r.numDeletedDocs());
assertNotNull(MultiFields.getLiveDocs(r));
r.close();
d.close();
}
}