Skip to content

Apache Lucene open-source search software

SOLR-310: bound pending deletes

Mike Klaasb9da3b2ace01
diff --git a/CHANGES.txt b/CHANGES.txt
index ce69d2a35fc..925af1eb6a0 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -130,7 +130,11 @@ New Features
Changes in runtime behavior
Optimizations
- 1. SOLR-276: improve JSON writer speed. (yonik)
+ 1. SOLR-276: improve JSON writer speed. (yonik)
+
+ 2. SOLR-310: bound and reduce memory usage by providing <maxBufferedDeletes> parameter,
+ which flushes deleted without forcing the user to use <commit/> for this purpose.
+ (klaas)
Bug Fixes
1. Make TextField respect sortMissingFirst and sortMissingLast fields.
diff --git a/example/solr/conf/solrconfig.xml b/example/solr/conf/solrconfig.xml
index 61a3190cc39..20d24019a83 100755
--- a/example/solr/conf/solrconfig.xml
+++ b/example/solr/conf/solrconfig.xml
@@ -82,10 +82,19 @@
org.apache.solr.(search|update|request|core|analysis)
-->
- <!-- autocommit pending docs if certain criteria are met
+ <!-- Limit the number of deletions Solr will buffer during doc updating.
+
+ Setting this lower can help bound memory use during indexing.
+ -->
+ <maxPendingDeletes>100000</maxPendingDeletes>
+
+ <!-- Perform a <commit/> automatically under certain conditions:
+
+ maxDocs - number of updates since last commit is greater than this
+ maxTime - oldest uncommited update (in ms) is this long ago
<autoCommit>
<maxDocs>10000</maxDocs>
- <maxTime>1000</maxTime>
+ <maxTime>1000</maxTime>
</autoCommit>
-->
diff --git a/src/java/org/apache/solr/update/DirectUpdateHandler2.java b/src/java/org/apache/solr/update/DirectUpdateHandler2.java
index 380086a7f68..a3f478b3da9 100644
--- a/src/java/org/apache/solr/update/DirectUpdateHandler2.java
+++ b/src/java/org/apache/solr/update/DirectUpdateHandler2.java
@@ -143,6 +143,7 @@ public class DirectUpdateHandler2 extends UpdateHandler {
// The key is the id, the value (Integer) is the number
// of docs to save (delete all except the last "n" added)
protected final Map<String,Integer> pset;
+ protected int maxPendingDeletes = SolrConfig.config.getInt("updateHandler/maxPendingDeletes", -1);
// commonly used constants for the count in the pset
protected final static Integer ZERO = 0;
@@ -274,6 +275,17 @@ public class DirectUpdateHandler2 extends UpdateHandler {
numDocsPending.incrementAndGet();
}
}
+ if (maxPendingDeletes > 0 && pset.size() > maxPendingDeletes) {
+ iwCommit.lock();
+ try {
+ // note: this may be entered multiple times since the synchro is
+ // inside the if(), but doDeletions() is a cheap no-op if it has
+ // already executed
+ doDeletions();
+ } finally {
+ iwCommit.unlock();
+ }
+ }
return rc;
}
diff --git a/src/test/org/apache/solr/update/AutoCommitTest.java b/src/test/org/apache/solr/update/AutoCommitTest.java
index a4929e1ba03..827217365d7 100644
--- a/src/test/org/apache/solr/update/AutoCommitTest.java
+++ b/src/test/org/apache/solr/update/AutoCommitTest.java
@@ -114,7 +114,7 @@ public class AutoCommitTest extends AbstractSolrTestCase {
req.setContentStreams( toContentStreams(
adoc("id", "B15", "subject", "info" ), null ) );
handler.handleRequest( req, rsp );
-
+
assertQ("should find one", req("id:B14") ,"//result[@numFound=1]" );
assertEquals( 2, tracker.autoCommitCount );
assertQ("should find none", req("id:B15") ,"//result[@numFound=0]" );
@@ -176,9 +176,40 @@ public class AutoCommitTest extends AbstractSolrTestCase {
Thread.sleep( 1000 );
req.setContentStreams( toContentStreams(
adoc("id", "531", "field_t", "what's inside?", "subject", "info"), null ) );
+ handler.handleRequest( req, rsp );
assertQ("now it should", req("id:500") ,"//result[@numFound=1]" );
assertQ("but not this", req("id:531") ,"//result[@numFound=0]" );
assertEquals( 3, tracker.autoCommitCount );
}
+
+ public void testMaxPending() throws Exception {
+
+ DirectUpdateHandler2 updater = (DirectUpdateHandler2)SolrCore.getSolrCore().getUpdateHandler();
+ updater.maxPendingDeletes = 14;
+
+ XmlUpdateRequestHandler handler = new XmlUpdateRequestHandler();
+ handler.init( null );
+
+ SolrCore core = SolrCore.getSolrCore();
+ MapSolrParams params = new MapSolrParams( new HashMap<String, String>() );
+
+ // Add a single document
+ SolrQueryResponse rsp = new SolrQueryResponse();
+ SolrQueryRequestBase req = new SolrQueryRequestBase( core, params ) {};
+ for( int i=0; i<14; i++ ) {
+ req.setContentStreams( toContentStreams(
+ adoc("id", "A"+i, "subject", "info" ), null ) );
+ handler.handleRequest( req, rsp );
+ }
+ assertEquals(updater.numDocsPending.get(), 14);
+
+ req.setContentStreams( toContentStreams(
+ adoc("id", "A14", "subject", "info" ), null ) );
+ handler.handleRequest( req, rsp );
+
+ assertEquals(updater.numDocsPending.get(), 0);
+ assertEquals(updater.commitCommands.get(), 0);
+ }
+
}