lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject svn commit: r936605 - in /lucene/dev/trunk/lucene: CHANGES.txt src/java/org/apache/lucene/index/IndexFileDeleter.java src/java/org/apache/lucene/index/IndexWriter.java src/test/org/apache/lucene/index/TestIndexWriter.java
Date Thu, 22 Apr 2010 03:45:01 GMT
Author: shaie
Date: Thu Apr 22 03:45:01 2010
New Revision: 936605

URL: http://svn.apache.org/viewvc?rev=936605&view=rev
Log:
LUCENE-2402: Add an explicit method to invoke IndexDeletionPolicy

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=936605&r1=936604&r2=936605&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Thu Apr 22 03:45:01 2010
@@ -219,6 +219,12 @@ API Changes
   expressions).
   (Uwe Schindler, Robert Muir)
 
+* LUCENE-2402: IndexWriter.deleteUnusedFiles now deletes unreferenced commit
+  points too. If you use an IndexDeletionPolicy which holds onto index commits
+  (such as SnapshotDeletionPolicy), you can call this method to remove those
+  commit points when they are not needed anymore (instead of waiting for the 
+  next commit). (Shai Erera)
+  
 Bug fixes
 
 * LUCENE-2119: Don't throw NegativeArraySizeException if you pass

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java?rev=936605&r1=936604&r2=936605&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java Thu Apr
22 03:45:01 2010
@@ -353,6 +353,26 @@ final class IndexFileDeleter {
     deletePendingFiles();
   }
 
+  /**
+   * Revisits the {@link IndexDeletionPolicy} by calling its
+   * {@link IndexDeletionPolicy#onCommit(List)} again with the known commits.
+   * This is useful in cases where a deletion policy which holds onto index
+   * commits is used. The application may know that some commits are not held by
+   * the deletion policy anymore and call
+   * {@link IndexWriter#deleteUnusedFiles()}, which will attempt to delete the
+   * unused commits again.
+   */
+  void revisitPolicy() throws IOException {
+    if (infoStream != null) {
+      message("now revisitPolicy");
+    }
+
+    if (commits.size() > 0) {
+      policy.onCommit(commits);
+      deleteCommits();
+    }
+  }
+  
   public void deletePendingFiles() throws IOException {
     if (deletable != null) {
       List<String> oldDeletable = deletable;

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java?rev=936605&r1=936604&r2=936605&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java Thu Apr 22 03:45:01
2010
@@ -4961,8 +4961,18 @@ public class IndexWriter implements Clos
    *  IndexWriter, you'll see the unused files linger.  If
    *  that's a problem, call this method to delete them
    *  (once you've closed the open readers that were
-   *  preventing their deletion). */
+   *  preventing their deletion). 
+   *  
+   *  <p> In addition, you can call this method to delete 
+   *  unreferenced index commits. This might be useful if you 
+   *  are using an {@link IndexDeletionPolicy} which holds
+   *  onto index commits until some criteria are met, but those
+   *  commits are no longer needed. Otherwise, those commits will
+   *  be deleted the next time commit() is called.
+   */
   public synchronized void deleteUnusedFiles() throws IOException {
     deleter.deletePendingFiles();
+    deleter.revisitPolicy();
   }
+  
 }

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=936605&r1=936604&r2=936605&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 Thu Apr
22 03:45:01 2010
@@ -4915,6 +4915,40 @@ public class TestIndexWriter extends Luc
     }
   }
 
+  public void testDeleteUnsedFiles2() throws Exception {
+    // Validates that iw.deleteUnusedFiles() also deletes unused index commits
+    // in case a deletion policy which holds onto commits is used.
+    Directory dir = new MockRAMDirectory();
+    SnapshotDeletionPolicy sdp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
+    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+        TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
+        .setIndexDeletionPolicy(sdp));
+    
+    // First commit
+    Document doc = new Document();
+    doc.add(new Field("c", "val", Store.YES, Index.ANALYZED, TermVector.WITH_POSITIONS_OFFSETS));
+    writer.addDocument(doc);
+    writer.commit();
+    assertEquals(1, IndexReader.listCommits(dir).size());
+
+    // Keep that commit
+    sdp.snapshot();
+    
+    // Second commit - now KeepOnlyLastCommit cannot delete the prev commit.
+    doc = new Document();
+    doc.add(new Field("c", "val", Store.YES, Index.ANALYZED, TermVector.WITH_POSITIONS_OFFSETS));
+    writer.addDocument(doc);
+    writer.commit();
+    assertEquals(2, IndexReader.listCommits(dir).size());
+
+    // Should delete the unreferenced commit
+    sdp.release();
+    writer.deleteUnusedFiles();
+    assertEquals(1, IndexReader.listCommits(dir).size());
+    
+    writer.close();
+  }
+  
   private static class FlushCountingIndexWriter extends IndexWriter {
     int flushCount;
     public FlushCountingIndexWriter(Directory dir, IndexWriterConfig iwc) throws IOException
{



Mime
View raw message