lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r634251 - in /lucene/java/trunk: ./ src/java/org/apache/lucene/index/ src/test/org/apache/lucene/ src/test/org/apache/lucene/index/
Date Thu, 06 Mar 2008 12:57:10 GMT
Author: mikemccand
Date: Thu Mar  6 04:57:08 2008
New Revision: 634251

URL: http://svn.apache.org/viewvc?rev=634251&view=rev
Log:
LUCENE-1201: add IndexReader.getIndexCommit to see which index commit a reader is reading

Added:
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java   (with props)
Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommitPoint.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexDeletionPolicy.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/trunk/src/java/org/apache/lucene/index/KeepOnlyLastCommitDeletionPolicy.java
    lucene/java/trunk/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java
    lucene/java/trunk/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.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=634251&r1=634250&r2=634251&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Thu Mar  6 04:57:08 2008
@@ -110,6 +110,9 @@
     and isLocked methods (deprecating the ones in IndexReader).  (Mike
     McCandless)
 
+10. LUCENE-1201: Add IndexReader.getIndexCommit() method. (Tim Brennan
+    via Mike McCandless)
+
 Optimizations
 
  1. LUCENE-705: When building a compound file, use

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=634251&r1=634250&r2=634251&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 Mar 
6 04:57:08 2008
@@ -20,6 +20,8 @@
 import java.io.IOException;
 
 import java.util.HashSet;
+import java.util.Collection;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.lucene.store.Directory;
@@ -96,7 +98,6 @@
     }.run();
   }
 
-  
   public final synchronized IndexReader reopen() throws CorruptIndexException, IOException
{
     ensureOpen();
 
@@ -337,4 +338,42 @@
     }
   }
 
+  private static class ReaderCommit extends IndexCommit {
+    private String segmentsFileName;
+    Collection files;
+    Directory dir;
+
+    ReaderCommit(SegmentInfos infos, Directory dir) throws IOException {
+      segmentsFileName = infos.getCurrentSegmentFileName();
+      this.dir = dir;
+      final int size = infos.size();
+      files = new ArrayList(size);
+      files.add(segmentsFileName);
+      for(int i=0;i<size;i++) {
+        SegmentInfo info = infos.info(i);
+        if (info.dir == dir)
+          files.addAll(info.files());
+      }
+    }
+    public String getSegmentsFileName() {
+      return segmentsFileName;
+    }
+    public Collection getFileNames() {
+      return files;
+    }
+    public Directory getDirectory() {
+      return dir;
+    }
+  }
+
+  /**
+   * Expert: return the IndexCommit that this reader has
+   * opened.
+   *
+   * <p><b>WARNING</b>: this API is new and experimental and
+   * may suddenly change.</p>
+   */
+  public IndexCommit getIndexCommit() throws IOException {
+    return new ReaderCommit(segmentInfos, directory);
+  }
 }

Added: lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java?rev=634251&view=auto
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java (added)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java Thu Mar  6 04:57:08
2008
@@ -0,0 +1,92 @@
+package org.apache.lucene.index;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+import java.util.Collection;
+import java.io.IOException;
+import org.apache.lucene.store.Directory;
+
+/**
+ * <p>Expert: represents a single commit into an index as seen by the
+ * {@link IndexDeletionPolicy} or {@link IndexReader}.</p>
+ *
+ * <p> Changes to the content of an index are made visible
+ * only after the writer who made that change commits by
+ * writing a new segments file
+ * (<code>segments_N</code>). This point in time, when the
+ * action of writing of a new segments file to the directory
+ * is completed, is an index commit.</p>
+ *
+ * <p>Each index commit point has a unique segments file
+ * associated with it. The segments file associated with a
+ * later index commit point would have a larger N.</p>
+ *
+ * <p><b>WARNING</b>: This API is a new and experimental and
+ * may suddenly change. </p>
+*/
+
+public abstract class IndexCommit implements IndexCommitPoint {
+
+  /**
+   * Get the segments file (<code>segments_N</code>) associated 
+   * with this commit point.
+   */
+  public abstract String getSegmentsFileName();
+
+  /**
+   * Returns all index files referenced by this commit point.
+   */
+  public abstract Collection getFileNames() throws IOException;
+
+  /**
+   * Returns the {@link Directory} for the index.
+   */
+  public abstract Directory getDirectory();
+  
+  /**
+   * Delete this commit point.  This only applies when using
+   * the commit point in the context of IndexWriter's
+   * IndexDeletionPolicy.
+   * <p>
+   * Upon calling this, the writer is notified that this commit 
+   * point should be deleted. 
+   * <p>
+   * Decision that a commit-point should be deleted is taken by the {@link IndexDeletionPolicy}
in effect
+   * and therefore this should only be called by its {@link IndexDeletionPolicy#onInit onInit()}
or 
+   * {@link IndexDeletionPolicy#onCommit onCommit()} methods.
+  */
+  public void delete() {
+    throw new UnsupportedOperationException("This IndexCommit does not support this method.");
+  }
+
+  /**
+   * Two IndexCommits are equal if both their Directory and
+   * segmentsFileName are equal.
+   */
+  public boolean equals(Object other) {
+    if (other instanceof IndexCommit) {
+      IndexCommit otherCommit = (IndexCommit) other;
+      return otherCommit.getDirectory().equals(getDirectory()) && otherCommit.getSegmentsFileName().equals(getSegmentsFileName());
+    } else
+      return false;
+  }
+
+  public int hashCode() {
+    return getDirectory().hashCode() + getSegmentsFileName().hashCode();
+  }
+}

