From 0d6494cb758cb56e30604b05858a517daca58556 Mon Sep 17 00:00:00 2001 From: Shalin Shekhar Mangar Date: Tue, 27 Jan 2009 07:21:52 +0000 Subject: [PATCH] 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 --- contrib/dataimporthandler/CHANGES.txt | 3 +++ .../solr/handler/dataimport/Context.java | 22 +++++++++++++++++-- .../solr/handler/dataimport/ContextImpl.java | 4 ++++ .../handler/dataimport/DataImportHandler.java | 14 ++++-------- .../solr/handler/dataimport/DataImporter.java | 13 +++++++++-- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/contrib/dataimporthandler/CHANGES.txt b/contrib/dataimporthandler/CHANGES.txt index c88bc63c4d3..84a9ac4d571 100644 --- a/contrib/dataimporthandler/CHANGES.txt +++ b/contrib/dataimporthandler/CHANGES.txt @@ -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 diff --git a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/Context.java b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/Context.java index e646def8aaf..5ef28145fed 100644 --- a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/Context.java +++ b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/Context.java @@ -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 diff --git a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/ContextImpl.java b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/ContextImpl.java index c6e9e8bbd88..0119414c4fe 100644 --- a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/ContextImpl.java +++ b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/ContextImpl.java @@ -126,6 +126,8 @@ public class ContextImpl extends Context { Map 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 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; } diff --git a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImportHandler.java b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImportHandler.java index 4c31733c0ab..37ebbcc2869 100644 --- a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImportHandler.java +++ b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImportHandler.java @@ -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 variables = new HashMap(); - - private Map dataSources = new HashMap(); private List debugDocuments; private boolean debugEnabled = true; + private Map coreScopeSession = new HashMap(); + @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(); - variables = new HashMap(); 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++; } diff --git a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImporter.java b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImporter.java index 930cf413e96..6000b530eba 100644 --- a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImporter.java +++ b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImporter.java @@ -75,20 +75,25 @@ public class DataImporter { private ReentrantLock importLock = new ReentrantLock(); + private final Map coreScopeSession; + /** * Only for testing purposes */ DataImporter() { + coreScopeSession = new HashMap(); } - DataImporter(String dataConfig, SolrCore core, - Map ds) { + DataImporter(String dataConfig, SolrCore core, Map ds, Map 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(); + coreScopeSession = session; loadDataConfig(dataConfig); for (Map.Entry entry : schema.getFields().entrySet()) { @@ -516,6 +521,10 @@ public class DataImporter { return schema; } + Map getCoreScopeSession() { + return coreScopeSession; + } + SolrCore getCore() { return core; }