lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1184889 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/src/test/ lucene/backwards/src/test/org/apache/lucene/search/ lucene/contrib/misc/src/java/org/apache/lucene/index/ lucene/contrib/misc/src/java/org/apache/lucene/sea...
Date Sun, 16 Oct 2011 17:56:33 GMT
Author: mikemccand
Date: Sun Oct 16 17:56:32 2011
New Revision: 1184889

URL: http://svn.apache.org/viewvc?rev=1184889&view=rev
Log:
LUCENE-3520: IndexReader.openIfChanged on NRT reader now returns null when there are no changes;
some simplifications to SearcherManager

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/CHANGES.txt
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/search/TestCachingSpanFilter.java
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
    lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/index/NRTManager.java
    lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/search/SearcherLifetimeManager.java
    lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/search/SearcherManager.java
    lucene/dev/branches/branch_3x/lucene/contrib/misc/src/test/org/apache/lucene/search/TestSearcherManager.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexReader.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingSpanFilter.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
    lucene/dev/branches/branch_3x/solr/   (props changed)

Modified: lucene/dev/branches/branch_3x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/CHANGES.txt?rev=1184889&r1=1184888&r2=1184889&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/lucene/CHANGES.txt Sun Oct 16 17:56:32 2011
@@ -29,6 +29,13 @@ Changes in backwards compatibility polic
   (instead of the old reader) if there are no changes in the index, to
   prevent the common pitfall of accidentally closing the old reader.
 
+Changes in runtime behavior
+
+* LUCENE-3520: IndexReader.openIfChanged, when passed a near-real-time
+  reader, will now return null if there are no changes.  The API has
+  always reserved the right to do this; it's just that in the past for
+  near-real-time readers it never did. (Mike McCandless)
+
 Bug fixes
 
 * SOLR-2762: (backport form 4.x line): FSTLookup could return duplicate 

Modified: lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/search/TestCachingSpanFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/search/TestCachingSpanFilter.java?rev=1184889&r1=1184888&r2=1184889&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/search/TestCachingSpanFilter.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/search/TestCachingSpanFilter.java
Sun Oct 16 17:56:32 2011
@@ -113,10 +113,10 @@ public class TestCachingSpanFilter exten
 
     // make sure we get a cache hit when we reopen readers
     // that had no new deletions
+    // Deletes nothing:
+    writer.deleteDocuments(new Term("foo", "bar"));
     reader = refreshReader(reader);
-    assertTrue(reader != oldReader);
-    searcher.close();
-    searcher = newSearcher(reader, false);
+    assertTrue(reader == oldReader);
     int missCount = filter.missCount;
     docs = searcher.search(constantScore, 1);
     assertEquals("[just filter] Should find a hit...", 1, docs.totalHits);

Modified: lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java?rev=1184889&r1=1184888&r2=1184889&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
Sun Oct 16 17:56:32 2011
@@ -229,10 +229,10 @@ public class TestCachingWrapperFilter ex
 
     // make sure we get a cache hit when we reopen reader
     // that had no change to deletions
+    // Deletes nothing:
+    writer.deleteDocuments(new Term("foo", "bar"));
     reader = refreshReader(reader);
-    assertTrue(reader != oldReader);
-    searcher.close();
-    searcher = newSearcher(reader, false);
+    assertTrue(reader == oldReader);
     int missCount = filter.missCount;
     docs = searcher.search(constantScore, 1);
     assertEquals("[just filter] Should find a hit...", 1, docs.totalHits);

