Introduction
When using solr, you may want to share lib between cores, as solr cores may load different libs (configured with solrconfig.xml) with different class loaders. The problem is that they do not share class variables with each other, then you have to waste more space and spend more time to make distributed programs to work well with each other, e.g., word segmentation plug in loading dictionaries.
Steps to Solve this Problem
- It takes a long time to find the answers by searching Google, as my keywords may not mean to the point. “solr classloader different core” are my keywords, focus on "
classloader
". If I changed to "share between cores", I may find the answer earlier. - I doubt that I may have made some mistakes when configuring solr, but not. So I checked the solr source code in despair, and found that solr load libs for cores with different classloader indeed.
- By accident, I found some clauses in https://issues.apache.org/jira/browse/SOLR-409, they do not solve my problem, but find my keywords from the issue topic "Allow configurable class loader sharing between cores". I should look for my answer from issues.apache.org first.
- After searching Google by new keywords, I found some solution from the results:
- Find a place inside the solr, before the core is created (if you want singletons you must load them outside of the core, using a parent classloader - in case of jetty, this means writing your own jetty initialization or config to force shared class loaders. or find a place inside the solr, before the core is created. Google for montysolr to see the example of the first approach)
- The solr config XML can now specify a
libDir
element (the same way the dataDir
can be specified). That element can also specify through the 'shared' attribute whether the library is shared. By default, the shared attribute is true
; if you specify a libDir
, its class loader is made shareable.
Syntax:
<libDir shared='true*|false'>/path/to/shareable/dir</libDir>
http://grokbase.com/t/lucene/solr-dev/07bc9zs7bt/jira-created-solr-409-allow-configurable-class-loader-sharing-between-cores
I realize that solr may provide the ability for extending to meet my needs, it should and I believe it will.
- I turn to apache solr official documentation for a solution. When I search “apache-solr-ref-guide-5.5.pdf” with "
shared
", the answer comes up "For a multi-core configuration, you can specify sharedLib='lib'
in the <solr/>
section of solr.xml and place the necessary jar files there."
"shared
=> sharedLib
=> Multi-Core
", in fact I searched multicore in pdf before, but not "multi-core" which may lead to the right answer. "multicore vs multi-core", they are different!
The difficult course may be one of the reasons I write my experience in English here.
Solution
- Specify
sharedLib='lib'
(default SOLR_HOME/lib, or your specified relative path) in the <solr/>
section of solr.xml - Modify your shell script and cp the necessary jar files (maybe placed under folder "global" or somewhere else) there.
Points of Interest
I know this site by searching "good foreign developer forum site: zhihu.com".