lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r748493 - in /lucene/java/trunk: ./ src/java/org/apache/lucene/index/ src/test/org/apache/lucene/index/
Date Fri, 27 Feb 2009 12:20:23 GMT
Author: mikemccand
Date: Fri Feb 27 12:20:23 2009
New Revision: 748493

URL: http://svn.apache.org/viewvc?rev=748493&view=rev
Log:
LUCENE-1546: add IndexReader.flush(String commitUserData)

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/FilterIndexReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.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=748493&r1=748492&r2=748493&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Feb 27 12:20:23 2009
@@ -51,6 +51,11 @@
    that's visited.  All core collectors now use this API.  (Mark
    Miller, Mike McCandless)
 
+8. LUCENE-1546: Add IndexReader.flush(String commitUserData), allowing
+   you to record an opaque commitUserData into the commit written by
+   IndexReader.  This matches IndexWriter's commit methods.  (Jason
+   Rutherglen via Mike McCandless)
+
 Bug fixes
 
 1. LUCENE-1415: MultiPhraseQuery has incorrect hashCode() and equals()

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=748493&r1=748492&r2=748493&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 Fri Feb 27
12:20:23 2009
@@ -327,6 +327,10 @@
       directory.close();
   }
   
+  protected void doCommit() throws IOException {
+    doCommit(null);
+  }
+
   /**
    * Commit changes resulting from delete, undeleteAll, or
    * setNorm operations
@@ -336,10 +340,10 @@
    * (transactional semantics).
    * @throws IOException if there is a low-level IO error
    */
-  protected void doCommit() throws IOException {
+  protected void doCommit(String commitUserData) throws IOException {
     if (hasChanges) {
       if (segmentInfos != null) {
-
+        segmentInfos.setUserData(commitUserData);
         // Default deleter (for backwards compatibility) is
         // KeepOnlyLastCommitDeleter:
         IndexFileDeleter deleter =  new IndexFileDeleter(directory,

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/FilterIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/FilterIndexReader.java?rev=748493&r1=748492&r2=748493&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/FilterIndexReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/FilterIndexReader.java Fri Feb 27 12:20:23
2009
@@ -209,7 +209,8 @@
   }
 
   protected void doDelete(int n) throws  CorruptIndexException, IOException { in.deleteDocument(n);
}
-  protected void doCommit() throws IOException { in.commit(); }
+  protected void doCommit() throws IOException { doCommit(null); }
+  protected void doCommit(String commitUserData) throws IOException { in.commit(commitUserData);
}
   protected void doClose() throws IOException { in.close(); }
 
 

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=748493&r1=748492&r2=748493&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 Fri Feb 27 12:20:23
2009
@@ -995,6 +995,17 @@
   }
 
   /**
+   * @param commitUserData Opaque String that's recorded
+   *  into the segments file in the index, and retrievable
+   *  by {@link IndexReader#getCommitUserData}.
+   * @throws IOException
+   */
+  public final synchronized void flush(String commitUserData) throws IOException {
+    ensureOpen();
+    commit(commitUserData);
+  }
+  
+  /**
    * Commit changes resulting from delete, undeleteAll, or
    * setNorm operations
    *
@@ -1004,15 +1015,38 @@
    * @throws IOException if there is a low-level IO error
    */
   protected final synchronized void commit() throws IOException {
-    if(hasChanges){
-      doCommit();
+    commit(null);
+  }
+  
+  /**
+   * Commit changes resulting from delete, undeleteAll, or
+   * setNorm operations
+   *
+   * If an exception is hit, then either no changes or all
+   * changes will have been committed to the index
+   * (transactional semantics).
+   * @throws IOException if there is a low-level IO error
+   */
+  protected final synchronized void commit(String commitUserData) throws IOException {
+    if (hasChanges) {
+      doCommit(commitUserData);
     }
     hasChanges = false;
   }
 
-  /** Implements commit. */
+  /** Implements commit.
+   *  @deprecated Please implement {@link #doCommit(String)
+   *  instead}. */
   protected abstract void doCommit() throws IOException;
 
+  /** Implements commit.  NOTE: subclasses should override
+   *  this.  In 3.0 this will become an abstract method. */
+  void doCommit(String commitUserData) throws IOException {
+    // Default impl discards commitUserData; all Lucene
+    // subclasses override this (do not discard it).
+    doCommit();
+  }
+
   /**
    * Closes files associated with this index.
    * Also saves any new deletions to disk.

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java?rev=748493&r1=748492&r2=748493&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java Fri Feb 27 12:20:23
2009
@@ -349,8 +349,12 @@
   }
 
   protected void doCommit() throws IOException {
+    doCommit(null);
+  }
+  
+  protected void doCommit(String commitUserData) throws IOException {
     for (int i = 0; i < subReaders.length; i++)
-      subReaders[i].commit();
+      subReaders[i].commit(commitUserData);
   }
 
   protected synchronized void doClose() throws IOException {

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java?rev=748493&r1=748492&r2=748493&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java Fri Feb 27 12:20:23
2009
@@ -437,8 +437,12 @@
   }
 
   protected void doCommit() throws IOException {
+    doCommit(null);
+  }
+
+  protected void doCommit(String commitUserData) throws IOException {
     for (int i = 0; i < readers.size(); i++)
-      ((IndexReader)readers.get(i)).commit();
+      ((IndexReader)readers.get(i)).commit(commitUserData);
   }
 
   protected synchronized void doClose() throws IOException {

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=748493&r1=748492&r2=748493&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 Fri Feb 27 12:20:23
2009
@@ -68,7 +68,57 @@
     public TestIndexReader(String name) {
         super(name);
     }
+    
+    public void testCommitUserData() throws Exception {
+      RAMDirectory d = new MockRAMDirectory();
+      
+      String cmpCommitUserData = "foo fighters";
+      
+      // 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();
+      
+      IndexReader r = IndexReader.open(d);
+      r.deleteDocument(5);
+      r.flush(cmpCommitUserData);
+      r.close();
+      
+      SegmentInfos sis = new SegmentInfos();
+      sis.read(d);
+      IndexReader r2 = IndexReader.open(d);
+      IndexCommit c = r.getIndexCommit();
+      assertEquals(c.getUserData(), cmpCommitUserData);
+
+      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 r3 = r2.reopen();
+      assertFalse(c.equals(r3.getIndexCommit()));
+      assertFalse(r2.getIndexCommit().isOptimized());
+      r3.close();
+
+      writer = new IndexWriter(d, new StandardAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
+      writer.optimize();
+      writer.close();
+
+      r3 = r2.reopen();
+      assertTrue(r3.getIndexCommit().isOptimized());
+      r2.close();
+      r3.close();
+      d.close();
+    }
+    
     public void testIsCurrent() throws Exception
     {
       RAMDirectory d = new MockRAMDirectory();



Mime
View raw message