SOLR-974 -- DataImportHandler skips commit if no data has been updated

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@738020 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2009-01-27 07:49:22 +00:00
parent 0d6494cb75
commit 100d85d8a6
3 changed files with 48 additions and 8 deletions

View File

@ -61,6 +61,9 @@ Optimizations
1. SOLR-846: Reduce memory consumption during delta import by removing keys when used
(Ricky Leung, Noble Paul via shalin)
2. SOLR-974: DataImportHandler skips commit if no data has been updated.
(Wojtek Piaseczny, shalin)
Bug Fixes
----------------------
1. SOLR-800: Deep copy collections to avoid ConcurrentModificationException in XPathEntityprocessor while streaming

View File

@ -175,8 +175,15 @@ public class DocBuilder {
}
}
} else {
// Finished operation normally, commit now
commit();
// Do not commit unnecessarily if this is a delta-import and no documents were created or deleted
if (!requestParameters.clean) {
if (importStatistics.docCount.get() > 0 || importStatistics.deletedDocCount.get() > 0) {
commit();
}
} else {
// Finished operation normally, commit now
commit();
}
if (document.onImportEnd != null) {
invokeEventListener(document.onImportEnd);
}

View File

@ -21,10 +21,7 @@ import static org.apache.solr.handler.dataimport.AbstractDataImportHandlerTest.c
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* <p>
@ -70,6 +67,31 @@ public class TestDocBuilder {
}
}
@Test
public void testDeltaImportNoRows_MustNotCommit() {
try {
DataImporter di = new DataImporter();
di.loadDataConfig(dc_deltaConfig);
DataConfig cfg = di.getConfig();
DataConfig.Entity ent = cfg.document.entities.get(0);
MockDataSource.setIterator("select * from x", new ArrayList().iterator());
MockDataSource.setIterator("select id from x", new ArrayList().iterator());
ent.dataSrc = new MockDataSource();
ent.isDocRoot = true;
DataImporter.RequestParams rp = new DataImporter.RequestParams(createMap("command", "delta-import"));
SolrWriterImpl swi = new SolrWriterImpl();
di.runCmd(rp, swi);
Assert.assertEquals(Boolean.FALSE, swi.deleteAllCalled);
Assert.assertEquals(Boolean.FALSE, swi.commitCalled);
Assert.assertEquals(0, swi.docs.size());
Assert.assertEquals(1, di.getDocBuilder().importStatistics.queryCount.get());
Assert.assertEquals(0, di.getDocBuilder().importStatistics.docCount.get());
Assert.assertEquals(0, di.getDocBuilder().importStatistics.rowsCount.get());
} finally {
MockDataSource.clearCache();
}
}
@Test
public void singleEntityOneRow() {
try {
@ -153,9 +175,9 @@ public class TestDocBuilder {
static class SolrWriterImpl extends SolrWriter {
List<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
Boolean deleteAllCalled;
Boolean deleteAllCalled = Boolean.FALSE;
Boolean commitCalled;
Boolean commitCalled = Boolean.FALSE;
public SolrWriterImpl() {
super(null, ".");
@ -186,4 +208,12 @@ public class TestDocBuilder {
+ " <field column=\"desc\" name=\"desc_s\" />" + " </entity>\n"
+ " </document>\n" + "</dataConfig>";
public static final String dc_deltaConfig = "<dataConfig>\n"
+ " <document name=\"X\" >\n"
+ " <entity name=\"x\" query=\"select * from x\" deltaQuery=\"select id from x\">\n"
+ " <field column=\"id\"/>\n"
+ " <field column=\"desc\"/>\n"
+ " <field column=\"desc\" name=\"desc_s\" />" + " </entity>\n"
+ " </document>\n" + "</dataConfig>";
}