Apache Lucene open-source search software
SOLR-3391: Make explicit commits cancel pending autocommits.
Yonik Seeleyd5d8fef91e5f
diff --git a/solr/core/src/java/org/apache/solr/update/CommitTracker.java b/solr/core/src/java/org/apache/solr/update/CommitTracker.javaindex 528b502f960..17521b8bd57 100644--- a/solr/core/src/java/org/apache/solr/update/CommitTracker.java+++ b/solr/core/src/java/org/apache/solr/update/CommitTracker.java@@ -79,6 +79,10 @@ final class CommitTracker implements Runnable {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 Runnable {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;diff --git a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.javaindex ab6e50e4fb3..de6ced6dfb2 100644--- a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java+++ b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java@@ -59,7 +59,9 @@ import org.apache.solr.schema.SchemaField;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 extends UpdateHandler implements SolrCoreStatelog.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) {diff --git a/solr/core/src/test/org/apache/solr/update/SoftAutoCommitTest.java b/solr/core/src/test/org/apache/solr/update/SoftAutoCommitTest.javaindex d0b413bf10a..8c2b3591a76 100644--- a/solr/core/src/test/org/apache/solr/update/SoftAutoCommitTest.java+++ b/solr/core/src/test/org/apache/solr/update/SoftAutoCommitTest.java@@ -188,6 +188,11 @@ public class SoftAutoCommitTest extends AbstractSolrTestCase {// add a doc and force a commitassertU(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-commitslong postAdd529 = System.currentTimeMillis();// wait for first hard/soft commit@@ -204,6 +209,8 @@ public class SoftAutoCommitTest extends AbstractSolrTestCase {assertNotNull("hard529 wasn't fast enough", hard529);monitor.assertSaneOffers();+ ***/+monitor.clear();// Delete the document