LUCENE-2281: add doBeforeFlush; make both do{Before,After}Flush protected

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@915399 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2010-02-23 15:56:37 +00:00
parent 5a320d2c4b
commit 4eef6adaaf
3 changed files with 33 additions and 12 deletions

View File

@ -64,6 +64,10 @@ API Changes
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

View File

@ -3312,12 +3312,18 @@ public class IndexWriter implements Closeable {
}
}
// 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 @@ public class IndexWriter implements Closeable {
assert testPoint("startDoFlush");
doBeforeFlush();
flushCount++;
// If we are flushing because too many deletes

View File

@ -3174,16 +3174,22 @@ public class TestIndexWriter extends LuceneTestCase {
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 @@ public class TestIndexWriter extends LuceneTestCase {
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);