From 2adc9df23a50e26a36569ff4384c0706deaa9f34 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Tue, 3 Jul 2007 07:31:32 +0000 Subject: [PATCH] SOLR-283: autoCommit after delete git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@552698 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../solr/update/DirectUpdateHandler2.java | 27 ++++++++++++++++++- .../apache/solr/update/AutoCommitTest.java | 11 ++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d0853332d02..9f4d62e37d6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -103,6 +103,8 @@ Bug Fixes 2. autoCommit/maxDocs was not working properly when large autoCommit/maxTime was specified (klaas) + 3. SOLR-283: autoCommit was not working after delete. (ryan) + Other Changes 1. SOLR-135: Moved common classes to org.apache.solr.common and altered the build scripts to make two jars: apache-solr-1.3.jar and diff --git a/src/java/org/apache/solr/update/DirectUpdateHandler2.java b/src/java/org/apache/solr/update/DirectUpdateHandler2.java index 8935131ac77..1b9e6e8a280 100644 --- a/src/java/org/apache/solr/update/DirectUpdateHandler2.java +++ b/src/java/org/apache/solr/update/DirectUpdateHandler2.java @@ -304,6 +304,10 @@ public class DirectUpdateHandler2 extends UpdateHandler { } finally { iwCommit.unlock(); } + + if( tracker.timeUpperBound > 0 ) { + tracker.scheduleCommitWithin( tracker.timeUpperBound ); + } } // why not return number of docs deleted? @@ -351,6 +355,10 @@ public class DirectUpdateHandler2 extends UpdateHandler { } numDocsDeleted.getAndAdd(totDeleted); madeIt=true; + + if( tracker.timeUpperBound > 0 ) { + tracker.scheduleCommitWithin( tracker.timeUpperBound ); + } } finally { if (!madeIt) { numErrors.incrementAndGet(); @@ -568,7 +576,7 @@ public class DirectUpdateHandler2 extends UpdateHandler { } log.info("closed " + this); } - + /** Helper class for tracking autoCommit state. * * Note: This is purely an implementation detail of autoCommit and will @@ -605,6 +613,23 @@ public class DirectUpdateHandler2 extends UpdateHandler { SolrCore.log.info("AutoCommit: " + this); } + /** schedeule individual commits */ + public synchronized void scheduleCommitWithin(long commitMaxTime) + { + // Check if there is a commit already scheduled for longer then this time + if( pending != null && + pending.getDelay(TimeUnit.MILLISECONDS) >= commitMaxTime ) + { + pending.cancel(false); + pending = null; + } + + // schedule a new commit + if( pending == null ) { + pending = scheduler.schedule( this, commitMaxTime, TimeUnit.MILLISECONDS ); + } + } + /** Indicate that documents have been added */ public void addedDocument() { diff --git a/src/test/org/apache/solr/update/AutoCommitTest.java b/src/test/org/apache/solr/update/AutoCommitTest.java index e0fe75bffa7..7e433f3010b 100644 --- a/src/test/org/apache/solr/update/AutoCommitTest.java +++ b/src/test/org/apache/solr/update/AutoCommitTest.java @@ -156,6 +156,13 @@ public class AutoCommitTest extends AbstractSolrTestCase { // But not this one assertQ("should find none", req("id:530") ,"//result[@numFound=0]" ); + // Delete the document + assertU( delI("529") ); + assertQ("deleted, but should still be there", req("id:529") ,"//result[@numFound=1]" ); + // Wait longer then the autocommit time + Thread.sleep( 1000 ); + assertQ("deleted and time has passed", req("id:529") ,"//result[@numFound=0]" ); + // now make the call 10 times really fast and make sure it // only commits once req.setContentStreams( toContentStreams( @@ -164,7 +171,7 @@ public class AutoCommitTest extends AbstractSolrTestCase { handler.handleRequest( req, rsp ); } assertQ("should not be there yet", req("id:500") ,"//result[@numFound=0]" ); - assertEquals( 1, tracker.autoCommitCount ); + assertEquals( 2, tracker.autoCommitCount ); // Wait longer then the autocommit time Thread.sleep( 1000 ); @@ -173,6 +180,6 @@ public class AutoCommitTest extends AbstractSolrTestCase { assertQ("now it should", req("id:500") ,"//result[@numFound=1]" ); assertQ("but not this", req("id:531") ,"//result[@numFound=0]" ); - assertEquals( 2, tracker.autoCommitCount ); + assertEquals( 3, tracker.autoCommitCount ); } }