Modified: lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/index/NRTManager.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/index/NRTManager.java?rev=1184889&r1=1184888&r2=1184889&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/index/NRTManager.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/index/NRTManager.java
Sun Oct 16 17:56:32 2011
@@ -95,10 +95,10 @@ public class NRTManager implements Close
       SearcherWarmer warmer, boolean alwaysApplyDeletes) throws IOException {
     this.writer = writer;
     if (alwaysApplyDeletes) {
-      withoutDeletes = withDeletes = new SearcherManagerRef(true, 0,  SearcherManager.open(writer,
true, warmer, es));
+      withoutDeletes = withDeletes = new SearcherManagerRef(true, 0,  new SearcherManager(writer,
true, warmer, es));
     } else {
-      withDeletes = new SearcherManagerRef(true, 0,  SearcherManager.open(writer, true, warmer,
es));
-      withoutDeletes = new SearcherManagerRef(false, 0,  SearcherManager.open(writer, false,
warmer, es));
+      withDeletes = new SearcherManagerRef(true, 0, new SearcherManager(writer, true, warmer,
es));
+      withoutDeletes = new SearcherManagerRef(false, 0, new SearcherManager(writer, false,
warmer, es));
     }
     indexingGen = new AtomicLong(1);
   }

Modified: lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/search/SearcherLifetimeManager.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/search/SearcherLifetimeManager.java?rev=1184889&r1=1184888&r2=1184889&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/search/SearcherLifetimeManager.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/search/SearcherLifetimeManager.java
Sun Oct 16 17:56:32 2011
@@ -172,8 +172,8 @@ public class SearcherLifetimeManager imp
         // incRef done by SearcherTracker ctor:
         tracker.close();
       }
