mirror of https://github.com/apache/lucene.git
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:
parent
e36809b163
commit
0d6494cb75
|
@ -53,6 +53,9 @@ New Features
|
||||||
11.SOLR-801: Add support for configurable pre-import and post-import delete query per root-entity.
|
11.SOLR-801: Add support for configurable pre-import and post-import delete query per root-entity.
|
||||||
(Noble Paul via shalin)
|
(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
|
Optimizations
|
||||||
----------------------
|
----------------------
|
||||||
1. SOLR-846: Reduce memory consumption during delta import by removing keys when used
|
1. SOLR-846: Reduce memory consumption during delta import by removing keys when used
|
||||||
|
|
|
@ -41,8 +41,26 @@ import java.util.Map;
|
||||||
public abstract class Context {
|
public abstract class Context {
|
||||||
public static final int FULL_DUMP = 1, DELTA_DUMP = 2, FIND_DELTA = 3;
|
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
|
* Get the value of any attribute put into this entity
|
||||||
|
|
|
@ -126,6 +126,8 @@ public class ContextImpl extends Context {
|
||||||
Map<String, Object> docsession = getDocSession();
|
Map<String, Object> docsession = getDocSession();
|
||||||
if (docsession != null)
|
if (docsession != null)
|
||||||
docsession.put(name, val);
|
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();
|
Map<String, Object> docsession = getDocSession();
|
||||||
if (docsession != null)
|
if (docsession != null)
|
||||||
return docsession.get(name);
|
return docsession.get(name);
|
||||||
|
} else if (SCOPE_SOLR_CORE.equals(scope)){
|
||||||
|
return dataImporter == null ? null : dataImporter.getCoreScopeSession().get(name);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.apache.solr.handler.RequestHandlerUtils;
|
||||||
import org.apache.solr.request.RawResponseWriter;
|
import org.apache.solr.request.RawResponseWriter;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.request.SolrQueryResponse;
|
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.UpdateRequestProcessor;
|
||||||
import org.apache.solr.update.processor.UpdateRequestProcessorChain;
|
import org.apache.solr.update.processor.UpdateRequestProcessorChain;
|
||||||
import org.apache.solr.util.plugin.SolrCoreAware;
|
import org.apache.solr.util.plugin.SolrCoreAware;
|
||||||
|
@ -67,15 +66,14 @@ public class DataImportHandler extends RequestHandlerBase implements
|
||||||
|
|
||||||
private DataImporter importer;
|
private DataImporter importer;
|
||||||
|
|
||||||
private Map<String, String> variables = new HashMap<String, String>();
|
|
||||||
|
|
||||||
|
|
||||||
private Map<String, Properties> dataSources = new HashMap<String, Properties>();
|
private Map<String, Properties> dataSources = new HashMap<String, Properties>();
|
||||||
|
|
||||||
private List<SolrInputDocument> debugDocuments;
|
private List<SolrInputDocument> debugDocuments;
|
||||||
|
|
||||||
private boolean debugEnabled = true;
|
private boolean debugEnabled = true;
|
||||||
|
|
||||||
|
private Map<String , Object> coreScopeSession = new HashMap<String, Object>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void init(NamedList args) {
|
public void init(NamedList args) {
|
||||||
|
@ -96,7 +94,7 @@ public class DataImportHandler extends RequestHandlerBase implements
|
||||||
|
|
||||||
importer = new DataImporter(SolrWriter.getResourceAsString(core
|
importer = new DataImporter(SolrWriter.getResourceAsString(core
|
||||||
.getResourceLoader().openResource(configLoc)), core,
|
.getResourceLoader().openResource(configLoc)), core,
|
||||||
dataSources);
|
dataSources, coreScopeSession);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -142,7 +140,7 @@ public class DataImportHandler extends RequestHandlerBase implements
|
||||||
try {
|
try {
|
||||||
processConfiguration((NamedList) initArgs.get("defaults"));
|
processConfiguration((NamedList) initArgs.get("defaults"));
|
||||||
importer = new DataImporter(requestParams.dataConfig, req.getCore()
|
importer = new DataImporter(requestParams.dataConfig, req.getCore()
|
||||||
, dataSources);
|
, dataSources, coreScopeSession);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
rsp.add("exception", DebugLogger.getStacktraceString(e));
|
rsp.add("exception", DebugLogger.getStacktraceString(e));
|
||||||
importer = null;
|
importer = null;
|
||||||
|
@ -229,7 +227,6 @@ public class DataImportHandler extends RequestHandlerBase implements
|
||||||
LOG.info("Processing configuration from solrconfig.xml: " + defaults);
|
LOG.info("Processing configuration from solrconfig.xml: " + defaults);
|
||||||
|
|
||||||
dataSources = new HashMap<String, Properties>();
|
dataSources = new HashMap<String, Properties>();
|
||||||
variables = new HashMap<String, String>();
|
|
||||||
|
|
||||||
int position = 0;
|
int position = 0;
|
||||||
|
|
||||||
|
@ -245,9 +242,6 @@ public class DataImportHandler extends RequestHandlerBase implements
|
||||||
props.put(dsConfig.getName(i), dsConfig.getVal(i));
|
props.put(dsConfig.getName(i), dsConfig.getVal(i));
|
||||||
LOG.info("Adding properties to datasource: " + props);
|
LOG.info("Adding properties to datasource: " + props);
|
||||||
dataSources.put((String) dsConfig.get("name"), props);
|
dataSources.put((String) dsConfig.get("name"), props);
|
||||||
} else if (!name.equals("config")) {
|
|
||||||
String value = (String) defaults.getVal(position);
|
|
||||||
variables.put(name, value);
|
|
||||||
}
|
}
|
||||||
position++;
|
position++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,20 +75,25 @@ public class DataImporter {
|
||||||
|
|
||||||
private ReentrantLock importLock = new ReentrantLock();
|
private ReentrantLock importLock = new ReentrantLock();
|
||||||
|
|
||||||
|
private final Map<String , Object> coreScopeSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only for testing purposes
|
* Only for testing purposes
|
||||||
*/
|
*/
|
||||||
DataImporter() {
|
DataImporter() {
|
||||||
|
coreScopeSession = new HashMap<String, Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
DataImporter(String dataConfig, SolrCore core,
|
DataImporter(String dataConfig, SolrCore core, Map<String, Properties> ds, Map<String, Object> session) {
|
||||||
Map<String, Properties> ds) {
|
|
||||||
if (dataConfig == null)
|
if (dataConfig == null)
|
||||||
throw new DataImportHandlerException(DataImportHandlerException.SEVERE,
|
throw new DataImportHandlerException(DataImportHandlerException.SEVERE,
|
||||||
"Configuration not found");
|
"Configuration not found");
|
||||||
this.core = core;
|
this.core = core;
|
||||||
this.schema = core.getSchema();
|
this.schema = core.getSchema();
|
||||||
dataSourceProps = ds;
|
dataSourceProps = ds;
|
||||||
|
if (session == null)
|
||||||
|
session = new HashMap<String, Object>();
|
||||||
|
coreScopeSession = session;
|
||||||
loadDataConfig(dataConfig);
|
loadDataConfig(dataConfig);
|
||||||
|
|
||||||
for (Map.Entry<String, SchemaField> entry : schema.getFields().entrySet()) {
|
for (Map.Entry<String, SchemaField> entry : schema.getFields().entrySet()) {
|
||||||
|
@ -516,6 +521,10 @@ public class DataImporter {
|
||||||
return schema;
|
return schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, Object> getCoreScopeSession() {
|
||||||
|
return coreScopeSession;
|
||||||
|
}
|
||||||
|
|
||||||
SolrCore getCore() {
|
SolrCore getCore() {
|
||||||
return core;
|
return core;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue