lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r1210273 - in /lucene/dev/branches/lucene3606/lucene/src: java/org/apache/lucene/index/ test/org/apache/lucene/index/
Date Sun, 04 Dec 2011 23:12:28 GMT
Author: uschindler
Date: Sun Dec  4 23:12:28 2011
New Revision: 1210273

URL: http://svn.apache.org/viewvc?rev=1210273&view=rev
Log:
LUCENE-3606: remove more readOnly booleans

Modified:
    lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
    lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/IndexReader.java
    lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/SegmentReader.java
    lucene/dev/branches/lucene3606/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java

Modified: lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/DirectoryReader.java?rev=1210273&r1=1210272&r2=1210273&view=diff
==============================================================================
--- lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
(original)
+++ lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
Sun Dec  4 23:12:28 2011
@@ -44,7 +44,6 @@ import org.apache.lucene.util.MapBackedS
  */
 class DirectoryReader extends IndexReader implements Cloneable {
   protected Directory directory;
-  protected boolean readOnly = true; // nocommit: remove this
 
   IndexWriter writer;
 
@@ -58,28 +57,23 @@ class DirectoryReader extends IndexReade
   private int numDocs = -1;
   private boolean hasDeletions = false;
 
-  // Max version in index as of when we opened; this can be
-  // > our current segmentInfos version in case we were
-  // opened on a past IndexCommit:
-  private long maxIndexVersion;
-
   private final boolean applyAllDeletes;
 
-  static IndexReader open(final Directory directory, final IndexCommit commit, final boolean
readOnly,
+  static IndexReader open(final Directory directory, final IndexCommit commit,
                           final int termInfosIndexDivisor) throws CorruptIndexException,
IOException {
     return (IndexReader) new SegmentInfos.FindSegmentsFile(directory) {
       @Override
       protected Object doBody(String segmentFileName) throws CorruptIndexException, IOException
{
         SegmentInfos infos = new SegmentInfos();
         infos.read(directory, segmentFileName);
-        return new DirectoryReader(directory, infos, readOnly, termInfosIndexDivisor);
+        return new DirectoryReader(directory, infos, termInfosIndexDivisor);
       }
     }.run(commit);
   }
+  
   /** Construct reading the named set of readers. */
-  DirectoryReader(Directory directory, SegmentInfos sis, boolean readOnly, int termInfosIndexDivisor)
throws IOException {
+  DirectoryReader(Directory directory, SegmentInfos sis, int termInfosIndexDivisor) throws
IOException {
     this.directory = directory;
-    this.readOnly = true; // nocommit: remove readOnly at all
     this.segmentInfos = sis;
     this.termInfosIndexDivisor = termInfosIndexDivisor;
     readerFinishedListeners = new MapBackedSet<ReaderFinishedListener>(new ConcurrentHashMap<ReaderFinishedListener,Boolean>());
@@ -94,7 +88,7 @@ class DirectoryReader extends IndexReade
     for (int i = sis.size()-1; i >= 0; i--) {
       boolean success = false;
       try {
-        readers[i] = SegmentReader.get(readOnly, sis.info(i), termInfosIndexDivisor, IOContext.READ);
+        readers[i] = SegmentReader.get(true /** nocommit: remove readOnly */, sis.info(i),
termInfosIndexDivisor, IOContext.READ);
         readers[i].readerFinishedListeners = readerFinishedListeners;
         success = true;
       } finally {
@@ -117,7 +111,6 @@ class DirectoryReader extends IndexReade
   // Used by near real-time search
   DirectoryReader(IndexWriter writer, SegmentInfos infos, boolean applyAllDeletes) throws
IOException {
     this.directory = writer.getDirectory();
-    this.readOnly = true;
     this.applyAllDeletes = applyAllDeletes;       // saved for reopen
 
     this.termInfosIndexDivisor = writer.getConfig().getReaderTermsIndexDivisor();
@@ -169,9 +162,8 @@ class DirectoryReader extends IndexReade
 
   /** This constructor is only used for {@link #doOpenIfChanged()} */
   DirectoryReader(Directory directory, SegmentInfos infos, SegmentReader[] oldReaders,
-                  boolean readOnly, boolean doClone, int termInfosIndexDivisor, Collection<ReaderFinishedListener>
readerFinishedListeners) throws IOException {
+                  boolean doClone, int termInfosIndexDivisor, Collection<ReaderFinishedListener>
readerFinishedListeners) throws IOException {
     this.directory = directory;
-    this.readOnly = readOnly;
     this.segmentInfos = infos;
     this.termInfosIndexDivisor = termInfosIndexDivisor;
     this.readerFinishedListeners = readerFinishedListeners;
@@ -214,12 +206,12 @@ class DirectoryReader extends IndexReade
           assert !doClone;
 
           // this is a new reader; in case we hit an exception we can close it safely
-          newReader = SegmentReader.get(readOnly, infos.info(i), termInfosIndexDivisor, IOContext.READ);
+          newReader = SegmentReader.get(true, infos.info(i), termInfosIndexDivisor, IOContext.READ);
           newReader.readerFinishedListeners = readerFinishedListeners;
           readerShared[i] = false;
           newReaders[i] = newReader;
         } else {
-          newReader = newReaders[i].reopenSegment(infos.info(i), doClone, readOnly);
+          newReader = newReaders[i].reopenSegment(infos.info(i), doClone, true /* nocommit:
remove readOnly */);
           if (newReader == null) {
             // this reader will be shared between the old and the new one,
             // so we must incRef it
@@ -303,10 +295,6 @@ class DirectoryReader extends IndexReade
       }
     }
     starts[subReaders.length] = maxDoc;
-
-    if (!readOnly) {
-      maxIndexVersion = SegmentInfos.readCurrentVersion(directory);
-    }
   }
 
   @Override
@@ -317,7 +305,7 @@ class DirectoryReader extends IndexReade
   @Override
   public final synchronized Object clone() {
     try {
-      return clone(readOnly); // Preserve current readOnly
+      return clone(true);
     } catch (Exception ex) {
       throw new RuntimeException(ex);
     }
@@ -325,6 +313,7 @@ class DirectoryReader extends IndexReade
 
   @Override
   public final synchronized IndexReader clone(boolean openReadOnly) throws CorruptIndexException,
IOException {
+    assert openReadOnly;
     // doOpenIfChanged calls ensureOpen
     DirectoryReader newReader = doOpenIfChanged((SegmentInfos) segmentInfos.clone(), true,
openReadOnly);
 
@@ -337,8 +326,7 @@ class DirectoryReader extends IndexReade
 
   @Override
   protected final IndexReader doOpenIfChanged() throws CorruptIndexException, IOException
{
-    // Preserve current readOnly
-    return doOpenIfChanged(readOnly, null);
+    return doOpenIfChanged(true, null);
   }
 
   @Override
@@ -361,11 +349,7 @@ class DirectoryReader extends IndexReade
   }
 
   private final IndexReader doOpenFromWriter(boolean openReadOnly, IndexCommit commit) throws
CorruptIndexException, IOException {
-    assert readOnly;
-
-    if (!openReadOnly) {
-      throw new IllegalArgumentException("a reader obtained from IndexWriter.getReader()
can only be reopened with openReadOnly=true (got false)");
-    }
+    assert openReadOnly;
 
     if (commit != null) {
       throw new IllegalArgumentException("a reader obtained from IndexWriter.getReader()
cannot currently accept a commit");
@@ -390,7 +374,7 @@ class DirectoryReader extends IndexReade
   private IndexReader doOpenIfChanged(final boolean openReadOnly, IndexCommit commit) throws
CorruptIndexException, IOException {
     ensureOpen();
 
-    assert commit == null || openReadOnly;
+    assert openReadOnly;
 
     // If we were obtained by writer.getReader(), re-ask the
     // writer to get a new reader.
@@ -427,7 +411,8 @@ class DirectoryReader extends IndexReade
   }
 
   private synchronized DirectoryReader doOpenIfChanged(SegmentInfos infos, boolean doClone,
boolean openReadOnly) throws CorruptIndexException, IOException {
-    return new DirectoryReader(directory, infos, subReaders, openReadOnly, doClone, termInfosIndexDivisor,
readerFinishedListeners);
+    assert openReadOnly;
+    return new DirectoryReader(directory, infos, subReaders, doClone, termInfosIndexDivisor,
readerFinishedListeners);
   }
 
   /** Version number when this IndexReader was opened. */

Modified: lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/IndexReader.java?rev=1210273&r1=1210272&r2=1210273&view=diff
==============================================================================
--- lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/IndexReader.java
(original)
+++ lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/IndexReader.java
Sun Dec  4 23:12:28 2011
@@ -456,8 +456,8 @@ public abstract class IndexReader implem
   }
 
   private static IndexReader open(final Directory directory, final IndexDeletionPolicy deletionPolicy,
final IndexCommit commit, final boolean readOnly, int termInfosIndexDivisor) throws CorruptIndexException,
IOException {
-    // nocommit: deletionPolicy is ignored -> remove it
-    return DirectoryReader.open(directory, commit, readOnly, termInfosIndexDivisor);
+    // nocommit: deletionPolicy is ignored -> remove it, same for readonly
+    return DirectoryReader.open(directory, commit, termInfosIndexDivisor);
   }
 
   /**

Modified: lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/SegmentReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/SegmentReader.java?rev=1210273&r1=1210272&r2=1210273&view=diff
==============================================================================
--- lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/SegmentReader.java
(original)
+++ lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/SegmentReader.java
Sun Dec  4 23:12:28 2011
@@ -51,14 +51,13 @@ public class SegmentReader extends Index
   boolean hasChanges = false;
   private boolean liveDocsDirty = false;
 
-  // TODO: we should move this tracking into SegmentInfo;
-  // this way SegmentInfo.toString shows pending deletes
+  // nocommit: move the whole modification stuff to IW
   private int pendingDeleteCount;
-
   private boolean rollbackHasChanges = false;
   private boolean rollbackDeletedDocsDirty = false;
   private SegmentInfo rollbackSegmentInfo;
   private int rollbackPendingDeleteCount;
+  // end nocommit
 
   SegmentCoreReaders core;
 

Modified: lucene/dev/branches/lucene3606/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3606/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java?rev=1210273&r1=1210272&r2=1210273&view=diff
==============================================================================
--- lucene/dev/branches/lucene3606/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java
(original)
+++ lucene/dev/branches/lucene3606/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java
Sun Dec  4 23:12:28 2011
@@ -17,14 +17,11 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
-import org.apache.lucene.search.similarities.DefaultSimilarity;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.TextField;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.LockObtainFailedException;
 import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.Bits;
 
 /**
  * Tests cloning multiple types of readers, modifying the liveDocs and norms
@@ -32,63 +29,6 @@ import org.apache.lucene.util.Bits;
  * implemented properly
  */
 public class TestIndexReaderClone extends LuceneTestCase {
-  
-  // open non-readOnly reader1 on multi-segment index, then
-  // fully merge the index, then clone to readOnly reader2
-  public void testReadOnlyCloneAfterFullMerge() throws Exception {
-    final Directory dir1 = newDirectory();
-
-    TestIndexReaderReopen.createIndex(random, dir1, true);
-    IndexReader reader1 = IndexReader.open(dir1, false);
-    IndexWriter w = new IndexWriter(dir1, newIndexWriterConfig(
-        TEST_VERSION_CURRENT, new MockAnalyzer(random)));
-    w.forceMerge(1);
-    w.close();
-    IndexReader reader2 = reader1.clone(true);
-    assertTrue(isReadOnly(reader2));
-    reader1.close();
-    reader2.close();
-    dir1.close();
-  }
-  
-  public void testCloneReadOnlyDirectoryReader() throws Exception {
-    final Directory dir1 = newDirectory();
-
-    TestIndexReaderReopen.createIndex(random, dir1, true);
-    IndexReader reader = IndexReader.open(dir1, false);
-    IndexReader readOnlyReader = reader.clone(true);
-    if (!isReadOnly(readOnlyReader)) {
-      fail("reader isn't read only");
-    }
-    reader.close();
-    readOnlyReader.close();
-    dir1.close();
-  }
-
-  public static boolean isReadOnly(IndexReader r) {
-    if (r instanceof SegmentReader) {
-      return ((SegmentReader) r).readOnly;
-    } else if (r instanceof DirectoryReader) {
-      return ((DirectoryReader) r).readOnly;
-    } else {
-      return false;
-    }
-  }
-
-  public void testSegmentReaderCloseReferencing() throws Exception {
-    final Directory dir1 = newDirectory();
-    TestIndexReaderReopen.createIndex(random, dir1, false);
-    SegmentReader origSegmentReader = getOnlySegmentReader(IndexReader.open(dir1, false));
-    origSegmentReader.deleteDocument(1);
-
-    SegmentReader clonedSegmentReader = (SegmentReader) origSegmentReader
-        .clone();
-    assertDelDocsRefCountEquals(2, origSegmentReader);
-    origSegmentReader.close();
-    assertDelDocsRefCountEquals(1, origSegmentReader);
-    clonedSegmentReader.close();
-    dir1.close();
-  }
 
   private void assertDelDocsRefCountEquals(int refCount, SegmentReader reader) {
     assertEquals(refCount, reader.liveDocsRef.get());
@@ -105,8 +45,8 @@ public class TestIndexReaderClone extend
     doc.add(newField("field", "yes it's stored", TextField.TYPE_STORED));
     w.addDocument(doc);
     w.close();
-    IndexReader r1 = IndexReader.open(dir, false);
-    IndexReader r2 = r1.clone(false);
+    IndexReader r1 = IndexReader.open(dir);
+    IndexReader r2 = (IndexReader) r1.clone();
     r1.close();
     r2.close();
     dir.close();



Mime
View raw message