-    } else {
-      assert tracker.searcher == searcher;
+    } else if (tracker.searcher != searcher) {
+      throw new IllegalArgumentException("the provided searcher has the same underlying reader
version yet the searcher instance differs from before (new=" + searcher + " vs old=" + tracker.searcher);
     }
 
     return version;

Modified: lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/search/SearcherManager.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/search/SearcherManager.java?rev=1184889&r1=1184888&r2=1184889&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/search/SearcherManager.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/search/SearcherManager.java
Sun Oct 16 17:56:32 2011
@@ -64,23 +64,76 @@ import org.apache.lucene.store.Directory
  * @lucene.experimental
  */
 
-public abstract class SearcherManager {
+public final class SearcherManager {
 
-  protected volatile IndexSearcher currentSearcher;
-  protected final ExecutorService es;
-  protected final SearcherWarmer warmer;
-  protected final Semaphore reopenLock = new Semaphore(1);
+  private volatile IndexSearcher currentSearcher;
+  private final ExecutorService es;
+  private final SearcherWarmer warmer;
+  private final Semaphore reopenLock = new Semaphore(1);
   
-  protected SearcherManager(IndexReader openedReader, SearcherWarmer warmer,
+  /**
+   * Creates and returns a new SearcherManager from the given {@link IndexWriter}. 
+   * @param writer the IndexWriter to open the IndexReader from.
+   * @param applyAllDeletes If <code>true</code>, all buffered deletes will
+   *        be applied (made visible) in the {@link IndexSearcher} / {@link IndexReader}.
+   *        If <code>false</code>, the deletes may or may not be applied, but
remain buffered 
+   *        (in IndexWriter) so that they will be applied in the future.
+   *        Applying deletes can be costly, so if your app can tolerate deleted documents
+   *        being returned you might gain some performance by passing <code>false</code>.
+   *        See {@link IndexReader#openIfChanged(IndexReader, IndexWriter, boolean)}.
+   * @param warmer An optional {@link SearcherWarmer}. Pass
+   *        <code>null</code> if you don't require the searcher to warmed
+   *        before going live.  If this is  <code>non-null</code> then a
+   *        merged segment warmer is installed on the
+   *        provided IndexWriter's config.
+   * @param es An optional {@link ExecutorService} so different segments can
+   *        be searched concurrently (see {@link
+   *        IndexSearcher#IndexSearcher(IndexReader,ExecutorService)}.  Pass <code>null</code>
+   *        to search segments sequentially.
+   *        
+   * @throws IOException
+   */
+  public SearcherManager(IndexWriter writer, boolean applyAllDeletes,
+      final SearcherWarmer warmer, final ExecutorService es) throws IOException {
+    this.es = es;
+    this.warmer = warmer;
+    currentSearcher = new IndexSearcher(IndexReader.open(writer, applyAllDeletes));
+    if (warmer != null) {
+      writer.getConfig().setMergedSegmentWarmer(
+          new IndexWriter.IndexReaderWarmer() {
+            @Override
+            public void warm(IndexReader reader) throws IOException {
+              warmer.warm(new IndexSearcher(reader, es));
+            }
+          });
+    }
+  }
+
+  /**
+   * Creates and returns a new SearcherManager from the given {@link Directory}. 
+   * @param dir the directory to open the IndexReader on.
+   * @param warmer An optional {@link SearcherWarmer}.  Pass
+   *        <code>null</code> if you don't require the searcher to warmed
+   *        before going live.  If this is  <code>non-null</code> then a
+   *        merged segment warmer is installed on the
+   *        provided IndexWriter's config.
+   * @param es And optional {@link ExecutorService} so different segments can
+   *        be searched concurrently (see {@link
+   *        IndexSearcher#IndexSearcher(IndexReader,ExecutorService)}.  Pass <code>null</code>
+   *        to search segments sequentially.
+   *        
+   * @throws IOException
+   */
+  public SearcherManager(Directory dir, SearcherWarmer warmer,
       ExecutorService es) throws IOException {
     this.es = es;
     this.warmer = warmer;
-    currentSearcher = new IndexSearcher(openedReader, es);
+    currentSearcher = new IndexSearcher(IndexReader.open(dir, true), es);
   }
 
   /**
    * You must call this, periodically, to perform a reopen. This calls
-   * {@link #openIfChanged(IndexReader)} with the underlying reader, and if that returns
a
+   * {@link IndexReader#openIfChanged(IndexReader)} with the underlying reader, and if that
returns a
    * new reader, it's warmed (if you provided a {@link SearcherWarmer} and then
    * swapped into production.
    * 
@@ -103,7 +156,9 @@ public abstract class SearcherManager {
     // threads just return immediately:
     if (reopenLock.tryAcquire()) {
       try {
-        final IndexReader newReader = openIfChanged(currentSearcher.getIndexReader());
+        // IR.openIfChanged preserves NRT and applyDeletes
+        // in the newly returned reader:
+        final IndexReader newReader = IndexReader.openIfChanged(currentSearcher.getIndexReader());
         if (newReader != null) {
           final IndexSearcher newSearcher = new IndexSearcher(newReader, es);
           boolean success = false;
@@ -190,122 +245,10 @@ public abstract class SearcherManager {
     }
   }
 
-  protected synchronized void swapSearcher(IndexSearcher newSearcher) throws IOException
{
+  private synchronized void swapSearcher(IndexSearcher newSearcher) throws IOException {
     ensureOpen();
     final IndexSearcher oldSearcher = currentSearcher;
     currentSearcher = newSearcher;
     release(oldSearcher);
   }
-
-  protected abstract IndexReader openIfChanged(IndexReader oldReader)
-      throws IOException;
-
-  /**
-   * Creates and returns a new SearcherManager from the given {@link IndexWriter}. 
-   * @param writer the IndexWriter to open the IndexReader from.
-   * @param applyAllDeletes If <code>true</code>, all buffered deletes will
-   *        be applied (made visible) in the {@link IndexSearcher} / {@link IndexReader}.
-   *        If <code>false</code>, the deletes are not applied but remain buffered

-   *        (in IndexWriter) so that they will be applied in the future.
-   *        Applying deletes can be costly, so if your app can tolerate deleted documents
-   *        being returned you might gain some performance by passing <code>false</code>.
-   * @param warmer An optional {@link SearcherWarmer}. Pass
-   *        <code>null</code> if you don't require the searcher to warmed
-   *        before going live.  If this is  <code>non-null</code> then a
-   *        merged segment warmer is installed on the
-   *        provided IndexWriter's config.
-   * @param es An optional {@link ExecutorService} so different segments can
-   *        be searched concurrently (see {@link
-   *        IndexSearcher#IndexSearcher(IndexReader,ExecutorService)}.  Pass <code>null</code>
-   *        to search segments sequentially.
-   *        
-   * @see IndexReader#openIfChanged(IndexReader, IndexWriter, boolean)
-   * @throws IOException
-   */
-  public static SearcherManager open(IndexWriter writer, boolean applyAllDeletes,
-      SearcherWarmer warmer, ExecutorService es) throws IOException {
-    final IndexReader open = IndexReader.open(writer, true);
-    boolean success = false;
-    try {
-      SearcherManager manager = new NRTSearcherManager(writer, applyAllDeletes,
-          open, warmer, es);
-      success = true;
-      return manager;
-    } finally {
-      if (!success) {
-        open.close();
-      }
-    }
-  }
-
-  /**
-   * Creates and returns a new SearcherManager from the given {@link Directory}. 
-   * @param dir the directory to open the IndexReader on.
-   * @param warmer An optional {@link SearcherWarmer}.  Pass
-   *        <code>null</code> if you don't require the searcher to warmed
-   *        before going live.  If this is  <code>non-null</code> then a
-   *        merged segment warmer is installed on the
-   *        provided IndexWriter's config.
-   * @param es And optional {@link ExecutorService} so different segments can
-   *        be searched concurrently (see {@link
-   *        IndexSearcher#IndexSearcher(IndexReader,ExecutorService)}.  Pass <code>null</code>
-   *        to search segments sequentially.
-   *        
-   * @throws IOException
-   */
-  public static SearcherManager open(Directory dir, SearcherWarmer warmer,
-      ExecutorService es) throws IOException {
-    final IndexReader open = IndexReader.open(dir, true);
-    boolean success = false;
-    try {
-      SearcherManager manager = new DirectorySearchManager(open, warmer, es);
-      success = true;
-      return manager;
-    } finally {
-      if (!success) {
-        open.close();
-      }
-    }
-  }
-
-  static final class NRTSearcherManager extends SearcherManager {
-    private final IndexWriter writer;
-    private final boolean applyDeletes;
-
-    NRTSearcherManager(final IndexWriter writer, final boolean applyDeletes,
-        final IndexReader openedReader, final SearcherWarmer warmer, final ExecutorService
es)
-        throws IOException {
-      super(openedReader, warmer, es);
-      this.writer = writer;
-      this.applyDeletes = applyDeletes;
-      if (warmer != null) {
-        writer.getConfig().setMergedSegmentWarmer(
-            new IndexWriter.IndexReaderWarmer() {
-              @Override
-              public void warm(IndexReader reader) throws IOException {
-                warmer.warm(new IndexSearcher(reader, es));
-              }
-            });
-      }
-    }
-
-    @Override
-    protected IndexReader openIfChanged(IndexReader oldReader)
-        throws IOException {
-      return IndexReader.openIfChanged(oldReader, writer, applyDeletes);
-    }
-  }
-
-  static final class DirectorySearchManager extends SearcherManager {
-    DirectorySearchManager(IndexReader openedReader,
-        SearcherWarmer warmer, ExecutorService es) throws IOException {
-      super(openedReader, warmer, es);
-    }
-
-    @Override
-    protected IndexReader openIfChanged(IndexReader oldReader)
-        throws IOException {
-      return IndexReader.openIfChanged(oldReader, true);
-    }
-  }
 }

Modified: lucene/dev/branches/branch_3x/lucene/contrib/misc/src/test/org/apache/lucene/search/TestSearcherManager.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/misc/src/test/org/apache/lucene/search/TestSearcherManager.java?rev=1184889&r1=1184888&r2=1184889&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/misc/src/test/org/apache/lucene/search/TestSearcherManager.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/misc/src/test/org/apache/lucene/search/TestSearcherManager.java
Sun Oct 16 17:56:32 2011
@@ -71,12 +71,12 @@ public class TestSearcherManager extends
       }
     };
     if (random.nextBoolean()) {
-      mgr = SearcherManager.open(writer, true, warmer, es);
+      mgr = new SearcherManager(writer, true, warmer, es);
       isNRT = true;
     } else {
       // SearcherManager needs to see empty commit:
       writer.commit();
-      mgr = SearcherManager.open(dir, warmer, es);
+      mgr = new SearcherManager(dir, warmer, es);
       isNRT = false;
     }
 
@@ -195,8 +195,8 @@ public class TestSearcherManager extends
         }
       }
     };
