mirror of https://github.com/apache/lucene.git
SOLR-2481: Add support for commitWithin in DataImportHandler
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1212731 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c720f4da78
commit
55be28de90
|
@ -409,6 +409,9 @@ New Features
|
|||
* SOLR-2919: Added support for localized range queries when the analysis chain uses
|
||||
CollationKeyFilter or ICUCollationKeyFilter. (Michael Sokolov, rmuir)
|
||||
|
||||
* SOLR-2481: Add support for commitWithin in DataImportHandler (Sami Siren via yonik)
|
||||
|
||||
|
||||
Bug Fixes
|
||||
----------------------
|
||||
* SOLR-2912: Fixed File descriptor leak in ShowFileRequestHandler (Michael Ryan, shalin)
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.solr.handler.dataimport;
|
||||
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
import org.apache.solr.common.params.UpdateParams;
|
||||
import org.apache.solr.request.SolrQueryRequest;
|
||||
import org.apache.solr.update.AddUpdateCommand;
|
||||
import org.apache.solr.update.CommitUpdateCommand;
|
||||
|
@ -27,8 +28,6 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p> Writes documents to SOLR. </p>
|
||||
|
@ -43,12 +42,14 @@ public class SolrWriter extends DIHWriterBase implements DIHWriter {
|
|||
static final String LAST_INDEX_KEY = "last_index_time";
|
||||
|
||||
private final UpdateRequestProcessor processor;
|
||||
|
||||
private final int commitWithin;
|
||||
|
||||
SolrQueryRequest req;
|
||||
|
||||
public SolrWriter(UpdateRequestProcessor processor, SolrQueryRequest req) {
|
||||
this.processor = processor;
|
||||
this.req = req;
|
||||
commitWithin = (req != null) ? req.getParams().getInt(UpdateParams.COMMIT_WITHIN, -1): -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,6 +66,7 @@ public class SolrWriter extends DIHWriterBase implements DIHWriter {
|
|||
try {
|
||||
AddUpdateCommand command = new AddUpdateCommand(req);
|
||||
command.solrDoc = d;
|
||||
command.commitWithin = commitWithin;
|
||||
processor.processAdd(command);
|
||||
} catch (Exception e) {
|
||||
log.warn("Error creating document : " + d, e);
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.solr.client.solrj.response.QueryResponse;
|
|||
import org.apache.solr.common.SolrDocument;
|
||||
import org.apache.solr.common.SolrDocumentList;
|
||||
import org.apache.solr.common.params.ModifiableSolrParams;
|
||||
import org.apache.solr.common.params.UpdateParams;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
@ -80,6 +81,33 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa
|
|||
assertEquals("Hello C1", ((List)doc.getFieldValue("desc")).get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommitWithin() throws Exception {
|
||||
DirectXmlRequest req = new DirectXmlRequest("/dataimport", xml);
|
||||
ModifiableSolrParams params = params("command", "full-import",
|
||||
"clean", "false", UpdateParams.COMMIT, "false",
|
||||
UpdateParams.COMMIT_WITHIN, "1000");
|
||||
req.setParams(params);
|
||||
String url = "http://localhost:" + jetty.getLocalPort() + "/solr";
|
||||
CommonsHttpSolrServer solrServer = new CommonsHttpSolrServer(url);
|
||||
solrServer.request(req);
|
||||
Thread.sleep(100);
|
||||
ModifiableSolrParams queryAll = params("q", "*");
|
||||
QueryResponse qres = solrServer.query(queryAll);
|
||||
SolrDocumentList results = qres.getResults();
|
||||
assertEquals(0, results.getNumFound());
|
||||
Thread.sleep(1000);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
qres = solrServer.query(queryAll);
|
||||
results = qres.getResults();
|
||||
if (2 == results.getNumFound()) {
|
||||
return;
|
||||
}
|
||||
Thread.sleep(500);
|
||||
}
|
||||
fail("Commit should have occured but it did not");
|
||||
}
|
||||
|
||||
private class SolrInstance {
|
||||
String name;
|
||||
Integer port;
|
||||
|
|
Loading…
Reference in New Issue