lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r777080 - in /lucene/java/trunk/src: java/org/apache/lucene/index/DirectoryIndexReader.java java/org/apache/lucene/index/SegmentReader.java test/org/apache/lucene/index/TestIndexReaderClone.java
Date Thu, 21 May 2009 11:45:21 GMT
Author: mikemccand
Date: Thu May 21 11:45:21 2009
New Revision: 777080

URL: http://svn.apache.org/viewvc?rev=777080&view=rev
Log:
LUCENE-1648: carry over hasChanges/deletionsDirty/normsDirty/pendingDeleteCount when a SegmentReader
w/ pending changes is cloned

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderClone.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java?rev=777080&r1=777079&r2=777080&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java Thu May 21
11:45:21 2009
@@ -330,7 +330,9 @@
   /** Returns the directory this index resides in.
    */
   public Directory directory() {
-    ensureOpen();
+    // Don't ensureOpen here -- in certain cases, when a
+    // cloned/reopened reader needs to commit, it may call
+    // this method on the closed original reader
     return directory;
   }
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java?rev=777080&r1=777079&r2=777080&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java Thu May 21 11:45:21
2009
@@ -691,6 +691,15 @@
       clone.termVectorsReaderOrig = termVectorsReaderOrig;
       clone.fieldsReaderOrig = fieldsReaderOrig;
       
+      if (!openReadOnly && hasChanges) {
+        // My pending changes transfer to the new reader
+        clone.pendingDeleteCount = pendingDeleteCount;
+        clone.deletedDocsDirty = deletedDocsDirty;
+        clone.normsDirty = normsDirty;
+        clone.hasChanges = hasChanges;
+        hasChanges = false;
+      }
+      
       if (doClone) {
         if (deletedDocs != null) {
           deletedDocsRef.incRef();
@@ -752,6 +761,7 @@
       
       si.setDelCount(si.getDelCount()+pendingDeleteCount);
       pendingDeleteCount = 0;
+      assert deletedDocs.count() == si.getDelCount(): "delete count mismatch during commit:
info=" + si.getDelCount() + " vs BitVector=" + deletedDocs.count();
     }
     if (undeleteAll && si.hasDeletions()) {
       si.clearDelGen();

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderClone.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderClone.java?rev=777080&r1=777079&r2=777080&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderClone.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderClone.java Thu May 21
11:45:21 2009
@@ -397,6 +397,44 @@
     dir1.close();
   }
 
+  // LUCENE-1648
+  public void testCloneWithDeletes() throws Throwable {
+    final Directory dir1 = new MockRAMDirectory();
+    TestIndexReaderReopen.createIndex(dir1, false);
+    SegmentReader origSegmentReader = (SegmentReader) IndexReader.open(dir1);
+    origSegmentReader.deleteDocument(1);
+
+    SegmentReader clonedSegmentReader = (SegmentReader) origSegmentReader.clone();
+    origSegmentReader.close();
+    clonedSegmentReader.close();
+
+    SegmentReader r = (SegmentReader) IndexReader.open(dir1);
+    assertTrue(r.isDeleted(1));
+    r.close();
+    dir1.close();
+  }
+
+  // LUCENE-1648
+  public void testCloneWithSetNorm() throws Throwable {
+    final Directory dir1 = new MockRAMDirectory();
+    TestIndexReaderReopen.createIndex(dir1, false);
+    SegmentReader orig = (SegmentReader) IndexReader.open(dir1);
+    orig.setNorm(1, "field1", 17.0f);
+    final byte encoded = Similarity.encodeNorm(17.0f);
+    assertEquals(encoded, orig.norms("field1")[1]);
+
+    // the cloned segmentreader should have 2 references, 1 to itself, and 1 to
+    // the original segmentreader
+    SegmentReader clonedSegmentReader = (SegmentReader) orig.clone();
+    orig.close();
+    clonedSegmentReader.close();
+
+    SegmentReader r = (SegmentReader) IndexReader.open(dir1);
+    assertEquals(encoded, r.norms("field1")[1]);
+    r.close();
+    dir1.close();
+  }
+
   private void assertDocDeleted(SegmentReader reader, SegmentReader reader2,
       int doc) {
     assertEquals(reader.isDeleted(doc), reader2.isDeleted(doc));



Mime
View raw message