-    final SearcherManager searcherManager = random.nextBoolean() ? SearcherManager.open(dir,
-        warmer, es) : SearcherManager.open(writer, random.nextBoolean(), warmer, es);
+    final SearcherManager searcherManager = random.nextBoolean() ? new SearcherManager(dir,
+        warmer, es) : new SearcherManager(writer, random.nextBoolean(), warmer, es);
     IndexSearcher searcher = searcherManager.acquire();
     try {
       assertEquals(1, searcher.getIndexReader().numDocs());

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/DirectoryReader.java?rev=1184889&r1=1184888&r2=1184889&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
Sun Oct 16 17:56:32 2011
@@ -401,8 +401,15 @@ class DirectoryReader extends IndexReade
     return doOpenIfChanged(true, commit);
   }
 
-  // NOTE: always returns a non-null result (ie new reader)
-  // but that could change someday
+  @Override
+  protected final IndexReader doOpenIfChanged(IndexWriter writer, boolean applyAllDeletes)
throws CorruptIndexException, IOException {
+    if (writer == this.writer && applyAllDeletes == this.applyAllDeletes) {
+      return doOpenIfChanged();
+    } else {    
+      return super.doOpenIfChanged(writer, applyAllDeletes);
+    }
+  }
+
   private final IndexReader doOpenFromWriter(boolean openReadOnly, IndexCommit commit) throws
