lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1221404 [2/2] - in /lucene/dev/trunk/lucene/src: java/org/apache/lucene/index/ test/org/apache/lucene/ test/org/apache/lucene/index/
Date Tue, 20 Dec 2011 18:17:34 GMT
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SegmentReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SegmentReader.java?rev=1221404&r1=1221403&r2=1221404&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SegmentReader.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SegmentReader.java Tue Dec 20
18:17:33 2011
@@ -23,7 +23,6 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.codecs.PerDocProducer;
@@ -39,27 +38,21 @@ import org.apache.lucene.util.CloseableT
 /**
  * @lucene.experimental
  */
-public final class SegmentReader extends IndexReader implements Cloneable {
-  private final boolean readOnly;
+public final class SegmentReader extends IndexReader {
 
-  private SegmentInfo si;
+  private final SegmentInfo si;
   private final ReaderContext readerContext = new AtomicReaderContext(this);
-  final CloseableThreadLocal<StoredFieldsReader> fieldsReaderLocal = new FieldsReaderLocal();
-  final CloseableThreadLocal<TermVectorsReader> termVectorsLocal = new CloseableThreadLocal<TermVectorsReader>();
+  private final CloseableThreadLocal<StoredFieldsReader> fieldsReaderLocal = new FieldsReaderLocal();
+  private final CloseableThreadLocal<TermVectorsReader> termVectorsLocal = new CloseableThreadLocal<TermVectorsReader>();
 
-  volatile BitVector liveDocs = null;
-  volatile Object combinedCoreAndDeletesKey;
-  AtomicInteger liveDocsRef = null;
-  boolean hasChanges = false;
-
-  // TODO: remove deletions from SR
-  private int pendingDeleteCount;
-  private boolean rollbackHasChanges = false;
-  private SegmentInfo rollbackSegmentInfo;
-  private int rollbackPendingDeleteCount;
-  // end TODO
+  private final BitVector liveDocs;
 
-  SegmentCoreReaders core;
+  // Normally set to si.docCount - si.delDocCount, unless we
+  // were created as an NRT reader from IW, in which case IW
+  // tells us the docCount:
+  private final int numDocs;
+
+  private final SegmentCoreReaders core;
 
   /**
    * Sets the initial value 
@@ -75,56 +68,73 @@ public final class SegmentReader extends
    * @throws CorruptIndexException if the index is corrupt
    * @throws IOException if there is a low-level IO error
    */
-  public static SegmentReader get(SegmentInfo si, int termInfosIndexDivisor, IOContext context)
throws CorruptIndexException, IOException {
-    return get(true, si, true, termInfosIndexDivisor, context);
-  }
-
-  // TODO: remove deletions from SR
-  static SegmentReader getRW(SegmentInfo si, boolean doOpenStores, int termInfosIndexDivisor,
IOContext context) throws CorruptIndexException, IOException {
-    return get(false, si, doOpenStores, termInfosIndexDivisor, context);
-  }
-
-  /**
-   * @throws CorruptIndexException if the index is corrupt
-   * @throws IOException if there is a low-level IO error
-   */
-  private static SegmentReader get(boolean readOnly,
-                                  SegmentInfo si,
-                                  boolean doOpenStores,
-                                  int termInfosIndexDivisor,
-                                  IOContext context)
-    throws CorruptIndexException, IOException {
-    
-    SegmentReader instance = new SegmentReader(readOnly, si);
+  public SegmentReader(SegmentInfo si, int termInfosIndexDivisor, IOContext context) throws
IOException {
+    this.si = si;
     boolean success = false;
     try {
-      instance.core = new SegmentCoreReaders(instance, si.dir, si, context, termInfosIndexDivisor);
-      if (doOpenStores) {
-        instance.core.openDocStores(si);
+      core = new SegmentCoreReaders(this, si.dir, si, context, termInfosIndexDivisor);
+      if (si.hasDeletions()) {
+        // NOTE: the bitvector is stored using the regular directory, not cfs
+        liveDocs = new BitVector(directory(), si.getDelFileName(), new IOContext(IOContext.READ,
true));
+      } else {
+        assert si.getDelCount() == 0;
+        liveDocs = null;
       }
-      instance.loadLiveDocs(context);
+      numDocs = si.docCount - si.getDelCount();
+      assert checkLiveCounts(false);
       success = true;
     } finally {
-
       // With lock-less commits, it's entirely possible (and
       // fine) to hit a FileNotFound exception above.  In
       // this case, we want to explicitly close any subset
       // of things that were opened so that we don't have to
       // wait for a GC to do so.
       if (!success) {
-        instance.doClose();
+        doClose();
       }
     }
-    return instance;
   }
 
-  private SegmentReader(boolean readOnly, SegmentInfo si) {
-    this.readOnly = readOnly;
+  // TODO: really these next 2 ctors could take
+  // SegmentCoreReaders... that's all we do w/ the parent
+  // SR:
+
+  // Create new SegmentReader sharing core from a previous
+  // SegmentReader and loading new live docs from a new
+  // deletes file.  Used by openIfChanged.
+  SegmentReader(SegmentInfo si, SegmentReader parent, IOContext context) throws IOException
{
+    assert si.dir == parent.getSegmentInfo().dir;
     this.si = si;
-  }
 
-  void openDocStores() throws IOException {
-    core.openDocStores(si);
+    // It's no longer possible to unDeleteAll, so, we can
+    // only be created if we have deletions:
+    assert si.hasDeletions();
+
+    // ... but load our own deleted docs:
+    liveDocs = new BitVector(si.dir, si.getDelFileName(), new IOContext(IOContext.READ, true));
+    numDocs = si.docCount - si.getDelCount();
+    assert checkLiveCounts(false);
+
+    // We share core w/ parent:
+    parent.core.incRef();
+    core = parent.core;
+  }
+
+  // Create new SegmentReader sharing core from a previous
+  // SegmentReader and using the provided in-memory
+  // liveDocs.  Used by IndexWriter to provide a new NRT
+  // reader:
+  SegmentReader(SegmentReader parent, BitVector liveDocs, int numDocs) throws IOException
{
+    this.si = parent.si;
+    parent.core.incRef();
+    this.core = parent.core;
+
+    assert liveDocs != null;
+    this.liveDocs = liveDocs;
+
+    this.numDocs = numDocs;
+
+    assert checkLiveCounts(true);
   }
 
   @Override
@@ -133,123 +143,37 @@ public final class SegmentReader extends
     return liveDocs;
   }
 
-  private boolean checkLiveCounts() throws IOException {
-    final int recomputedCount = liveDocs.getRecomputedCount();
-    // First verify BitVector is self consistent:
-    assert liveDocs.count() == recomputedCount : "live count=" + liveDocs.count() + " vs
recomputed count=" + recomputedCount;
-
-    assert si.getDelCount() == si.docCount - recomputedCount :
-      "delete count mismatch: info=" + si.getDelCount() + " vs BitVector=" + (si.docCount-recomputedCount);
-
-    // Verify # deletes does not exceed maxDoc for this
-    // segment:
-    assert si.getDelCount() <= maxDoc() : 
-      "delete count mismatch: " + recomputedCount + ") exceeds max doc (" + maxDoc() + ")
for segment " + si.name;
-
-    return true;
-  }
-
-  private void loadLiveDocs(IOContext context) throws IOException {
-    // NOTE: the bitvector is stored using the regular directory, not cfs
-    if (si.hasDeletions()) {
-      liveDocs = new BitVector(directory(), si.getDelFileName(), new IOContext(context, true));
-      liveDocsRef = new AtomicInteger(1);
-      assert checkLiveCounts();
+  private boolean checkLiveCounts(boolean isNRT) throws IOException {
+    if (liveDocs != null) {
       if (liveDocs.size() != si.docCount) {
         throw new CorruptIndexException("document count mismatch: deleted docs count " +
liveDocs.size() + " vs segment doc count " + si.docCount + " segment=" + si.name);
       }
-    } else {
-      assert si.getDelCount() == 0;
-    }
-    // we need a key reflecting actual deletes (if existent or not):
-    combinedCoreAndDeletesKey = new Object();
-  }
-
-  /** Clones are always in readOnly mode */
-  @Override
-  public final synchronized Object clone() {
-    try {
-      return reopenSegment(si, true);
-    } catch (Exception ex) {
-      throw new RuntimeException(ex);
-    }
-  }
-  
-  // used by DirectoryReader:
-  synchronized SegmentReader reopenSegment(SegmentInfo si, boolean doClone) throws CorruptIndexException,
IOException {
-    ensureOpen();
-    boolean deletionsUpToDate = (this.si.hasDeletions() == si.hasDeletions()) 
-                                  && (!si.hasDeletions() || this.si.getDelFileName().equals(si.getDelFileName()));
-
-    // if we're cloning we need to run through the reopenSegment logic
-    // also if both old and new readers aren't readonly, we clone to avoid sharing modifications
-    if (deletionsUpToDate && !doClone && readOnly) {
-      return null;
-    }    
 
-    // When cloning, the incoming SegmentInfos should not
-    // have any changes in it:
-    assert !doClone || (deletionsUpToDate);
+      final int recomputedCount = liveDocs.getRecomputedCount();
+      // Verify BitVector is self consistent:
+      assert liveDocs.count() == recomputedCount : "live count=" + liveDocs.count() + " vs
recomputed count=" + recomputedCount;
+
+      // Verify our docCount matches:
+      assert numDocs == recomputedCount :
+      "delete count mismatch: numDocs=" + numDocs + " vs BitVector=" + (si.docCount-recomputedCount);
 
-    // clone reader
-    SegmentReader clone = new SegmentReader(true, si);
-
-    boolean success = false;
-    try {
-      core.incRef();
-      clone.core = core;
-      clone.pendingDeleteCount = pendingDeleteCount;
-      clone.combinedCoreAndDeletesKey = combinedCoreAndDeletesKey;
-
-      if (doClone) {
-        if (liveDocs != null) {
-          liveDocsRef.incrementAndGet();
-          clone.liveDocs = liveDocs;
-          clone.liveDocsRef = liveDocsRef;
-        }
-      } else {
-        if (!deletionsUpToDate) {
-          // load deleted docs
-          assert clone.liveDocs == null;
-          clone.loadLiveDocs(IOContext.READ);
-        } else if (liveDocs != null) {
-          liveDocsRef.incrementAndGet();
-          clone.liveDocs = liveDocs;
-          clone.liveDocsRef = liveDocsRef;
-        }
-      }
-      success = true;
-    } finally {
-      if (!success) {
-        // An exception occurred during reopen, we have to decRef the norms
-        // that we incRef'ed already and close singleNormsStream and FieldsReader
-        clone.decRef();
-      }
+      assert isNRT || si.docCount - si.getDelCount() == recomputedCount :
+        "si.docCount=" + si.docCount + "si.getDelCount()=" + si.getDelCount() + " recomputedCount="
+ recomputedCount;
     }
-    
-    return clone;
+  
+    return true;
   }
 
   /** @lucene.internal */
   public StoredFieldsReader getFieldsReader() {
     return fieldsReaderLocal.get();
   }
-
+  
   @Override
   protected void doClose() throws IOException {
-    if (hasChanges) {
-      doCommit();
-    }
-    
+    //System.out.println("SR.close seg=" + si);
     termVectorsLocal.close();
     fieldsReaderLocal.close();
-    
-    if (liveDocs != null) {
-      liveDocsRef.decrementAndGet();
-      // null so if an app hangs on to us we still free most ram
-      liveDocs = null;
-    }
-
     if (core != null) {
       core.decRef();
     }
@@ -409,12 +333,9 @@ public final class SegmentReader extends
 
   @Override
   public String toString() {
-    final StringBuilder buffer = new StringBuilder();
-    if (hasChanges) {
-      buffer.append('*');
-    }
-    buffer.append(si.toString(core.dir, pendingDeleteCount));
-    return buffer.toString();
+    // SegmentInfo.toString takes dir and number of
+    // *pending* deletions; so we reverse compute that here:
+    return si.toString(core.dir, si.docCount - numDocs - si.getDelCount());
   }
   
   @Override
@@ -437,10 +358,6 @@ public final class SegmentReader extends
     return si;
   }
 
-  void setSegmentInfo(SegmentInfo info) {
-    si = info;
-  }
-
   /** Returns the directory this index resides in. */
   @Override
   public Directory directory() {
@@ -460,7 +377,7 @@ public final class SegmentReader extends
 
   @Override
   public Object getCombinedCoreAndDeletesKey() {
-    return combinedCoreAndDeletesKey;
+    return this;
   }
   
   @Override
@@ -479,103 +396,6 @@ public final class SegmentReader extends
   }
 
   /**
-   * Clones the deleteDocs BitVector.  May be overridden by subclasses. New and experimental.
-   * @param bv BitVector to clone
-   * @return New BitVector
-   */
-  // TODO: remove deletions from SR
-  BitVector cloneDeletedDocs(BitVector bv) {
-    ensureOpen();
-    return (BitVector)bv.clone();
-  }
-
-  // TODO: remove deletions from SR
-  void doCommit() throws IOException {
-    assert hasChanges;
-    startCommit();
-    boolean success = false;
-    try {
-      commitChanges();
-      success = true;
-    } finally {
-      if (!success) {
-        rollbackCommit();
-      }
-    }
-  }
-
-  // TODO: remove deletions from SR
-  private void startCommit() {
-    rollbackSegmentInfo = (SegmentInfo) si.clone();
-    rollbackHasChanges = hasChanges;
-    rollbackPendingDeleteCount = pendingDeleteCount;
-  }
-
-  // TODO: remove deletions from SR
-  private void rollbackCommit() {
-    si.reset(rollbackSegmentInfo);
-    hasChanges = rollbackHasChanges;
-    pendingDeleteCount = rollbackPendingDeleteCount;
-  }
-
-  // TODO: remove deletions from SR
-  private synchronized void commitChanges() throws IOException {
-    si.advanceDelGen();
-
-    assert liveDocs.length() == si.docCount;
-
-    // We can write directly to the actual name (vs to a
-    // .tmp & renaming it) because the file is not live
-    // until segments file is written:
-    final String delFileName = si.getDelFileName();
-    boolean success = false;
-    try {
-      liveDocs.write(directory(), delFileName, IOContext.DEFAULT);
-      success = true;
-    } finally {
-      if (!success) {
-        try {
-          directory().deleteFile(delFileName);
-        } catch (Throwable t) {
-          // suppress this so we keep throwing the
-          // original exception
-        }
-      }
-    }
-    si.setDelCount(si.getDelCount()+pendingDeleteCount);
-    pendingDeleteCount = 0;
-    assert (maxDoc()-liveDocs.count()) == si.getDelCount(): "delete count mismatch during
commit: info=" + si.getDelCount() + " vs BitVector=" + (maxDoc()-liveDocs.count());
-    hasChanges = false;
-  }
-
-  // TODO: remove deletions from SR
-  synchronized void deleteDocument(int docNum) throws IOException {
-    if (readOnly)
-      throw new UnsupportedOperationException("this SegmentReader is read only");
-    hasChanges = true;
-    if (liveDocs == null) {
-      liveDocs = new BitVector(maxDoc());
-      liveDocs.setAll();
-      liveDocsRef = new AtomicInteger(1);
-    }
-    // there is more than 1 SegmentReader with a reference to this
-    // liveDocs BitVector so decRef the current liveDocsRef,
-    // clone the BitVector, create a new liveDocsRef
-    if (liveDocsRef.get() > 1) {
-      AtomicInteger oldRef = liveDocsRef;
-      liveDocs = cloneDeletedDocs(liveDocs);
-      liveDocsRef = new AtomicInteger(1);
-      oldRef.decrementAndGet();
-    }
-    // we need a key reflecting actual deletes (if existent or not):
-    combinedCoreAndDeletesKey = new Object();
-    // liveDocs are now dirty:
-    if (liveDocs.getAndClear(docNum)) {
-      pendingDeleteCount++;
-    }
-  }
-  
-  /**
    * Called when the shared core for this SegmentReader
    * is closed.
    * <p>

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestExternalCodecs.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestExternalCodecs.java?rev=1221404&r1=1221403&r2=1221404&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestExternalCodecs.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestExternalCodecs.java Tue Dec 20
18:17:33 2011
@@ -58,6 +58,10 @@ public class TestExternalCodecs extends 
   public void testPerFieldCodec() throws Exception {
     
     final int NUM_DOCS = atLeast(173);
+    if (VERBOSE) {
+      System.out.println("TEST: NUM_DOCS=" + NUM_DOCS);
+    }
+
     MockDirectoryWrapper dir = newDirectory();
     dir.setCheckIndexOnClose(false); // we use a custom codec provider
     IndexWriter w = new IndexWriter(
@@ -101,7 +105,14 @@ public class TestExternalCodecs extends 
       System.out.println("\nTEST: now delete 2nd doc");
     }
     w.deleteDocuments(new Term("id", "44"));
+
+    if (VERBOSE) {
+      System.out.println("\nTEST: now force merge");
+    }
     w.forceMerge(1);
+    if (VERBOSE) {
+      System.out.println("\nTEST: now open reader");
+    }
     r = IndexReader.open(w, true);
     assertEquals(NUM_DOCS-2, r.maxDoc());
     assertEquals(NUM_DOCS-2, r.numDocs());
@@ -112,6 +123,9 @@ public class TestExternalCodecs extends 
     assertEquals(0, s.search(new TermQuery(new Term("id", "77")), 1).totalHits);
     assertEquals(0, s.search(new TermQuery(new Term("id", "44")), 1).totalHits);
 
+    if (VERBOSE) {
+      System.out.println("\nTEST: now close NRT reader");
+    }
     r.close();
 
     w.close();

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java?rev=1221404&r1=1221403&r2=1221404&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java Tue Dec 20
18:17:33 2011
@@ -443,6 +443,9 @@ public class TestAddIndexes extends Luce
             setMergePolicy(newLogMergePolicy(4))
     );
 
+    if (VERBOSE) {
+      System.out.println("\nTEST: now addIndexes");
+    }
     writer.addIndexes(aux, new MockDirectoryWrapper(random, new RAMDirectory(aux, newIOContext(random))));
     assertEquals(1020, writer.maxDoc());
     assertEquals(1000, writer.getDocCount(0));

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDoc.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDoc.java?rev=1221404&r1=1221403&r2=1221404&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDoc.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDoc.java Tue Dec 20 18:17:33
2011
@@ -197,8 +197,8 @@ public class TestDoc extends LuceneTestC
    private SegmentInfo merge(Directory dir, SegmentInfo si1, SegmentInfo si2, String merged,
boolean useCompoundFile)
    throws Exception {
       IOContext context = newIOContext(random);
-      SegmentReader r1 = SegmentReader.get(si1, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
context);
-      SegmentReader r2 = SegmentReader.get(si2, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
context);
+      SegmentReader r1 = new SegmentReader(si1, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
context);
+      SegmentReader r2 = new SegmentReader(si2, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
context);
 
       final Codec codec = Codec.getDefault();
       SegmentMerger merger = new SegmentMerger(InfoStream.getDefault(), si1.dir, IndexWriterConfig.DEFAULT_TERM_INDEX_INTERVAL,
merged, MergeState.CheckAbort.NONE, null, new FieldInfos(new FieldInfos.FieldNumberBiMap()),
codec, context);
@@ -225,7 +225,7 @@ public class TestDoc extends LuceneTestC
 
    private void printSegment(PrintWriter out, SegmentInfo si)
    throws Exception {
-      SegmentReader reader = SegmentReader.get(si, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
+      SegmentReader reader = new SegmentReader(si, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
 
       for (int i = 0; i < reader.numDocs(); i++)
         out.println(reader.document(i));

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java?rev=1221404&r1=1221403&r2=1221404&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java Tue Dec
20 18:17:33 2011
@@ -64,7 +64,7 @@ public class TestDocumentWriter extends 
     SegmentInfo info = writer.newestSegment();
     writer.close();
     //After adding the document, we should be able to read it back in
-    SegmentReader reader = SegmentReader.get(info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
+    SegmentReader reader = new SegmentReader(info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
     assertTrue(reader != null);
     Document doc = reader.document(0);
     assertTrue(doc != null);
@@ -94,7 +94,7 @@ public class TestDocumentWriter extends 
 
     // test that the norms are not present in the segment if
     // omitNorms is true
-    for (FieldInfo fi : reader.core.fieldInfos) {
+    for (FieldInfo fi : reader.fieldInfos()) {
       if (fi.isIndexed) {
         assertTrue(fi.omitNorms == !reader.hasNorms(fi.name));
       }
@@ -125,7 +125,7 @@ public class TestDocumentWriter extends 
     writer.commit();
     SegmentInfo info = writer.newestSegment();
     writer.close();
-    SegmentReader reader = SegmentReader.get(info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
+    SegmentReader reader = new SegmentReader(info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
 
     DocsAndPositionsEnum termPositions = MultiFields.getTermPositionsEnum(reader, MultiFields.getLiveDocs(reader),
                                                                           "repeated", new
BytesRef("repeated"));
@@ -197,7 +197,7 @@ public class TestDocumentWriter extends 
     writer.commit();
     SegmentInfo info = writer.newestSegment();
     writer.close();
-    SegmentReader reader = SegmentReader.get(info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
+    SegmentReader reader = new SegmentReader(info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
 
     DocsAndPositionsEnum termPositions = MultiFields.getTermPositionsEnum(reader, reader.getLiveDocs(),
"f1", new BytesRef("a"));
     assertTrue(termPositions.nextDoc() != termPositions.NO_MORE_DOCS);
@@ -241,7 +241,7 @@ public class TestDocumentWriter extends 
     writer.commit();
     SegmentInfo info = writer.newestSegment();
     writer.close();
-    SegmentReader reader = SegmentReader.get(info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
+    SegmentReader reader = new SegmentReader(info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
 
     DocsAndPositionsEnum termPositions = reader.termPositionsEnum(reader.getLiveDocs(), "preanalyzed",
new BytesRef("term1"));
     assertTrue(termPositions.nextDoc() != termPositions.NO_MORE_DOCS);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReader.java?rev=1221404&r1=1221403&r2=1221404&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReader.java Tue Dec
20 18:17:33 2011
@@ -717,36 +717,6 @@ public class TestIndexReader extends Luc
     dir.close();
   }
 
-  // LUCENE-1579: Ensure that on a cloned reader, segments
-  // reuse the doc values arrays in FieldCache
-  public void testFieldCacheReuseAfterClone() throws Exception {
-    Directory dir = newDirectory();
-    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random)));
-    Document doc = new Document();
-    doc.add(newField("number", "17", StringField.TYPE_UNSTORED));
-    writer.addDocument(doc);
-    writer.close();
-
-    // Open reader
-    IndexReader r = getOnlySegmentReader(IndexReader.open(dir));
-    final int[] ints = FieldCache.DEFAULT.getInts(r, "number", false);
-    assertEquals(1, ints.length);
-    assertEquals(17, ints[0]);
-
-    // Clone reader
-    IndexReader r2 = (IndexReader) r.clone();
-    r.close();
-    assertTrue(r2 != r);
-    final int[] ints2 = FieldCache.DEFAULT.getInts(r2, "number", false);
-    r2.close();
-
-    assertEquals(1, ints2.length);
-    assertEquals(17, ints2[0]);
-    assertTrue(ints == ints2);
-
-    dir.close();
-  }
-
   // LUCENE-1579: Ensure that on a reopened reader, that any
   // shared segments reuse the doc values arrays in
   // FieldCache

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=1221404&r1=1221403&r2=1221404&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java Tue Dec
20 18:17:33 2011
@@ -1128,8 +1128,7 @@ public class TestIndexWriter extends Luc
     writer2.close();
 
     IndexReader r1 = IndexReader.open(dir2);
-    IndexReader r2 = (IndexReader) r1.clone();
-    writer.addIndexes(r1, r2);
+    writer.addIndexes(r1, r1);
     writer.close();
 
     IndexReader r3 = IndexReader.open(dir);
@@ -1137,7 +1136,6 @@ public class TestIndexWriter extends Luc
     r3.close();
 
     r1.close();
-    r2.close();
 
     dir2.close();
     dir.close();

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestMultiReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestMultiReader.java?rev=1221404&r1=1221403&r2=1221404&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestMultiReader.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestMultiReader.java Tue Dec
20 18:17:33 2011
@@ -38,8 +38,8 @@ public class TestMultiReader extends Tes
     IndexReader reader;
 
     sis.read(dir);
-    SegmentReader reader1 = SegmentReader.get(sis.info(0), IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
-    SegmentReader reader2 = SegmentReader.get(sis.info(1), IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
+    SegmentReader reader1 = new SegmentReader(sis.info(0), IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
+    SegmentReader reader2 = new SegmentReader(sis.info(1), IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
     readers[0] = reader1;
     readers[1] = reader2;
     assertTrue(reader1 != null);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSegmentMerger.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSegmentMerger.java?rev=1221404&r1=1221403&r2=1221404&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSegmentMerger.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSegmentMerger.java Tue Dec
20 18:17:33 2011
@@ -24,7 +24,6 @@ import org.apache.lucene.analysis.MockAn
 import org.apache.lucene.codecs.Codec;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.TextField;
-import org.apache.lucene.index.IndexWriterConfig.OpenMode;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.InfoStream;
@@ -54,8 +53,8 @@ public class TestSegmentMerger extends L
     SegmentInfo info1 = DocHelper.writeDoc(random, merge1Dir, doc1);
     DocHelper.setupDoc(doc2);
     SegmentInfo info2 = DocHelper.writeDoc(random, merge2Dir, doc2);
-    reader1 = SegmentReader.get(info1, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, newIOContext(random));
-    reader2 = SegmentReader.get(info2, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, newIOContext(random));
+    reader1 = new SegmentReader(info1, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, newIOContext(random));
+    reader2 = new SegmentReader(info2, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, newIOContext(random));
   }
 
   @Override
@@ -86,9 +85,9 @@ public class TestSegmentMerger extends L
     assertTrue(docsMerged == 2);
     final FieldInfos fieldInfos = mergeState.fieldInfos;
     //Should be able to open a new SegmentReader against the new directory
-    SegmentReader mergedReader = SegmentReader.getRW(new SegmentInfo(mergedSegment, docsMerged,
mergedDir, false,
+    SegmentReader mergedReader = new SegmentReader(new SegmentInfo(mergedSegment, docsMerged,
mergedDir, false,
                                                                                      codec,
fieldInfos),
-                                                   true, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
+                                                   IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
     assertTrue(mergedReader != null);
     assertTrue(mergedReader.numDocs() == 2);
     Document newDoc1 = mergedReader.document(0);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSegmentReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSegmentReader.java?rev=1221404&r1=1221403&r2=1221404&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSegmentReader.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSegmentReader.java Tue Dec
20 18:17:33 2011
@@ -41,7 +41,7 @@ public class TestSegmentReader extends L
     dir = newDirectory();
     DocHelper.setupDoc(testDoc);
     SegmentInfo info = DocHelper.writeDoc(random, dir, testDoc);
-    reader = SegmentReader.get(info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, IOContext.READ);
+    reader = new SegmentReader(info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, IOContext.READ);
   }
   
   @Override
@@ -73,50 +73,6 @@ public class TestSegmentReader extends L
     }
   }
   
-  public void testDelete() throws IOException {
-    Document docToDelete = new Document();
-    DocHelper.setupDoc(docToDelete);
-    SegmentInfo info = DocHelper.writeDoc(random, dir, docToDelete);
-    SegmentReader deleteReader = SegmentReader.getRW(info, true, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR,
newIOContext(random));
-    assertNotNull(deleteReader);
-    assertEquals(1, deleteReader.numDocs());
-    final Object combKey = deleteReader.getCombinedCoreAndDeletesKey();
-    final Object coreKey = deleteReader.getCoreCacheKey();
-    assertNotNull(combKey);
-    assertNotNull(coreKey);
-    assertNotSame(combKey, coreKey);
-
-    SegmentReader clone1 = (SegmentReader) deleteReader.clone();
-    assertSame(coreKey, clone1.getCoreCacheKey());    
-    assertSame(combKey, clone1.getCombinedCoreAndDeletesKey());
-
-    deleteReader.deleteDocument(0);
-    final Object newCombKey = deleteReader.getCombinedCoreAndDeletesKey();
-    assertNotNull(newCombKey);
-    assertNotSame(combKey, newCombKey);
-    assertSame(coreKey, deleteReader.getCoreCacheKey());
-    assertFalse(deleteReader.getLiveDocs().get(0));
-    assertTrue(deleteReader.hasDeletions());
-    assertTrue(deleteReader.numDocs() == 0);
-    
-    SegmentReader clone2 = (SegmentReader) deleteReader.clone();
-    assertSame(coreKey, clone2.getCoreCacheKey());    
-    assertSame(newCombKey, clone2.getCombinedCoreAndDeletesKey());
-    assertFalse(clone2.getLiveDocs().get(0));
-    assertTrue(clone2.hasDeletions());
-    assertEquals(0, clone2.numDocs());
-    clone2.close();
-    
-    assertSame(coreKey, clone1.getCoreCacheKey());    
-    assertSame(combKey, clone1.getCombinedCoreAndDeletesKey());
-    assertNull(clone1.getLiveDocs());
-    assertFalse(clone1.hasDeletions());
-    assertEquals(1, clone2.numDocs());
-    clone1.close();
-
-    deleteReader.close();
-  }
-  
   public void testGetFieldNameVariations() {
     Collection<String> result = reader.getFieldNames(IndexReader.FieldOption.ALL);
     assertTrue(result != null);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSegmentTermDocs.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSegmentTermDocs.java?rev=1221404&r1=1221403&r2=1221404&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSegmentTermDocs.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSegmentTermDocs.java Tue
Dec 20 18:17:33 2011
@@ -56,7 +56,7 @@ public class TestSegmentTermDocs extends
 
   public void testTermDocs(int indexDivisor) throws IOException {
     //After adding the document, we should be able to read it back in
-    SegmentReader reader = SegmentReader.get(info, indexDivisor, newIOContext(random));
+    SegmentReader reader = new SegmentReader(info, indexDivisor, newIOContext(random));
     assertTrue(reader != null);
     assertEquals(indexDivisor, reader.getTermInfosIndexDivisor());
 
@@ -79,7 +79,7 @@ public class TestSegmentTermDocs extends
   public void testBadSeek(int indexDivisor) throws IOException {
     {
       //After adding the document, we should be able to read it back in
-      SegmentReader reader = SegmentReader.get(info, indexDivisor, newIOContext(random));
+      SegmentReader reader = new SegmentReader(info, indexDivisor, newIOContext(random));
       assertTrue(reader != null);
       DocsEnum termDocs = _TestUtil.docs(random, reader,
                                          "textField2",
@@ -93,7 +93,7 @@ public class TestSegmentTermDocs extends
     }
     {
       //After adding the document, we should be able to read it back in
-      SegmentReader reader = SegmentReader.get(info, indexDivisor, newIOContext(random));
+      SegmentReader reader = new SegmentReader(info, indexDivisor, newIOContext(random));
       assertTrue(reader != null);
       DocsEnum termDocs = _TestUtil.docs(random, reader,
                                          "junk",

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestTieredMergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestTieredMergePolicy.java?rev=1221404&r1=1221403&r2=1221404&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestTieredMergePolicy.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestTieredMergePolicy.java Tue
Dec 20 18:17:33 2011
@@ -132,6 +132,10 @@ public class TestTieredMergePolicy exten
     assertEquals(numDocs, r.numDocs());
     r.close();
 
+    if (VERBOSE) {
+      System.out.println("\nTEST: delete doc");
+    }
+
     w.deleteDocuments(new Term("id", ""+(42+17)));
 
     r = w.getReader();



Mime
View raw message