lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r915399 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/IndexWriter.java src/test/org/apache/lucene/index/TestIndexWriter.java
Date Tue, 23 Feb 2010 15:56:37 GMT
Author: mikemccand
Date: Tue Feb 23 15:56:37 2010
New Revision: 915399

URL: http://svn.apache.org/viewvc?rev=915399&view=rev
Log:
LUCENE-2281: add doBeforeFlush; make both do{Before,After}Flush protected

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

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=915399&r1=915398&r2=915399&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Feb 23 15:56:37 2010
@@ -64,6 +64,10 @@
   files are no longer open by IndexReaders. (luocanrao via Mike
   McCandless)
 
+* LUCENE-2281: added doBeforeFlush to IndexWriter to allow extensions to perform
+  operations before flush starts. Also exposed doAfterFlush as protected instead
+  of package-private. (Shai Erera via Mike McCandless)
+
 Bug fixes
 
 * LUCENE-2119: Don't throw NegativeArraySizeException if you pass

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=915399&r1=915398&r2=915399&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 Tue Feb 23 15:56:37
2010
@@ -3312,12 +3312,18 @@
     }
   }
 
-  // This is called after pending added and deleted
-  // documents have been flushed to the Directory but before
-  // the change is committed (new segments_N file written).
-  void doAfterFlush()
-    throws IOException {
-  }
+  /**
+   * A hook for extending classes to execute operations after pending added and
+   * deleted documents have been flushed to the Directory but before the change
+   * is committed (new segments_N file written).
+   */
+  protected void doAfterFlush() throws IOException {}
+
+  /**
+   * A hook for extending classes to execute operations before pending added and
+   * deleted documents are flushed to the Directory.
+   */
+  protected void doBeforeFlush() throws IOException {}
 
   /** Expert: prepare for commit.
    *
@@ -3525,6 +3531,8 @@
 
     assert testPoint("startDoFlush");
 
+    doBeforeFlush();
+    
     flushCount++;
 
     // If we are flushing because too many deletes

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=915399&r1=915398&r2=915399&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Tue Feb 23 15:56:37
2010
@@ -3174,16 +3174,22 @@
       super(dir, a, create, mfl);
     }
 
-    boolean wasCalled;
+    boolean afterWasCalled;
+    boolean beforeWasCalled;
 
     @Override
     public void doAfterFlush() {
-      wasCalled = true;
+      afterWasCalled = true;
+    }
+    
+    @Override
+    protected void doBeforeFlush() throws IOException {
+      beforeWasCalled = true;
     }
   }
 
   // LUCENE-1222
-  public void testDoAfterFlush() throws IOException {
+  public void testDoBeforeAfterFlush() throws IOException {
     MockRAMDirectory dir = new MockRAMDirectory();
     MockIndexWriter3 w = new MockIndexWriter3(dir, new WhitespaceAnalyzer(TEST_VERSION_CURRENT),
true, IndexWriter.MaxFieldLength.LIMITED);
     Document doc = new Document();
@@ -3191,11 +3197,14 @@
                       Field.Index.ANALYZED));
     w.addDocument(doc);
     w.commit();
-    assertTrue(w.wasCalled);
-    w.wasCalled = true;
+    assertTrue(w.beforeWasCalled);
+    assertTrue(w.afterWasCalled);
+    w.beforeWasCalled = false;
+    w.afterWasCalled = false;
     w.deleteDocuments(new Term("field", "field"));
     w.commit();
-    assertTrue(w.wasCalled);
+    assertTrue(w.beforeWasCalled);
+    assertTrue(w.afterWasCalled);
     w.close();
 
     IndexReader ir = IndexReader.open(dir, true);



Mime
View raw message