CorruptIndexException, IOException {
     assert readOnly;
 
@@ -414,10 +421,18 @@ class DirectoryReader extends IndexReade
       throw new IllegalArgumentException("a reader obtained from IndexWriter.getReader()
cannot currently accept a commit");
     }
 
-    // TODO: right now we *always* make a new reader; in
-    // the future we could have write make some effort to
-    // detect that no changes have occurred
+    if (writer.nrtIsCurrent(segmentInfos)) {
+      return null;
+    }
+
     IndexReader reader = writer.getReader(applyAllDeletes);
+
+    // If in fact no changes took place, return null:
+    if (reader.getVersion() == getVersion()) {
+      reader.decRef();
+      return null;
+    }
+
     reader.readerFinishedListeners = readerFinishedListeners;
     return reader;
   }

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexReader.java?rev=1184889&r1=1184888&r2=1184889&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexReader.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexReader.java
Sun Oct 16 17:56:32 2011
@@ -486,10 +486,6 @@ public abstract class IndexReader implem
    * with the old reader uses "copy on write" semantics to
    * ensure the changes are not seen by other readers.
    *
-   * <p><b>NOTE</b>: If the provided reader is a near real-time
-   * reader, this method will return another near-real-time
-   * reader.
-   * 
    * @throws CorruptIndexException if the index is corrupt
    * @throws IOException if there is a low-level IO error
    * @return null if there are no changes; else, a new

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexWriter.java?rev=1184889&r1=1184888&r2=1184889&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexWriter.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexWriter.java
Sun Oct 16 17:56:32 2011
@@ -4765,6 +4765,7 @@ public class IndexWriter implements Clos
 
   synchronized boolean nrtIsCurrent(SegmentInfos infos) {
     //System.out.println("IW.nrtIsCurrent " + (infos.version == segmentInfos.version &&
!docWriter.anyChanges() && !bufferedDeletesStream.any()));
+    ensureOpen();
     return infos.version == segmentInfos.version && !docWriter.anyChanges() &&
