Click here to Skip to main content
15,881,600 members
Articles / Programming Languages / Java
Tip/Trick

How to Share Lib Between Cores When Using solr

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
17 Oct 2016CPOL2 min read 11.1K   1   1
Recording one solution to share lib between solr cores

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

  1. 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.
  2. 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.
  3. 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.
  4. After searching Google by new keywords, I found some solution from the results:
    1. 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)
    2. 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:

    HTML
    <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.

  5. 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

  1. Specify sharedLib='lib'(default SOLR_HOME/lib, or your specified relative path) in the <solr/> section of solr.xml
  2. 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".

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionMy vote of 5 Pin
Farhad Reza24-Oct-16 6:11
Farhad Reza24-Oct-16 6:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.