LUCENE-5289: clarify that hasUncommittedChanges can still be true after commit, due to merges
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene_solr_4_5@1533265 13f79535-47bb-0310-9956-ffa450edef68
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 267e1eb..e14700e 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
@@ -2935,7 +2935,12 @@
commitInternal();
}
- /** Returns true if there are changes that have not been committed */
+ /** Returns true if there are changes that have not been
+ * committed. Note that if a merge kicked off as a
+ * result of flushing a new segment during {@link
+ * #commit}, or a concurrent merged finished,
+ * this method may return true right after you
+ * had just called {@link #commit}. */
public final boolean hasUncommittedChanges() {
return changeCount != lastCommitChangeCount || docWriter.anyChanges() || bufferedDeletesStream.any();
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
index ffd2007..e7e925a 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
@@ -2303,6 +2303,11 @@
doc.add(newTextField("myfield", "a b c", Field.Store.NO));
writer.addDocument(doc);
assertTrue(writer.hasUncommittedChanges());
+
+ // Must commit, waitForMerges, commit again, to be
+ // certain that hasUncommittedChanges returns false:
+ writer.commit();
+ writer.waitForMerges();
writer.commit();
assertFalse(writer.hasUncommittedChanges());
writer.addDocument(doc);
@@ -2312,10 +2317,20 @@
doc.add(newStringField("id", "xyz", Field.Store.YES));
writer.addDocument(doc);
assertTrue(writer.hasUncommittedChanges());
+
+ // Must commit, waitForMerges, commit again, to be
+ // certain that hasUncommittedChanges returns false:
+ writer.commit();
+ writer.waitForMerges();
writer.commit();
assertFalse(writer.hasUncommittedChanges());
writer.deleteDocuments(new Term("id", "xyz"));
assertTrue(writer.hasUncommittedChanges());
+
+ // Must commit, waitForMerges, commit again, to be
+ // certain that hasUncommittedChanges returns false:
+ writer.commit();
+ writer.waitForMerges();
writer.commit();
assertFalse(writer.hasUncommittedChanges());
writer.close();