!bufferedDeletesStream.any();
   }
 

Modified: lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java?rev=1184889&r1=1184888&r2=1184889&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java
Sun Oct 16 17:56:32 2011
@@ -51,7 +51,7 @@ import org.apache.lucene.util._TestUtil;
 
 // TODO
 //   - mix in optimize, addIndexes
-//   - randomoly mix in non-congruent docs
+//   - randomly mix in non-congruent docs
 
 /** Utility class that spawns multiple indexing and
  *  searching threads. */

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java?rev=1184889&r1=1184888&r2=1184889&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java
Sun Oct 16 17:56:32 2011
@@ -851,7 +851,7 @@ public class TestIndexWriterReader exten
     int sum = 0;
     while(System.currentTimeMillis() < endTime) {
       IndexReader r2 = IndexReader.openIfChanged(r);
-      if (r2 != r) {
+      if (r2 != null) {
         r.close();
         r = r2;
       }
@@ -1000,4 +1000,40 @@ public class TestIndexWriterReader exten
     }
   }
   
+  public void testReopenAfterNoRealChange() throws Exception {
+    Directory d = newDirectory();
+    IndexWriter w = new IndexWriter(
+        d,
+        newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
+    w.setInfoStream(VERBOSE ? System.out : null);
+
+    IndexReader r = w.getReader(); // start pooling readers
+
+    IndexReader r2 = IndexReader.openIfChanged(r);
+    assertNull(r2);
+    
+    w.addDocument(new Document());
+    IndexReader r3 = IndexReader.openIfChanged(r);
+    assertNotNull(r3);
+    assertTrue(r3.getVersion() != r.getVersion());
+    assertTrue(r3.isCurrent());
+
+    // Deletes nothing in reality...:
+    w.deleteDocuments(new Term("foo", "bar"));
+
+    // ... but IW marks this as not current:
+    assertFalse(r3.isCurrent());
+    IndexReader r4 = IndexReader.openIfChanged(r3);
+    assertNull(r4);
+
+    // Deletes nothing in reality...:
+    w.deleteDocuments(new Term("foo", "bar"));
+    IndexReader r5 = IndexReader.openIfChanged(r3, w, true);
+    assertNull(r5);
+
+    r3.close();
+
+    w.close();
+    d.close();
+  }
 }

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingSpanFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingSpanFilter.java?rev=1184889&r1=1184888&r2=1184889&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingSpanFilter.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingSpanFilter.java
Sun Oct 16 17:56:32 2011
@@ -113,10 +113,10 @@ public class TestCachingSpanFilter exten
 
     // make sure we get a cache hit when we reopen readers
     // that had no new deletions
+    // Deletes nothing:
+    writer.deleteDocuments(new Term("foo", "bar"));
     reader = refreshReader(reader);
-    assertTrue(reader != oldReader);
-    searcher.close();
-    searcher = newSearcher(reader, false);
+    assertTrue(reader == oldReader);
     int missCount = filter.missCount;
     docs = searcher.search(constantScore, 1);
     assertEquals("[just filter] Should find a hit...", 1, docs.totalHits);

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java?rev=1184889&r1=1184888&r2=1184889&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
Sun Oct 16 17:56:32 2011
@@ -229,10 +229,9 @@ public class TestCachingWrapperFilter ex
 
     // make sure we get a cache hit when we reopen reader
     // that had no change to deletions
+    writer.deleteDocuments(new Term("foo", "bar"));
     reader = refreshReader(reader);
-    assertTrue(reader != oldReader);
-    searcher.close();
-    searcher = newSearcher(reader, false);
+    assertTrue(reader == oldReader);
     int missCount = filter.missCount;
     docs = searcher.search(constantScore, 1);
     assertEquals("[just filter] Should find a hit...", 1, docs.totalHits);



Mime
View raw message