You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by nizan <ni...@yahoo-inc.com> on 2010/11/09 09:54:08 UTC

solr dynamic core creation

Hi,

I’m not sure this is the right place, hopefully you can help. Anyway, I also
sent mail to solr-user@lucene.apache.org

I’m using solr – one master with 17 slaves in the server and using solrj as
the java client

Currently there’s only one core in all of them (master and slaves) – only
the cpaCore.

I thought about using multi-cores solr, but I have some problems with that.

I don’t know in advance which cores I’d need – 

When my java program runs, I call for documents to be index to a certain
url, which contains the core name, and I might create a url based on core
that is not yet created. For example:

(at the begining, the only core is cpaCore)

Calling to index – http://localhost:8080/cpaCore  - existing core,
everything as usual
Calling to index -  http://localhost:8080/newCore - Currently throws
excecption. what I'd like to happen is - server realizes there’s no core
“newCore”, creates it and indexes to it. After that – also creates the new
core in the slaves
Calling to index – http://localhost:8080/newCore  - existing core,
everything as usual

What I’d like to have on the server side to do is realize by itself if the
cores exists or not, and if not  - create it

One other restriction – I can’t change anything in the client side – calling
to the server can only make the calls it’s doing now – for index and search,
and cannot make calls for cores creation via the CoreAdminHandler. All I can
do is something in the server itself

What can I do to get it done? Write some RequestHandler? REquestProcessor?
Any other option?

Thanks, nizan

-- 
View this message in context: http://lucene.472066.n3.nabble.com/solr-dynamic-core-creation-tp1867705p1867705.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: solr dynamic core creation

Posted by samarth s <sa...@gmail.com>.
Hi nizan,

I have the same requirement of creating cores on the fly. Was looking
for some API provided by http solr server. Currently working around by
writing my own shell script on the server (solr server :) ). Any
better leads on the same?

Thanks,
Samarth

On Thu, Nov 11, 2010 at 9:27 PM, Robert Sandiford
<bo...@sirsidynix.com> wrote:
>
> No - in reading what you just wrote, and what you originally wrote, I think
> the misunderstanding was mine, based on the architecture of my code.  In my
> code, it is our 'server' level that does the SolrJ indexing calls, but you
> meant 'server' to be the Solr instance, and what you mean by 'client' is
> what I was thinking of (without thinking) as the 'server'...
>
> Sorry about that.  Hopefully someone else can chime in on your specific
> issue...
> --
> View this message in context: http://lucene.472066.n3.nabble.com/solr-dynamic-core-creation-tp1867705p1883354.html
> Sent from the Solr - User mailing list archive at Nabble.com.

Re: solr dynamic core creation

Posted by Robert Sandiford <bo...@sirsidynix.com>.
No - in reading what you just wrote, and what you originally wrote, I think
the misunderstanding was mine, based on the architecture of my code.  In my
code, it is our 'server' level that does the SolrJ indexing calls, but you
meant 'server' to be the Solr instance, and what you mean by 'client' is
what I was thinking of (without thinking) as the 'server'...

Sorry about that.  Hopefully someone else can chime in on your specific
issue...
-- 
View this message in context: http://lucene.472066.n3.nabble.com/solr-dynamic-core-creation-tp1867705p1883354.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: solr dynamic core creation

Posted by nizan <ni...@yahoo-inc.com>.
Hi,

Maybe just don't understand all the concept there and I mix up server and
client...

Client - The place where I make the http calls (for index, search etc.) -
where I use the CommonsHttpSolrServer as the solr server. This machine isn't
defined as master or slave, it just use solr as search engine

Server - The http calls I made in the client, goes to another server, the
master solr server (or one of the slaves), where I have embeddedSolrServer,
aren't they?

thanks, nizan
-- 
View this message in context: http://lucene.472066.n3.nabble.com/solr-dynamic-core-creation-tp1867705p1883269.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: solr dynamic core creation

Posted by Robert Sandiford <bo...@sirsidynix.com>.
Hmmm.  Maybe you need to define what you mean by 'server' and what you mean
by 'client'.
-- 
View this message in context: http://lucene.472066.n3.nabble.com/solr-dynamic-core-creation-tp1867705p1883238.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: solr dynamic core creation

Posted by nizan <ni...@yahoo-inc.com>.
Hi,

Thanks for the offers, I'll take deeper look into them.

In the offers you showed me, if I understand correctly, the call for
creation is done in the client side. I need the mechanism we'll work in the
server side.

I know it sounds stupid, but I need the client side wouldn't know about
which cores are there or not, and on the server side I (maybe with a
handler?), will understand if the core is not created, and create it if
needed.

Thanks, nizan
-- 
View this message in context: http://lucene.472066.n3.nabble.com/solr-dynamic-core-creation-tp1867705p1883213.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: solr dynamic core creation

Posted by Robert Sandiford <bo...@sirsidynix.com>.
Hi, nizan.  I didn't realize that just replying to a thread from my email
client wouldn't get back to you.  Here's some info on this thread since your
original post:


On Nov 10, 2010, at 12:30pm, Bob Sandiford wrote:

> Why not use replication?  Call it inexperience...
>
> We're really early into working with and fully understanding Solr and 
> the best way to approach various issues.  I did mention that this was 
> a prototype and non-production code, so I'm covered, though :)
>
> We'll take a look at the replication feature...

Replication doesn't replicate the top-level solr.xml file that defines
available cores, so if dynamic cores is a requirement then your custom code
isn't wasted :)

-- Ken


>> -----Original Message-----
>> From: Jonathan Rochkind [mailto:rochkind@jhu.edu]
>> Sent: Wednesday, November 10, 2010 3:26 PM
>> To: solr-user@lucene.apache.org
>> Subject: Re: Dynamic creating of cores in solr
>>
>> You could use the actual built-in Solr replication feature to 
>> accomplish that same function -- complete re-index to a 'master', and 
>> then when finished, trigger replication to the 'slave', with the 
>> 'slave' being the live index that actually serves your applications.
>>
>> I am curious if there was any reason you chose to roll your own 
>> solution using JSolr and dynamic creation of cores, instead of simply 
>> using the replication feature. Were there any downsides of using the 
>> replication feature for this purpose that you amerliorated through 
>> your solution?
>>
>> Jonathan
>>
>> Bob Sandiford wrote:
>>> We also use SolrJ, and have a dynamically created Core capability -
>> where we don't know in advance what the Cores will be that we 
>> require.
>>>
>>> We almost always do a complete index build, and if there's a 
>>> previous
>> instance of that index, it needs to be available during a complete 
>> index build, so we have two cores per index, and switch them as 
>> required at the end of an indexing run.
>>>
>>> Here's a summary of how we do it (we're in an early prototype /
>> implementation right now - this isn't  production quality code - as 
>> you can tell from our voluminous javadocs on the methods...)
>>>
>>> 1) Identify if the core exists, and if not, create it:
>>>
>>>   /**
>>>     * This method instantiates two SolrServer objects, solr and
>> indexCore.  It requires that
>>>     * indexName be set before calling.
>>>     */
>>>    private void initSolrServer() throws IOException
>>>    {
>>>        String baseUrl = "http://localhost:8983/solr/";
>>>        solr = new CommonsHttpSolrServer(baseUrl);
>>>
>>>        String indexCoreName = indexName +
>> SolrConstants.SUFFIX_INDEX; // SUFIX_INDEX = "_INDEX"
>>>        String indexCoreUrl = baseUrl + indexCoreName;
>>>
>>>        // Here we create two cores for the indexName, if they don't
>> already exist - the live core used
>>>        // for searching and a second core used for indexing. After
>> indexing, the two will be switched so the
>>>        // just-indexed core will become the live core. The way that
>> core swapping works, the live core will always
>>>        // be named [indexName] and the indexing core will always be
>> named [indexname]_INDEX, but the
>>>        // dataDir of each core will alternate between [indexName]_1
>> and [indexName]_2.
>>>        createCoreIfNeeded(indexName, indexName + "_1", solr);
>>>        createCoreIfNeeded(indexCoreName, indexName + "_2", solr);
>>>        indexCore = new CommonsHttpSolrServer(indexCoreUrl);
>>>    }
>>>
>>>
>>>   /**
>>>     * Create a core if it does not already exists. Returns true if a
>> new core was created, false otherwise.
>>>     */
>>>    private boolean createCoreIfNeeded(String coreName, String
>> dataDir, SolrServer server) throws IOException
>>>    {
>>>        boolean coreExists = true;
>>>        try
>>>        {
>>>            // SolrJ provides no direct method to check if a core
>> exists, but getStatus will
>>>            // return an empty list for any core that doesn't.
>>>            CoreAdminResponse statusResponse =
>> CoreAdminRequest.getStatus(coreName, server);
>>>            coreExists =
>> statusResponse.getCoreStatus(coreName).size() > 0;
>>>            if(!coreExists)
>>>            {
>>>                // Create the core
>>>                LOG.info("Creating Solr core: " + coreName);
>>>                CoreAdminRequest.Create create = new
>> CoreAdminRequest.Create();
>>>                create.setCoreName(coreName);
>>>                create.setInstanceDir(".");
>>>                create.setDataDir(dataDir);
>>>                create.process(server);
>>>            }
>>>        }
>>>        catch (SolrServerException e)
>>>        {
>>>            e.printStackTrace();
>>>        }
>>>        return !coreExists;
>>>    }
>>>
>>>
>>> 2) Do the index, clearing it first if it's a complete rebuild:
>>>
>>> 	[snip]
>>>        if (fullIndex)
>>>        {
>>>            try
>>>            {
>>>                indexCore.deleteByQuery("*:*");
>>>            }
>>>            catch (SolrServerException e)
>>>            {
>>>                e.printStackTrace();  //To change body of catch
>> statement use File | Settings | File Templates.
>>>            }
>>>        }
>>> 	[snip]
>>>
>>> 	various logic, then (we submit batches of 100 :
>>>
>>> 	[snip]
>>>            List<SolrInputDocument> docList =
>> b.getSolrInputDocumentList();
>>> 	      UpdateResponse rsp;
>>>            try
>>>            {
>>>                rsp = indexCore.add(docList);
>>>                rsp = indexCore.commit();
>>>            }
>>>            catch (IOException e)
>>>            {
>>>                LOG.warn("Error commiting documents", e);
>>>            }
>>>            catch (SolrServerException e)
>>>            {
>>>                LOG.warn("Error commiting documents", e);
>>>            }
>>> 	[snip]
>>>
>>> 3) optimize, then swap cores:
>>>
>>>    private void optimizeCore()
>>>    {
>>>        try
>>>        {
>>>            indexCore.optimize();
>>>        }
>>>        catch(SolrServerException e)
>>>        {
>>>            LOG.warn("Error while optimizing core", e);
>>>        }
>>>        catch(IOException e)
>>>        {
>>>            LOG.warn("Error while optimizing core", e);
>>>        }
>>>    }
>>>
>>>    private void swapCores()
>>>    {
>>>        String liveCore = indexName;
>>>        String indexCore = indexName + SolrConstants.SUFFIX_INDEX; //
>> SUFFIX_INDEX = "_INDEX"
>>>        LOG.info("Swapping Solr cores: " + indexCore + ", " +
>> liveCore);
>>>        CoreAdminRequest request = new CoreAdminRequest();
>>>        request.setAction(CoreAdminAction.SWAP);
>>>        request.setCoreName(indexCore);
>>>        request.setOtherCoreName(liveCore);
>>>        try
>>>        {
>>>            request.process(solr);
>>>        }
>>>        catch (SolrServerException e)
>>>        {
>>>            e.printStackTrace();
>>>        }
>>>        catch (IOException e)
>>>        {
>>>            e.printStackTrace();
>>>        }
>>>    }
>>>
>>>
>>> And that's about it.
>>>
>>> You could adjust the above so there's only one core per index that
>> you want - if you don't do complete reindexes, and don't need the 
>> index to always be searchable.
>>>
>>> Hope that helps...
>>>
>>>
>>> Bob Sandiford | Lead Software Engineer | SirsiDynix
>>> P: 800.288.8020 X6943 | Bob.Sandiford@sirsidynix.com 
>>> www.sirsidynix.com
>>>
>>>
>>>
>>>> -----Original Message-----
>>>> From: Nizan Grauer [mailto:nizang@yahoo-inc.com]
>>>> Sent: Tuesday, November 09, 2010 3:36 AM
>>>> To: solr-user@lucene.apache.org
>>>> Subject: Dynamic creating of cores in solr
>>>>
>>>> Hi,
>>>>
>>>> I'm not sure this is the right mail to write to, hopefully you can
>> help
>>>> or direct me to the right person
>>>>
>>>> I'm using solr - one master with 17 slaves in the server and using 
>>>> solrj as the java client
>>>>
>>>> Currently there's only one core in all of them (master and
>>>> slaves) -
>>>> only the cpaCore.
>>>>
>>>> I thought about using multi-cores solr, but I have some problems
>> with
>>>> that.
>>>>
>>>> I don't know in advance which cores I'd need -
>>>>
>>>> When my java program runs, I call for documents to be index to a 
>>>> certain url, which contains the core name, and I might create a url 
>>>> based on core that is not yet created. For example:
>>>>
>>>> Calling to index - http://localhost:8080/cpaCore  - existing core, 
>>>> everything as usual Calling to index -  
>>>> http://localhost:8080/newCore - server realizes there's no core 
>>>> "newCore", creates it and indexes to it. After that
>> -
>>>> also creates the new core in the slaves Calling to index - 
>>>> http://localhost:8080/newCore  - existing core, everything as usual
>>>>
>>>> What I'd like to have on the server side to do is realize by itself
>> if
>>>> the cores exists or not, and if not  - create it
>>>>
>>>> One other restriction - I can't change anything in the client side 
>>>> - calling to the server can only make the calls it's doing now - 
>>>> for index and search, and cannot make calls for cores creation via 
>>>> the CoreAdminHandler. All I can do is something in the server 
>>>> itself
>>>>
>>>> What can I do to get it done? Write some RequestHandler?
>>>> REquestProcessor? Any other option?
>>>>
>>>> Thanks, nizan
>>>>
>>>
>>>
>>>
>

--------------------------
Ken Krugler
+1 530-210-6378
http://bixolabs.com
e l a s t i c   w e b   m i n i n g
-- 
View this message in context: http://lucene.472066.n3.nabble.com/solr-dynamic-core-creation-tp1867705p1883055.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: solr dynamic core creation

Posted by nizan <ni...@yahoo-inc.com>.
Does anyone has any idea on how to do this?
-- 
View this message in context: http://lucene.472066.n3.nabble.com/solr-dynamic-core-creation-tp1867705p1881374.html
Sent from the Solr - User mailing list archive at Nabble.com.