Apache Lucene open-source search software
SOLR-4652: Fix broken behavior with shared libraries in resource loader for solr.xml plugins.
Uwe Schindlere529be400683
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex c95ccdee6d1..a24233f23a4 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -147,6 +147,9 @@ Bug Fixes* SOLR-3758: Fixed SpellCheckComponent to work consistently with distributed grouping(James Dyer)+* SOLR-4652: Fix broken behavior with shared libraries in resource loader for+ solr.xml plugins. (Ryan Ernst, Robert Muir, Uwe Schindler)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.javaindex 6fbd76047a9..38a14e4da4e 100644--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java@@ -116,7 +116,6 @@ public class CoreContainerprotected CollectionsHandler collectionsHandler = null;protected File configFile = null;protected String libDir = null;- protected ClassLoader libLoader = null;protected SolrResourceLoader loader = null;protected Properties containerProperties;protected Map<String ,IndexSchema> indexSchemaCache;@@ -394,6 +393,15 @@ public class CoreContainer// now.cfg.substituteProperties();+ // add the sharedLib to the shared resource loader before initializing cfg based plugins+ libDir = cfg.get(ConfigSolr.ConfLevel.SOLR, "sharedLib", null);+ if (libDir != null) {+ File f = FileUtils.resolvePath(new File(dir), libDir);+ log.info("loading shared library: " + f.getAbsolutePath());+ loader.addToClassLoader(libDir);+ loader.reloadLuceneSPI();+ }+shardHandlerFactory = cfg.initShardHandler();coreMaps.allocateLazyCores(cfg, loader);@@ -448,7 +456,6 @@ public class CoreContainerdefaultCoreName = dcoreName;}persistent = cfg.getBool(ConfigSolr.ConfLevel.SOLR, "persistent", false);- libDir = cfg.get(ConfigSolr.ConfLevel.SOLR, "sharedLib", null);zkHost = cfg.get(ConfigSolr.ConfLevel.SOLR, "zkHost", null);coreLoadThreads = cfg.getInt(ConfigSolr.ConfLevel.SOLR, "coreLoadThreads", CORE_LOAD_THREADS);@@ -485,12 +492,6 @@ public class CoreContainer"SolrCloud requires a value of at least 2 in solr.xml for coreLoadThreads");}- if (libDir != null) {- File f = FileUtils.resolvePath(new File(dir), libDir);- log.info("loading shared library: " + f.getAbsolutePath());- libLoader = SolrResourceLoader.createClassLoader(f, null);- }-if (adminPath != null) {if (adminHandler == null) {coreAdminHandler = new CoreAdminHandler(this);@@ -876,7 +877,7 @@ public class CoreContainerthrow new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,"Could not find config name for collection:" + collection);}- solrLoader = new ZkSolrResourceLoader(instanceDir, zkConfigName, libLoader,+ solrLoader = new ZkSolrResourceLoader(instanceDir, zkConfigName, loader.getClassLoader(),ConfigSolrXml.getCoreProperties(instanceDir, dcore), zkController);config = getSolrConfigFromZk(zkConfigName, dcore.getConfigName(), solrLoader);schema = IndexSchemaFactory.buildIndexSchema(dcore.getSchemaName(), config);@@ -900,7 +901,7 @@ public class CoreContainerSolrResourceLoader solrLoader = null;SolrConfig config = null;- solrLoader = new SolrResourceLoader(instanceDir, libLoader, ConfigSolrXml.getCoreProperties(instanceDir, dcore));+ solrLoader = new SolrResourceLoader(instanceDir, loader.getClassLoader(), ConfigSolrXml.getCoreProperties(instanceDir, dcore));try {config = new SolrConfig(solrLoader, dcore.getConfigName(), null);} catch (Exception e) {@@ -1057,7 +1058,7 @@ public class CoreContainercd.getName(), instanceDir.getAbsolutePath());SolrResourceLoader solrLoader;if(zkController == null) {- solrLoader = new SolrResourceLoader(instanceDir.getAbsolutePath(), libLoader, ConfigSolrXml.getCoreProperties(instanceDir.getAbsolutePath(), cd));+ solrLoader = new SolrResourceLoader(instanceDir.getAbsolutePath(), loader.getClassLoader(), ConfigSolrXml.getCoreProperties(instanceDir.getAbsolutePath(), cd));} else {try {String collection = cd.getCloudDescriptor().getCollectionName();@@ -1069,7 +1070,7 @@ public class CoreContainerthrow new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,"Could not find config name for collection:" + collection);}- solrLoader = new ZkSolrResourceLoader(instanceDir.getAbsolutePath(), zkConfigName, libLoader,+ solrLoader = new ZkSolrResourceLoader(instanceDir.getAbsolutePath(), zkConfigName, loader.getClassLoader(),ConfigSolrXml.getCoreProperties(instanceDir.getAbsolutePath(), cd), zkController);} catch (KeeperException e) {log.error("", e);@@ -1187,8 +1188,6 @@ public class CoreContainer* @return a CoreAdminHandler*/protected CoreAdminHandler createMultiCoreHandler(final String adminHandlerClass) {- // :TODO: why create a new SolrResourceLoader? why not use this.loader ???- SolrResourceLoader loader = new SolrResourceLoader(solrHome, libLoader, null);return loader.newAdminHandlerInstance(CoreContainer.this, adminHandlerClass);}diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.javaindex 5858c851777..3f07c7f47bf 100644--- a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java+++ b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java@@ -309,6 +309,26 @@ public class TestCoreContainer extends SolrTestCaseJ4 {}}++ @Test+ public void testClassLoaderHierarchy() throws Exception {+ final CoreContainer cc = init("_classLoaderHierarchy");+ try {+ cc.setPersistent(false);+ ClassLoader sharedLoader = cc.loader.getClassLoader();+ ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();+ assertSame(contextLoader, sharedLoader.getParent());++ CoreDescriptor descriptor1 = new CoreDescriptor(cc, "core1", "./collection1");+ SolrCore core1 = cc.create(descriptor1);+ ClassLoader coreLoader = core1.getResourceLoader().getClassLoader();+ assertSame(sharedLoader, coreLoader.getParent());++ core1.close();+ } finally {+ cc.shutdown();+ }+ }private static final String EMPTY_SOLR_XML ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +"<solr persistent=\"false\">\n" +