LUCENE-6523: a new commit, even without user-data changes, is visible to reopened NRT reader

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1683947 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2015-06-06 20:11:06 +00:00
parent 08484fac91
commit e1ca83240e
4 changed files with 48 additions and 6 deletions

View File

@ -77,6 +77,9 @@ Bug fixes
* LUCENE-5805: QueryNodeImpl.removeFromParent was doing nothing in a
costly manner (Christoph Kaser, Cao Manh Dat via Mike McCAndless)
* LUCENE-6523: NRT readers now reflect a new commit even if there is
no change to the commit user data (Mike McCandless)
Changes in Runtime Behavior
* LUCENE-6501: The subreader structure in ParallelCompositeReader

View File

@ -2715,6 +2715,15 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
readerPool.commit(segmentInfos);
if (changeCount.get() != lastCommitChangeCount) {
// There are changes to commit, so we will write a new segments_N in startCommit.
// The act of committing is itself an NRT-visible change (an NRT reader that was
// just opened before this should see it on reopen) so we increment changeCount
// and segments version so a future NRT reopen will see the change:
changeCount.incrementAndGet();
segmentInfos.changed();
}
// Must clone the segmentInfos while we still
// hold fullFlushLock and while sync'd so that
// no partial changes (eg a delete w/o

View File

@ -2812,5 +2812,26 @@ public class TestIndexWriter extends LuceneTestCase {
assertNotNull(r2);
IOUtils.close(r, r2, w, dir);
}
// LUCENE-6523
public void testCommitImmediaatelyAfterNRTReopen() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
IndexWriter w = new IndexWriter(dir, iwc);
w.commit();
w.addDocument(new Document());
DirectoryReader r = DirectoryReader.open(w, true);
w.commit();
assertFalse(r.isCurrent());
DirectoryReader r2 = DirectoryReader.openIfChanged(r);
assertNotNull(r2);
// segments_N should have changed:
assertFalse(r2.getIndexCommit().getSegmentsFileName().equals(r.getIndexCommit().getSegmentsFileName()));
IOUtils.close(r, r2, w, dir);
}
}

View File

@ -103,9 +103,15 @@ public class TestIndexWriterReader extends LuceneTestCase {
writer.forceMerge(1); // make sure all merging is done etc.
DirectoryReader reader = writer.getReader();
writer.commit(); // no changes that are not visible to the reader
// A commit is now seen as a change to an NRT reader:
assertFalse(reader.isCurrent());
reader.close();
reader = writer.getReader();
assertTrue(reader.isCurrent());
writer.close();
assertTrue(reader.isCurrent()); // all changes are visible to the reader
assertTrue(reader.isCurrent());
iwc = newIndexWriterConfig(new MockAnalyzer(random()));
writer = new IndexWriter(dir1, iwc);
assertTrue(reader.isCurrent());
@ -160,11 +166,12 @@ public class TestIndexWriterReader extends LuceneTestCase {
r1.close();
assertTrue(r2.isCurrent());
writer.close();
assertTrue(r2.isCurrent());
// writer.close wrote a new commit
assertFalse(r2.isCurrent());
DirectoryReader r3 = DirectoryReader.open(dir1);
assertTrue(r3.isCurrent());
assertTrue(r2.isCurrent());
assertFalse(r2.isCurrent());
assertEquals(0, count(new Term("id", id10), r3));
assertEquals(1, count(new Term("id", Integer.toString(8000)), r3));
@ -172,7 +179,7 @@ public class TestIndexWriterReader extends LuceneTestCase {
Document doc = new Document();
doc.add(newTextField("field", "a b c", Field.Store.NO));
writer.addDocument(doc);
assertTrue(r2.isCurrent());
assertFalse(r2.isCurrent());
assertTrue(r3.isCurrent());
writer.close();
@ -216,7 +223,7 @@ public class TestIndexWriterReader extends LuceneTestCase {
assertEquals(2, nrtReader.maxDoc()); // sees the actual document added
assertEquals(1, dirReader.maxDoc());
writer.close(); // close is actually a commit both should see the changes
assertTrue(nrtReader.isCurrent());
assertFalse(nrtReader.isCurrent());
assertFalse(dirReader.isCurrent()); // this reader has been opened before the writer was closed / committed
dirReader.close();
@ -259,7 +266,9 @@ public class TestIndexWriterReader extends LuceneTestCase {
assertTrue(r1.isCurrent());
writer.commit();
assertTrue(r1.isCurrent()); // we have seen all changes - no change after opening the NRT reader
// A commit is seen as a change to NRT reader:
assertFalse(r1.isCurrent());
assertEquals(200, r1.maxDoc());