Propchange: lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommitPoint.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommitPoint.java?rev=634251&r1=634250&r2=634251&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommitPoint.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommitPoint.java Thu Mar  6 04:57:08
2008
@@ -17,23 +17,12 @@
  * limitations under the License.
  */
 
-/**
- * <p>Expert: represents a single commit into an index as seen by the
- * {@link IndexDeletionPolicy}. 
- * <p>
- * Changes to the content of an index are made visible only
- * after the writer who made that change had written to the
- * directory a new segments file (<code>segments_N</code>). This point in 
- * time, when the action of writing of a new segments file to the
- * directory is completed, is therefore an index commit point.
- * <p>
- * Each index commit point has a unique segments file associated
- * with it. The segments file associated with a later 
- * index commit point would have a larger N.
- */
-
 import java.util.Collection;
 import java.io.IOException;
+
+/**
+ * @deprecated Please subclass IndexCommit class instead
+ */
 
 public interface IndexCommitPoint {
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexDeletionPolicy.java?rev=634251&r1=634250&r2=634251&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexDeletionPolicy.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexDeletionPolicy.java Thu Mar  6
04:57:08 2008
@@ -21,12 +21,12 @@
 import java.io.IOException;
 
 /**
- * <p>Expert: policy for deletion of stale {@link IndexCommitPoint index commits}.

+ * <p>Expert: policy for deletion of stale {@link IndexCommit index commits}. 
  * 
  * <p>Implement this interface, and pass it to one
  * of the {@link IndexWriter} or {@link IndexReader}
  * constructors, to customize when older
- * {@link IndexCommitPoint point-in-time commits}
+ * {@link IndexCommit point-in-time commits}
  * are deleted from the index directory.  The default deletion policy
  * is {@link KeepOnlyLastCommitDeletionPolicy}, which always
  * removes old commits as soon as a new commit is done (this
@@ -58,8 +58,8 @@
    * <p>The writer locates all index commits present in the 
    * index directory and calls this method.  The policy may 
    * choose to delete some of the commit points, doing so by
-   * calling method {@link IndexCommitPoint#delete delete()} 
-   * of {@link IndexCommitPoint}.</p>
+   * calling method {@link IndexCommit#delete delete()} 
+   * of {@link IndexCommit}.</p>
    * 
    * <p><u>Note:</u> the last CommitPoint is the most recent one,
    * i.e. the "front index state". Be careful not to delete it,
@@ -67,7 +67,7 @@
    * you can afford to lose the index content while doing that. 
    *
    * @param commits List of current 
-   * {@link IndexCommitPoint point-in-time commits},
+   * {@link IndexCommit point-in-time commits},
    *  sorted by age (the 0th one is the oldest commit).
    */
   public void onInit(List commits) throws IOException;
@@ -78,8 +78,8 @@
    * with each commit.</p>
    *
    * <p>The policy may now choose to delete old commit points 
-   * by calling method {@link IndexCommitPoint#delete delete()} 
-   * of {@link IndexCommitPoint}.</p>
+   * by calling method {@link IndexCommit#delete delete()} 
+   * of {@link IndexCommit}.</p>
    * 
    * <p>If writer has <code>autoCommit = true</code> then
    * this method will in general be called many times during
@@ -94,7 +94,7 @@
    * unless you know for sure what you are doing, and unless 
    * you can afford to lose the index content while doing that.
    *  
-   * @param commits List of {@link IndexCommitPoint},
+   * @param commits List of {@link IndexCommit},
    *  sorted by age (the 0th one is the oldest commit).
    */
   public void onCommit(List commits) throws IOException;

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java?rev=634251&r1=634250&r2=634251&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java Thu Mar  6 04:57:08
2008
@@ -48,7 +48,7 @@
  * force a blocking commit.
  * 
  * The same directory file may be referenced by more than
- * one IndexCommitPoints, i.e. more than one SegmentInfos.
+ * one IndexCommit, i.e. more than one SegmentInfos.
  * Therefore we count how many commits reference each file.
  * When all the commits referencing a certain file have been
  * deleted, the refcount for that file becomes zero, and the
@@ -569,7 +569,7 @@
    * equals.
    */
 
-  final private static class CommitPoint implements Comparable, IndexCommitPoint {
+  final private static class CommitPoint extends IndexCommit implements Comparable {
 
     long gen;
     List files;
@@ -594,15 +594,16 @@
       }
     }
 
-    /**
-     * Get the segments_N file for this commit point.
-     */
     public String getSegmentsFileName() {
       return segmentsFileName;
     }
 
     public Collection getFileNames() throws IOException {
       return Collections.unmodifiableCollection(files);
+    }
+
+    public Directory getDirectory() {
+      return directory;
     }
 
     /**

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java?rev=634251&r1=634250&r2=634251&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java Thu Mar  6 04:57:08
2008
@@ -886,6 +886,19 @@
   }
 
   /**
+   * Expert: return the IndexCommit that this reader has
+   * opened.  This method is only implemented by those
+   * readers that correspond to a Directory with its own
+   * segments_N file.
+   *
+   * <p><b>WARNING</b>: this API is new and experimental and
+   * may suddenly change.</p>
+   */
+  public IndexCommit getIndexCommit() throws IOException {
+    throw new UnsupportedOperationException("This reader does not support this method.");
+  }
+  
+  /**
    * Prints the filename and size of each file within a given compound file.
    * Add the -extract flag to extract files to the current working directory.
    * In order to make the extracted version of the index work, you have to copy

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java?rev=634251&r1=634250&r2=634251&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java Thu Mar  6 04:57:08
2008
@@ -187,7 +187,7 @@
  * modified) directory files, we have a new "check point". 
  * If the modified/new SegmentInfos is written to disk - as a new 
  * (generation of) segments_N file - this check point is also an 
- * IndexCommitPoint.
+ * IndexCommit.
  * 
  * With autoCommit=true, every checkPoint is also a CommitPoint.
  * With autoCommit=false, some checkPoints may not be commits.

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/KeepOnlyLastCommitDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/KeepOnlyLastCommitDeletionPolicy.java?rev=634251&r1=634250&r2=634251&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/KeepOnlyLastCommitDeletionPolicy.java
(original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/KeepOnlyLastCommitDeletionPolicy.java
Thu Mar  6 04:57:08 2008
@@ -44,7 +44,7 @@
     // called by onInit above):
     int size = commits.size();
     for(int i=0;i<size-1;i++) {
-      ((IndexCommitPoint) commits.get(i)).delete();
+      ((IndexCommit) commits.get(i)).delete();
     }
   }
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java?rev=634251&r1=634250&r2=634251&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java Thu Mar
 6 04:57:08 2008
@@ -21,6 +21,7 @@
 import java.util.List;
 import java.util.ArrayList;
 import java.io.IOException;
+import org.apache.lucene.store.Directory;
 
 /** A {@link IndexDeletionPolicy} that wraps around any other
  *  {@link IndexDeletionPolicy} and adds the ability to hold and
@@ -35,11 +36,14 @@
  *  SnapshotDeletionPolicy across multiple writers as long
  *  as they are against the same index Directory.  Any
  *  snapshot held when a writer is closed will "survive"
- *  when the next writer is opened. */
+ *  when the next writer is opened.
+ *
+ * <p><b>WARNING</b>: This API is a new and experimental and
+ * may suddenly change.</p> */
 
 public class SnapshotDeletionPolicy implements IndexDeletionPolicy {
 
-  private IndexCommitPoint lastCommit;
+  private IndexCommit lastCommit;
   private IndexDeletionPolicy primary;
   private String snapshot;
 
@@ -49,12 +53,12 @@
 
   public synchronized void onInit(List commits) throws IOException {
     primary.onInit(wrapCommits(commits));
-    lastCommit = (IndexCommitPoint) commits.get(commits.size()-1);
+    lastCommit = (IndexCommit) commits.get(commits.size()-1);
   }
 
   public synchronized void onCommit(List commits) throws IOException {
     primary.onCommit(wrapCommits(commits));
-    lastCommit = (IndexCommitPoint) commits.get(commits.size()-1);
+    lastCommit = (IndexCommit) commits.get(commits.size()-1);
   }
 
   /** Take a snapshot of the most recent commit to the
@@ -66,6 +70,7 @@
    *  you call optimize()) then in the worst case this could
    *  consume an extra 1X of your total index size, until
    *  you release the snapshot. */
+  // TODO 3.0: change this to return IndexCommit instead
   public synchronized IndexCommitPoint snapshot() {
     if (snapshot == null)
       snapshot = lastCommit.getSegmentsFileName();
@@ -82,9 +87,9 @@
       throw new IllegalStateException("snapshot was not set; please call snapshot() first");
   }
 
-  private class MyCommitPoint implements IndexCommitPoint {
-    IndexCommitPoint cp;
-    MyCommitPoint(IndexCommitPoint cp) {
+  private class MyCommitPoint extends IndexCommit {
+    IndexCommit cp;
+    MyCommitPoint(IndexCommit cp) {
       this.cp = cp;
     }
     public String getSegmentsFileName() {
@@ -93,6 +98,9 @@
     public Collection getFileNames() throws IOException {
       return cp.getFileNames();
     }
+    public Directory getDirectory() {
+      return cp.getDirectory();
+    }
     public void delete() {
       synchronized(SnapshotDeletionPolicy.this) {
         // Suppress the delete request if this commit point is
@@ -107,7 +115,7 @@
     final int count = commits.size();
     List myCommits = new ArrayList(count);
     for(int i=0;i<count;i++)
-      myCommits.add(new MyCommitPoint((IndexCommitPoint) commits.get(i)));
+      myCommits.add(new MyCommitPoint((IndexCommit) commits.get(i)));
     return myCommits;
   }
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java?rev=634251&r1=634250&r2=634251&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java Thu Mar 
6 04:57:08 2008
@@ -31,7 +31,7 @@
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.store.MockRAMDirectory;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.index.IndexCommitPoint;
+import org.apache.lucene.index.IndexCommit;
 import org.apache.lucene.index.KeepOnlyLastCommitDeletionPolicy;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.TestIndexWriter;
@@ -75,25 +75,25 @@
     doc.add(new Field("content", "aaa", Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
     for(int i=0;i<7;i++)
       writer.addDocument(doc);
-    IndexCommitPoint cp = dp.snapshot();
-    copyFiles(dir, dp, cp);
+    IndexCommit cp = (IndexCommit) dp.snapshot();
+    copyFiles(dir, cp);
     writer.close();
-    copyFiles(dir, dp, cp);
+    copyFiles(dir, cp);
     
     writer = new IndexWriter(dir, true, new StandardAnalyzer(), dp,
                              IndexWriter.MaxFieldLength.LIMITED);
-    copyFiles(dir, dp, cp);
+    copyFiles(dir, cp);
     for(int i=0;i<7;i++)
       writer.addDocument(doc);
-    copyFiles(dir, dp, cp);
+    copyFiles(dir, cp);
     writer.close();
-    copyFiles(dir, dp, cp);
+    copyFiles(dir, cp);
     dp.release();
     writer = new IndexWriter(dir, true, new StandardAnalyzer(), dp,
                              IndexWriter.MaxFieldLength.LIMITED);
     writer.close();
     try {
-      copyFiles(dir, dp, cp);
+      copyFiles(dir, cp);
       fail("did not hit expected IOException");
     } catch (IOException ioe) {
       // expected
@@ -177,7 +177,7 @@
   public void backupIndex(Directory dir, SnapshotDeletionPolicy dp) throws IOException {
     // To backup an index we first take a snapshot:
     try {
-      copyFiles(dir, dp, dp.snapshot());
+      copyFiles(dir, (IndexCommit) dp.snapshot());
     } finally {
       // Make sure to release the snapshot, otherwise these
       // files will never be deleted during this IndexWriter
@@ -186,7 +186,7 @@
     }
   }
 
-  private void copyFiles(Directory dir, SnapshotDeletionPolicy dp, IndexCommitPoint cp) throws
IOException {
+  private void copyFiles(Directory dir, IndexCommit cp) throws IOException {
 
     // While we hold the snapshot, and nomatter how long
     // we take to do the backup, the IndexWriter will

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java?rev=634251&r1=634250&r2=634251&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java Thu Mar  6
04:57:08 2008
@@ -43,9 +43,9 @@
 public class TestDeletionPolicy extends LuceneTestCase
 {
   private void verifyCommitOrder(List commits) {
-    long last = SegmentInfos.generationFromSegmentsFileName(((IndexCommitPoint) commits.get(0)).getSegmentsFileName());
+    long last = SegmentInfos.generationFromSegmentsFileName(((IndexCommit) commits.get(0)).getSegmentsFileName());
     for(int i=1;i<commits.size();i++) {
-      long now = SegmentInfos.generationFromSegmentsFileName(((IndexCommitPoint) commits.get(i)).getSegmentsFileName());
+      long now = SegmentInfos.generationFromSegmentsFileName(((IndexCommit) commits.get(i)).getSegmentsFileName());
       assertTrue("SegmentInfos commits are out-of-order", now > last);
       last = now;
     }
@@ -77,7 +77,7 @@
       // On init, delete all commit points:
       Iterator it = commits.iterator();
       while(it.hasNext()) {
-        ((IndexCommitPoint) it.next()).delete();
+        ((IndexCommit) it.next()).delete();
       }
     }
     public void onCommit(List commits) {
@@ -85,7 +85,7 @@
       int size = commits.size();
       // Delete all but last one:
       for(int i=0;i<size-1;i++) {
-        ((IndexCommitPoint) commits.get(i)).delete();
+        ((IndexCommit) commits.get(i)).delete();
       }
       numOnCommit++;
     }
@@ -119,7 +119,7 @@
       // Assert that we really are only called for each new
       // commit:
       if (isCommit) {
-        String fileName = ((IndexCommitPoint) commits.get(commits.size()-1)).getSegmentsFileName();
+        String fileName = ((IndexCommit) commits.get(commits.size()-1)).getSegmentsFileName();
         if (seen.contains(fileName)) {
           throw new RuntimeException("onCommit was called twice on the same commit point:
" + fileName);
         }
@@ -128,7 +128,7 @@
       }
       int size = commits.size();
       for(int i=0;i<size-numToKeep;i++) {
-        ((IndexCommitPoint) commits.get(i)).delete();
+        ((IndexCommit) commits.get(i)).delete();
         numDelete++;
       }
     }
@@ -157,7 +157,7 @@
     public void onCommit(List commits) throws IOException {
       verifyCommitOrder(commits);
 
-      IndexCommitPoint lastCommit = (IndexCommitPoint) commits.get(commits.size()-1);
+      IndexCommit lastCommit = (IndexCommit) commits.get(commits.size()-1);
 
       // Any commit older than expireTime should be deleted:
       double expireTime = dir.fileModified(lastCommit.getSegmentsFileName())/1000.0 - expirationTimeSeconds;
@@ -165,7 +165,7 @@
       Iterator it = commits.iterator();
 
       while(it.hasNext()) {
-        IndexCommitPoint commit = (IndexCommitPoint) it.next();
+        IndexCommit commit = (IndexCommit) it.next();
         double modTime = dir.fileModified(commit.getSegmentsFileName())/1000.0;
         if (commit != lastCommit && modTime < expireTime) {
           commit.delete();

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=634251&r1=634250&r2=634251&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 Thu Mar  6 04:57:08
2008
@@ -1276,4 +1276,37 @@
       }
     }
 
+    public void testGetIndexCommit() throws IOException {
+
+      RAMDirectory d = new MockRAMDirectory();
+
+      // set up writer
+      IndexWriter writer = new IndexWriter(d, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
+      writer.setMaxBufferedDocs(2);
+      for(int i=0;i<27;i++)
+        addDocumentWithFields(writer);
+      writer.close();
+
+      SegmentInfos sis = new SegmentInfos();
+      sis.read(d);
+      IndexReader r = IndexReader.open(d);
+      IndexCommit c = r.getIndexCommit();
+
+      assertEquals(sis.getCurrentSegmentFileName(), c.getSegmentsFileName());
+
+      assertTrue(c.equals(r.getIndexCommit()));
+
+      // Change the index
+      writer = new IndexWriter(d, new StandardAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
+      writer.setMaxBufferedDocs(2);
+      for(int i=0;i<7;i++)
+        addDocumentWithFields(writer);
+      writer.close();
+
+      IndexReader r2 = r.reopen();
+      assertFalse(c.equals(r2.getIndexCommit()));
+      r.close();
+      r2.close();
+      d.close();
+    }      
 }



Mime
View raw message