SOLR-988 -- Add a new scope for session data stored in Context to store objects across imports

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@738015 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2009-01-27 07:21:52 +00:00
parent e36809b163
commit 0d6494cb75
5 changed files with 42 additions and 14 deletions

View File

@ -53,6 +53,9 @@ New Features
11.SOLR-801: Add support for configurable pre-import and post-import delete query per root-entity.
(Noble Paul via shalin)
12.SOLR-988: Add a new scope for session data stored in Context to store objects across imports.
(Noble Paul via shalin)
Optimizations
----------------------
1. SOLR-846: Reduce memory consumption during delta import by removing keys when used

View File

@ -41,8 +41,26 @@ import java.util.Map;
public abstract class Context {
public static final int FULL_DUMP = 1, DELTA_DUMP = 2, FIND_DELTA = 3;
public static final String SCOPE_ENTITY = "entity", SCOPE_GLOBAL = "global",
SCOPE_DOC = "document";
/**
* An object stored in entity scope is valid only for the current entity for the current document only.
*/
public static final String SCOPE_ENTITY = "entity";
/**
* An object stored in global scope is available for the current import only but across entities and documents.
*/
public static final String SCOPE_GLOBAL = "global";
/**
* An object stored in document scope is available for the current document only but across entities.
*/
public static final String SCOPE_DOC = "document";
/**
* An object stored in 'solrcore' scope is available across imports, entities and documents throughout the life of
* a solr core. A solr core unload or reload will destroy this data.
*/
public static final String SCOPE_SOLR_CORE = "solrcore";
/**
* Get the value of any attribute put into this entity

View File

@ -126,6 +126,8 @@ public class ContextImpl extends Context {
Map<String, Object> docsession = getDocSession();
if (docsession != null)
docsession.put(name, val);
} else if (SCOPE_SOLR_CORE.equals(scope)){
if(dataImporter != null) dataImporter.getCoreScopeSession().put(name, val);
}
}
@ -142,6 +144,8 @@ public class ContextImpl extends Context {
Map<String, Object> docsession = getDocSession();
if (docsession != null)
return docsession.get(name);
} else if (SCOPE_SOLR_CORE.equals(scope)){
return dataImporter == null ? null : dataImporter.getCoreScopeSession().get(name);
}
return null;
}

View File

@ -32,7 +32,6 @@ import org.apache.solr.handler.RequestHandlerUtils;
import org.apache.solr.request.RawResponseWriter;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryResponse;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.update.processor.UpdateRequestProcessor;
import org.apache.solr.update.processor.UpdateRequestProcessorChain;
import org.apache.solr.util.plugin.SolrCoreAware;
@ -67,15 +66,14 @@ public class DataImportHandler extends RequestHandlerBase implements
private DataImporter importer;
private Map<String, String> variables = new HashMap<String, String>();
private Map<String, Properties> dataSources = new HashMap<String, Properties>();
private List<SolrInputDocument> debugDocuments;
private boolean debugEnabled = true;
private Map<String , Object> coreScopeSession = new HashMap<String, Object>();
@Override
@SuppressWarnings("unchecked")
public void init(NamedList args) {
@ -96,7 +94,7 @@ public class DataImportHandler extends RequestHandlerBase implements
importer = new DataImporter(SolrWriter.getResourceAsString(core
.getResourceLoader().openResource(configLoc)), core,
dataSources);
dataSources, coreScopeSession);
}
}
} catch (Throwable e) {
@ -142,7 +140,7 @@ public class DataImportHandler extends RequestHandlerBase implements
try {
processConfiguration((NamedList) initArgs.get("defaults"));
importer = new DataImporter(requestParams.dataConfig, req.getCore()
, dataSources);
, dataSources, coreScopeSession);
} catch (RuntimeException e) {
rsp.add("exception", DebugLogger.getStacktraceString(e));
importer = null;
@ -229,7 +227,6 @@ public class DataImportHandler extends RequestHandlerBase implements
LOG.info("Processing configuration from solrconfig.xml: " + defaults);
dataSources = new HashMap<String, Properties>();
variables = new HashMap<String, String>();
int position = 0;
@ -245,9 +242,6 @@ public class DataImportHandler extends RequestHandlerBase implements
props.put(dsConfig.getName(i), dsConfig.getVal(i));
LOG.info("Adding properties to datasource: " + props);
dataSources.put((String) dsConfig.get("name"), props);
} else if (!name.equals("config")) {
String value = (String) defaults.getVal(position);
variables.put(name, value);
}
position++;
}

View File

@ -75,20 +75,25 @@ public class DataImporter {
private ReentrantLock importLock = new ReentrantLock();
private final Map<String , Object> coreScopeSession;
/**
* Only for testing purposes
*/
DataImporter() {
coreScopeSession = new HashMap<String, Object>();
}
DataImporter(String dataConfig, SolrCore core,
Map<String, Properties> ds) {
DataImporter(String dataConfig, SolrCore core, Map<String, Properties> ds, Map<String, Object> session) {
if (dataConfig == null)
throw new DataImportHandlerException(DataImportHandlerException.SEVERE,
"Configuration not found");
this.core = core;
this.schema = core.getSchema();
dataSourceProps = ds;
if (session == null)
session = new HashMap<String, Object>();
coreScopeSession = session;
loadDataConfig(dataConfig);
for (Map.Entry<String, SchemaField> entry : schema.getFields().entrySet()) {
@ -516,6 +521,10 @@ public class DataImporter {
return schema;
}
Map<String, Object> getCoreScopeSession() {
return coreScopeSession;
}
SolrCore getCore() {
return core;
}