You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2012/04/22 15:58:01 UTC

svn commit: r1328883 - in /lucene/dev/trunk/solr/core/src: java/org/apache/solr/update/CommitTracker.java java/org/apache/solr/update/DirectUpdateHandler2.java test/org/apache/solr/update/SoftAutoCommitTest.java

Author: yonik
Date: Sun Apr 22 13:58:00 2012
New Revision: 1328883

URL: http://svn.apache.org/viewvc?rev=1328883&view=rev
Log:
SOLR-3391: Make explicit commits cancel pending autocommits.

Modified:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/CommitTracker.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/SoftAutoCommitTest.java

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/CommitTracker.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/CommitTracker.java?rev=1328883&r1=1328882&r2=1328883&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/CommitTracker.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/CommitTracker.java Sun Apr 22 13:58:00 2012
@@ -79,6 +79,10 @@ final class CommitTracker implements Run
 
     SolrCore.log.info(name + " AutoCommit: " + this);
   }
+
+  public boolean getOpenSearcher() {
+    return openSearcher;
+  }
   
   public synchronized void close() {
     if (pending != null) {
@@ -92,6 +96,17 @@ final class CommitTracker implements Run
   public void scheduleCommitWithin(long commitMaxTime) {
     _scheduleCommitWithin(commitMaxTime);
   }
+
+  public void cancelPendingCommit() {
+    synchronized (this) {
+      if (pending != null) {
+        boolean canceled = pending.cancel(false);
+        if (canceled) {
+          pending = null;
+        }
+      }
+    }
+  }
   
   private void _scheduleCommitWithinIfNeeded(long commitWithin) {
     long ctime = (commitWithin > 0) ? commitWithin : timeUpperBound;

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java?rev=1328883&r1=1328882&r2=1328883&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java Sun Apr 22 13:58:00 2012
@@ -59,7 +59,9 @@ import org.apache.solr.schema.SchemaFiel
 import org.apache.solr.search.FunctionRangeQuery;
 import org.apache.solr.search.QParser;
 import org.apache.solr.search.QueryUtils;
+import org.apache.solr.search.SolrIndexSearcher;
 import org.apache.solr.search.function.ValueSourceRangeFilter;
+import org.apache.solr.util.RefCounted;
 
 /**
  *  TODO: add soft commitWithin support
@@ -381,6 +383,20 @@ public class DirectUpdateHandler2 extend
 
       log.info("start "+cmd);
 
+      // We must cancel pending commits *before* we actually execute the commit.
+
+      if (cmd.openSearcher) {
+        // we can cancel any pending soft commits if this commit will open a new searcher
+        softCommitTracker.cancelPendingCommit();
+      }
+      if (!cmd.softCommit && (cmd.openSearcher || !commitTracker.getOpenSearcher())) {
+        // cancel a pending hard commit if this commit is of equal or greater "strength"...
+        // If the autoCommit has openSearcher=true, then this commit must have openSearcher=true
+        // to cancel.
+         commitTracker.cancelPendingCommit();
+      }
+
+
       if (cmd.optimize) {
         writer.forceMerge(cmd.maxOptimizeSegments);
       } else if (cmd.expungeDeletes) {

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/SoftAutoCommitTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/SoftAutoCommitTest.java?rev=1328883&r1=1328882&r2=1328883&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/SoftAutoCommitTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/SoftAutoCommitTest.java Sun Apr 22 13:58:00 2012
@@ -188,6 +188,11 @@ public class SoftAutoCommitTest extends 
     // add a doc and force a commit
     assertU(adoc("id", "529", "subject", "the doc we care about in this test"));
     assertU(commit());
+
+    Long soft529;
+    Long hard529;
+
+/*** an explicit commit can (and should) clear pending auto-commits
     long postAdd529 = System.currentTimeMillis();
 
     // wait for first hard/soft commit
@@ -204,6 +209,8 @@ public class SoftAutoCommitTest extends 
     assertNotNull("hard529 wasn't fast enough", hard529);
 
     monitor.assertSaneOffers();
+ ***/
+
     monitor.clear();
 
     // Delete the document