mirror of
https://github.com/apache/lucene.git
synced 2025-03-06 08:19:23 +00:00
SOLR-1474 -- Delta-import should run even if last_index_time is not set
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@820235 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b98ef236e2
commit
e282b76156
@ -29,6 +29,10 @@ from Transformers into an EntityProcessorWrapper class. The EntityProcessor#dest
|
|||||||
parent-row at the end of row (end of data). A new method EntityProcessor#close is added which is called at the end
|
parent-row at the end of row (end of data). A new method EntityProcessor#close is added which is called at the end
|
||||||
of import.
|
of import.
|
||||||
|
|
||||||
|
In Solr 1.3, if the last_index_time was not available (first import) and a delta-import was requested, a full-import
|
||||||
|
was run instead. This is no longer the case. In Solr 1.4 delta import is run with last_index_time as the epoch
|
||||||
|
date (January 1, 1970, 00:00:00 GMT) if last_index_time is not available.
|
||||||
|
|
||||||
Detailed Change List
|
Detailed Change List
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
@ -266,6 +270,9 @@ Bug Fixes
|
|||||||
in solr_home/lib.
|
in solr_home/lib.
|
||||||
(Steve Sun via shalin)
|
(Steve Sun via shalin)
|
||||||
|
|
||||||
|
31.SOLR-1474: Delta-import should run even if last_index_time is not set.
|
||||||
|
(shalin)
|
||||||
|
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
----------------------
|
----------------------
|
||||||
|
@ -22,6 +22,7 @@ import org.apache.solr.util.AbstractSolrTestCase;
|
|||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -46,6 +47,14 @@ public abstract class AbstractDataImportHandlerTest extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
|
// remove dataimport.properties
|
||||||
|
File f = new File("solr/conf/dataimport.properties");
|
||||||
|
log.info("Looking for dataimport.properties at: " + f.getAbsolutePath());
|
||||||
|
if (f.exists()) {
|
||||||
|
log.info("Deleting dataimport.properties");
|
||||||
|
if (!f.delete())
|
||||||
|
log.warn("Could not delete dataimport.properties");
|
||||||
|
}
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,14 +252,6 @@ public class DataImporter {
|
|||||||
this.indexStartTime = indextStartTime;
|
this.indexStartTime = indextStartTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
Date getLastIndexTime() {
|
|
||||||
return lastIndexTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setLastIndexTime(Date lastIndexTime) {
|
|
||||||
this.lastIndexTime = lastIndexTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
void store(Object key, Object value) {
|
void store(Object key, Object value) {
|
||||||
store.put(key, value);
|
store.put(key, value);
|
||||||
}
|
}
|
||||||
@ -387,8 +379,6 @@ public class DataImporter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Date lastModified = sw.loadIndexStartTime();
|
|
||||||
setLastIndexTime(lastModified);
|
|
||||||
if (FULL_IMPORT_CMD.equals(command) || IMPORT_CMD.equals(command)) {
|
if (FULL_IMPORT_CMD.equals(command) || IMPORT_CMD.equals(command)) {
|
||||||
doFullImport(sw, reqParams);
|
doFullImport(sw, reqParams);
|
||||||
} else if (command.equals(DELTA_IMPORT_CMD)) {
|
} else if (command.equals(DELTA_IMPORT_CMD)) {
|
||||||
|
@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
import java.text.ParseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p> DocBuilder is responsible for creating Solr documents out of the given configuration. It also maintains
|
* <p> DocBuilder is responsible for creating Solr documents out of the given configuration. It also maintains
|
||||||
@ -41,6 +42,8 @@ public class DocBuilder {
|
|||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(DocBuilder.class);
|
private static final Logger LOG = LoggerFactory.getLogger(DocBuilder.class);
|
||||||
|
|
||||||
|
private static final Date EPOCH = new Date(0);
|
||||||
|
|
||||||
DataImporter dataImporter;
|
DataImporter dataImporter;
|
||||||
|
|
||||||
private DataConfig.Document document;
|
private DataConfig.Document document;
|
||||||
@ -76,24 +79,36 @@ public class DocBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public VariableResolverImpl getVariableResolver() {
|
public VariableResolverImpl getVariableResolver() {
|
||||||
VariableResolverImpl resolver = new VariableResolverImpl();
|
try {
|
||||||
Map<String, Object> indexerNamespace = new HashMap<String, Object>();
|
VariableResolverImpl resolver = new VariableResolverImpl();
|
||||||
if (dataImporter.getLastIndexTime() != null)
|
Map<String, Object> indexerNamespace = new HashMap<String, Object>();
|
||||||
indexerNamespace.put(LAST_INDEX_TIME,
|
if (persistedProperties.getProperty(LAST_INDEX_TIME) != null) {
|
||||||
DataImporter.DATE_TIME_FORMAT.get().format(dataImporter.getLastIndexTime()));
|
indexerNamespace.put(LAST_INDEX_TIME,
|
||||||
indexerNamespace.put(INDEX_START_TIME, dataImporter.getIndexStartTime());
|
DataImporter.DATE_TIME_FORMAT.get().parse(persistedProperties.getProperty(LAST_INDEX_TIME)));
|
||||||
indexerNamespace.put("request", requestParameters.requestParams);
|
} else {
|
||||||
indexerNamespace.put("functions", functionsNamespace);
|
// set epoch
|
||||||
for (DataConfig.Entity entity : dataImporter.getConfig().document.entities) {
|
indexerNamespace.put(LAST_INDEX_TIME, EPOCH);
|
||||||
String key = entity.name + "." + SolrWriter.LAST_INDEX_KEY;
|
|
||||||
String lastIndex = persistedProperties.getProperty(key);
|
|
||||||
if (lastIndex != null) {
|
|
||||||
indexerNamespace.put(key, lastIndex);
|
|
||||||
}
|
}
|
||||||
|
indexerNamespace.put(INDEX_START_TIME, dataImporter.getIndexStartTime());
|
||||||
|
indexerNamespace.put("request", requestParameters.requestParams);
|
||||||
|
indexerNamespace.put("functions", functionsNamespace);
|
||||||
|
for (DataConfig.Entity entity : dataImporter.getConfig().document.entities) {
|
||||||
|
String key = entity.name + "." + SolrWriter.LAST_INDEX_KEY;
|
||||||
|
String lastIndex = persistedProperties.getProperty(key);
|
||||||
|
if (lastIndex != null) {
|
||||||
|
indexerNamespace.put(key, lastIndex);
|
||||||
|
} else {
|
||||||
|
indexerNamespace.put(key, EPOCH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolver.addNamespace(DataConfig.IMPORTER_NS_SHORT, indexerNamespace);
|
||||||
|
resolver.addNamespace(DataConfig.IMPORTER_NS, indexerNamespace);
|
||||||
|
return resolver;
|
||||||
|
} catch (ParseException e) {
|
||||||
|
DataImportHandlerException.wrapAndThrow(DataImportHandlerException.SEVERE, e);
|
||||||
|
// unreachable statement
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
resolver.addNamespace(DataConfig.IMPORTER_NS_SHORT, indexerNamespace);
|
|
||||||
resolver.addNamespace(DataConfig.IMPORTER_NS, indexerNamespace);
|
|
||||||
return resolver;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void invokeEventListener(String className) {
|
private void invokeEventListener(String className) {
|
||||||
@ -153,8 +168,7 @@ public class DocBuilder {
|
|||||||
DataImporter.DATE_TIME_FORMAT.get().format(new Date()));
|
DataImporter.DATE_TIME_FORMAT.get().format(new Date()));
|
||||||
root = e;
|
root = e;
|
||||||
String delQuery = e.allAttributes.get("preImportDeleteQuery");
|
String delQuery = e.allAttributes.get("preImportDeleteQuery");
|
||||||
if (dataImporter.getStatus() == DataImporter.Status.RUNNING_DELTA_DUMP
|
if (dataImporter.getStatus() == DataImporter.Status.RUNNING_DELTA_DUMP) {
|
||||||
&& dataImporter.getLastIndexTime() != null) {
|
|
||||||
cleanByQuery(delQuery, fullCleanDone);
|
cleanByQuery(delQuery, fullCleanDone);
|
||||||
doDelta();
|
doDelta();
|
||||||
delQuery = e.allAttributes.get("postImportDeleteQuery");
|
delQuery = e.allAttributes.get("postImportDeleteQuery");
|
||||||
|
@ -219,22 +219,6 @@ public class SolrWriter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date loadIndexStartTime() {
|
|
||||||
Properties props;
|
|
||||||
props = readIndexerProperties();
|
|
||||||
String result = props.getProperty(SolrWriter.LAST_INDEX_KEY);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (result != null)
|
|
||||||
return DataImporter.DATE_TIME_FORMAT.get().parse(result);
|
|
||||||
} catch (ParseException e) {
|
|
||||||
throw new DataImportHandlerException(DataImportHandlerException.WARN,
|
|
||||||
"Unable to read last indexed time from: "
|
|
||||||
+ persistFilename, e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DebugLogger getDebugLogger() {
|
public DebugLogger getDebugLogger() {
|
||||||
if (debugLogger == null) {
|
if (debugLogger == null) {
|
||||||
debugLogger = new DebugLogger(this);
|
debugLogger = new DebugLogger(this);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user