lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r834035 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/SegmentInfos.java src/test/org/apache/lucene/index/TestIndexReader.java
Date Mon, 09 Nov 2009 12:37:44 GMT
Author: mikemccand
Date: Mon Nov  9 12:37:43 2009
New Revision: 834035

URL: http://svn.apache.org/viewvc?rev=834035&view=rev
Log:
LUCENE-2046: IndexReader.isCurrent should still return true after writer calls prepareCommit

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=834035&r1=834034&r2=834035&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Mon Nov  9 12:37:43 2009
@@ -192,6 +192,10 @@
    infoStream on IndexWriter and then add an empty document and commit
    (Shai Erera via Mike McCandless)
 
+ * LUCENE-2046: IndexReader should not see the index as changed, after
+   IndexWriter.prepareCommit has been called but before
+   IndexWriter.commit is called. (Peter Keegan via Mike McCandless)
+
 API Changes
 
  * Un-deprecate search(Weight weight, Filter filter, int n) from

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java?rev=834035&r1=834034&r2=834035&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java Mon Nov  9 12:37:43
2009
@@ -402,36 +402,14 @@
   public static long readCurrentVersion(Directory directory)
     throws CorruptIndexException, IOException {
 
-    return ((Long) new FindSegmentsFile(directory) {
-        @Override
-        protected Object doBody(String segmentFileName) throws CorruptIndexException, IOException
{
-
-          IndexInput input = directory.openInput(segmentFileName);
-
-          int format = 0;
-          long version = 0;
-          try {
-            format = input.readInt();
-            if(format < 0){
-              if (format < CURRENT_FORMAT)
-                throw new CorruptIndexException("Unknown format version: " + format);
-              version = input.readLong(); // read version
-            }
-          }
-          finally {
-            input.close();
-          }
-     
-          if(format < 0)
-            return Long.valueOf(version);
-
-          // We cannot be sure about the format of the file.
-          // Therefore we have to read the whole file and cannot simply seek to the version
entry.
-          SegmentInfos sis = new SegmentInfos();
-          sis.read(directory, segmentFileName);
-          return Long.valueOf(sis.getVersion());
-        }
-      }.run()).longValue();
+    // Fully read the segments file: this ensures that it's
+    // completely written so that if
+    // IndexWriter.prepareCommit has been called (but not
+    // yet commit), then the reader will still see itself as
+    // current:
+    SegmentInfos sis = new SegmentInfos();
+    sis.read(directory);
+    return sis.version;
   }
 
   /**

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java?rev=834035&r1=834034&r2=834035&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java Mon Nov  9 12:37:43
2009
@@ -1778,4 +1778,24 @@
     r2.close();
     dir.close();
   }
+
+  // LUCENE-2046
+  public void testPrepareCommitIsCurrent() throws Throwable {
+    Directory dir = new MockRAMDirectory();
+    IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
+    Document doc = new Document();
+    writer.addDocument(doc);
+    IndexReader r = IndexReader.open(dir, true);
+    assertTrue(r.isCurrent());
+    writer.addDocument(doc);
+    writer.prepareCommit();
+    assertTrue(r.isCurrent());
+    IndexReader r2 = r.reopen();
+    assertTrue(r == r2);
+    writer.commit();
+    assertFalse(r.isCurrent());
+    writer.close();
+    r.close();
+    dir.close();
+  }
 }



Mime
View raw message