Index: src/test/org/apache/solr/update/AutoCommitTest.java =================================================================== --- src/test/org/apache/solr/update/AutoCommitTest.java (revision 571042) +++ src/test/org/apache/solr/update/AutoCommitTest.java (working copy) @@ -114,7 +114,7 @@ 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 @@ 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() ); + + // 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); + } + } Index: src/java/org/apache/solr/update/DirectUpdateHandler2.java =================================================================== --- src/java/org/apache/solr/update/DirectUpdateHandler2.java (revision 571042) +++ src/java/org/apache/solr/update/DirectUpdateHandler2.java (working copy) @@ -143,6 +143,7 @@ // 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 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 @@ 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; } Index: example/solr/conf/solrconfig.xml =================================================================== --- example/solr/conf/solrconfig.xml (revision 571042) +++ example/solr/conf/solrconfig.xml (working copy) @@ -82,10 +82,19 @@ org.apache.solr.(search|update|request|core|analysis) --> - + 100000 + +