You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2013/06/26 20:48:53 UTC
svn commit: r1497039 - in /lucene/dev/trunk/lucene: CHANGES.txt
core/src/java/org/apache/lucene/index/IndexWriter.java
core/src/test/org/apache/lucene/index/TestIndexWriter.java
Author: yonik
Date: Wed Jun 26 18:48:52 2013
New Revision: 1497039
URL: http://svn.apache.org/r1497039
Log:
LUCENE-5079: IndexWriter.hasUncommittedChanges()
Modified:
lucene/dev/trunk/lucene/CHANGES.txt
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1497039&r1=1497038&r2=1497039&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Wed Jun 26 18:48:52 2013
@@ -254,6 +254,9 @@ New Features
* LUCENE-5063: FieldCache.DEFAULT.get(Ints|Longs) now uses bit-packing to save
memory. (Adrien Grand)
+* LUCENE-5079: IndexWriter.hasUncommittedChanges() returns true if there are
+ changes that have not been committed. (yonik, Mike McCandless, Uwe Schindler)
+
API Changes
* LUCENE-5077: Make it easier to use compressed norms. Lucene42NormsFormat takes
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java?rev=1497039&r1=1497038&r2=1497039&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java Wed Jun 26 18:48:52 2013
@@ -214,7 +214,7 @@ public class IndexWriter implements Clos
private final Analyzer analyzer; // how to analyze text
private volatile long changeCount; // increments every time a change is completed
- private long lastCommitChangeCount; // last changeCount that was committed
+ private volatile long lastCommitChangeCount; // last changeCount that was committed
private List<SegmentInfoPerCommit> rollbackSegments; // list of segmentInfo we will fallback to if the commit fails
@@ -2827,6 +2827,11 @@ public class IndexWriter implements Clos
commitInternal();
}
+ /** Returns true if there are changes that have not been committed */
+ public final boolean hasUncommittedChanges() {
+ return changeCount != lastCommitChangeCount;
+ }
+
private final void commitInternal() throws IOException {
if (infoStream.isEnabled("IW")) {
@@ -2866,8 +2871,8 @@ public class IndexWriter implements Clos
if (infoStream.isEnabled("IW")) {
infoStream.message("IW", "commit: wrote segments file \"" + pendingCommit.getSegmentsFileName() + "\"");
}
- lastCommitChangeCount = pendingCommitChangeCount;
segmentInfos.updateGeneration(pendingCommit);
+ lastCommitChangeCount = pendingCommitChangeCount;
rollbackSegments = pendingCommit.createBackupSegmentInfos();
deleter.checkpoint(pendingCommit, true);
} finally {
Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=1497039&r1=1497038&r2=1497039&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java Wed Jun 26 18:48:52 2013
@@ -2209,4 +2209,27 @@ public class TestIndexWriter extends Luc
dir.close();
}
}
+
+ public void testHasUncommittedChanges() throws IOException {
+ Directory dir = newDirectory();
+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random())));
+ assertTrue(writer.hasUncommittedChanges()); // this will be true because a commit will create an empty index
+ Document doc = new Document();
+ doc.add(newTextField("myfield", "a b c", Field.Store.NO));
+ writer.addDocument(doc);
+ assertTrue(writer.hasUncommittedChanges());
+ writer.commit();
+ assertFalse(writer.hasUncommittedChanges());
+ writer.addDocument(doc);
+ assertTrue(writer.hasUncommittedChanges());
+ writer.close();
+
+ writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random())));
+ assertFalse(writer.hasUncommittedChanges());
+ writer.addDocument(doc);
+ assertTrue(writer.hasUncommittedChanges());
+
+ writer.close();
+ dir.close();
+ }
}