lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bernhard Messer <bmes...@apache.org>
Subject Re: svn commit: r180010 - in /lucene/java/trunk/src: java/org/apache/lucene/index/IndexReader.java java/org/apache/lucene/index/SegmentInfos.java test/org/apache/lucene/index/TestIndexReader.java
Date Mon, 06 Jun 2005 16:23:30 GMT
Daniel,

i would suggest to remove the deprecated flags from methods 
"getCurrentVersion()" and "lastModified()". Even if "lastModified()" 
returns a value which is operating system dependend, we should leave it 
up to the developer to use it or not. If we do not provide such a 
functionality, people has to develop their own solutions by reading the 
last modified date from the "segments" file itself. As long as the 
filename "segments" is internal used only, we will break all 
implementations when we try to change the name of the segments file.

Bernhard

dnaber@apache.org wrote:

>Author: dnaber
>Date: Sat Jun  4 11:16:00 2005
>New Revision: 180010
>
>URL: http://svn.apache.org/viewcvs?rev=180010&view=rev
>Log:
>add isCurrent() and initialise the segments version number with System.currentTimeMillis()
>
>Modified:
>    lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
>    lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
>    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
>
>Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
>URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java?rev=180010&r1=180009&r2=180010&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 Sat Jun  4 11:16:00
2005
>@@ -224,6 +224,7 @@
>    * @param directory where the index resides.
>    * @return version number.
>    * @throws IOException if segments file cannot be read
>+   * @deprecated use {@link #isCurrent()} instead
>    */
>   public static long getCurrentVersion(String directory) throws IOException {
>     return getCurrentVersion(new File(directory));
>@@ -236,6 +237,7 @@
>    * @param directory where the index resides.
>    * @return version number.
>    * @throws IOException if segments file cannot be read
>+   * @deprecated use {@link #isCurrent()} instead
>    */
>   public static long getCurrentVersion(File directory) throws IOException {
>     Directory dir = FSDirectory.getDirectory(directory, false);
>@@ -251,9 +253,24 @@
>    * @param directory where the index resides.
>    * @return version number.
>    * @throws IOException if segments file cannot be read.
>+   * @deprecated use {@link #isCurrent()} instead
>    */
>   public static long getCurrentVersion(Directory directory) throws IOException {
>     return SegmentInfos.readCurrentVersion(directory);
>+  }
>+
>+  /**
>+   * Check whether this IndexReader still works on a current version of the index.
>+   * If this is not the case you will need to re-open the IndexReader to
>+   * make sure you see the latest changes made to the index.
>+   * 
>+   * @throws IOException
>+   */
>+  public boolean isCurrent() throws IOException {
>+    if (SegmentInfos.readCurrentVersion(directory) != segmentInfos.getVersion()) {
>+      return false;
>+    }
>+    return true;
>   }
> 
>   /**
>
>Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
>URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java?rev=180010&r1=180009&r2=180010&view=diff
>==============================================================================
>--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java (original)
>+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java Sat Jun  4 11:16:00
2005
>@@ -29,7 +29,11 @@
>   public static final int FORMAT = -1;
>   
>   public int counter = 0;    // used to name new segments
>-  private long version = 0; //counts how often the index has been changed by adding or
deleting docs
>+  /**
>+   * counts how often the index has been changed by adding or deleting docs.
>+   * starting with the current time in milliseconds forces to create unique version numbers.
>+   */
>+  private long version = System.currentTimeMillis();
> 
>   public final SegmentInfo info(int i) {
>     return (SegmentInfo) elementAt(i);
>@@ -59,7 +63,7 @@
>       
>       if(format >= 0){    // in old format the version number may be at the end of
the file
>         if (input.getFilePointer() >= input.length())
>-          version = 0; // old file format without version number
>+          version = System.currentTimeMillis(); // old file format without version number
>         else
>           version = input.readLong(); // read version
>       }
>
>Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
>URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java?rev=180010&r1=180009&r2=180010&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 Sat Jun  4
11:16:00 2005
>@@ -48,6 +48,27 @@
>         super(name);
>     }
> 
>+    public void testIsCurrent() throws Exception
>+    {
>+      RAMDirectory d = new RAMDirectory();
>+      IndexWriter writer = new IndexWriter(d, new StandardAnalyzer(), true);
>+      addDocumentWithFields(writer);
>+      writer.close();
>+      // set up reader:
>+      IndexReader reader = IndexReader.open(d);
>+      assertTrue(reader.isCurrent());
>+      // modify index by adding another document:
>+      writer = new IndexWriter(d, new StandardAnalyzer(), false);
>+      addDocumentWithFields(writer);
>+      writer.close();
>+      assertFalse(reader.isCurrent());
>+      // re-create index:
>+      writer = new IndexWriter(d, new StandardAnalyzer(), true);
>+      addDocumentWithFields(writer);
>+      writer.close();
>+      assertFalse(reader.isCurrent());
>+      reader.close();
>+    }
> 
>     /**
>      * Tests the IndexReader.getFieldNames implementation
>
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message