bugfix for SOLR-274

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@550576 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mike Klaas 2007-06-25 19:10:14 +00:00
parent 4e0e8f6707
commit e740dce042
2 changed files with 21 additions and 6 deletions

View File

@ -579,6 +579,9 @@ public class DirectUpdateHandler2 extends UpdateHandler {
*/
class CommitTracker implements Runnable
{
// scheduler delay for maxDoc-triggered autocommits
public final int DOC_COMMIT_DELAY_MS = 250;
// settings, not final so we can change them in testing
int docsUpperBound;
long timeUpperBound;
@ -607,15 +610,27 @@ public class DirectUpdateHandler2 extends UpdateHandler {
public void addedDocument() {
docsSinceCommit++;
lastAddedTime = System.currentTimeMillis();
if( pending == null ) { // Don't start a new event if one is already waiting
if( timeUpperBound > 0 ) {
pending = scheduler.schedule( this, timeUpperBound, TimeUnit.MILLISECONDS );
// maxDocs-triggered autoCommit
if( docsUpperBound > 0 && (docsSinceCommit > docsUpperBound) ) {
if (pending != null &&
pending.getDelay(TimeUnit.MILLISECONDS) > DOC_COMMIT_DELAY_MS) {
// another commit is pending, but too far away (probably due to
// maxTime)
pending.cancel(false);
pending = null;
}
else if( docsUpperBound > 0 && (docsSinceCommit > docsUpperBound) ) {
if (pending == null) {
// 1/4 second seems fast enough for anyone using maxDocs
pending = scheduler.schedule( this, 250, TimeUnit.MILLISECONDS );
pending = scheduler.schedule(this, DOC_COMMIT_DELAY_MS,
TimeUnit.MILLISECONDS);
}
}
// maxTime-triggered autoCommit
if( pending == null && timeUpperBound > 0 ) {
// Don't start a new event if one is already waiting
pending = scheduler.schedule( this, timeUpperBound, TimeUnit.MILLISECONDS );
}
}
/** Inform tracker that a commit has occurred, cancel any pending commits */

View File

@ -58,7 +58,7 @@ public class AutoCommitTest extends AbstractSolrTestCase {
DirectUpdateHandler2 updater = (DirectUpdateHandler2)SolrCore.getSolrCore().getUpdateHandler();
DirectUpdateHandler2.CommitTracker tracker = updater.tracker;
tracker.timeUpperBound = -1;
tracker.timeUpperBound = 100000;
tracker.docsUpperBound = 14;
XmlUpdateRequestHandler handler = new XmlUpdateRequestHandler();