Page 1 of 1

How many solr servers can I add?

Posted: Wed Oct 22, 2014 1:17 am
by gowthamgutha
As per the requirement, I needed three instances of Solr servers. So, I have created three Index services, three search services.
All of these three servers are standalone and are at ports 8983,8984,8985 respectively.

The problem I am getting is that, when I use just the two servers, everything is fine. But, when I add the third server, to my fascination, I am getting an error like:

Unknown field 'productId' in MySolrSearchServiceImpl.java

though the field is declared and I haven't modified it. Here the above class corresponds to 8983 port. When I remove a server, which maintains different data and is it 8985 port, then I am not seeing this error. I don't understand the relation between those two servers. Here is how I have created those servers in applicationContext.xml file..

<bean id="AbcServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg value="http://localhost:8985/solr"/>
</bean>

<bean id="AbcReindexServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg value="http://localhost:8985/solr/reindex"/>
</bean>

<bean id="abc" class="com.mycompany.core.search.service.solr.AbcSearchServiceImpl">
<constructor-arg name="solrServer" ref="AbcServer" />
<constructor-arg name="reindexServer" ref="AbcReindexServer" />
</bean>

<bean id="solrServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg value="http://localhost:8983/solr"/>
</bean>

<bean id="solrReindexServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg value="http://localhost:8983/solr/reindex"/>
</bean>

<bean id="blSearchService" class="com.mycompany.core.search.service.solr.MySolrSearchServiceImpl">
<constructor-arg name="solrServer" ref="solrServer" />
<constructor-arg name="reindexServer" ref="solrReindexServer" />
</bean>

<bean id="DefSolrServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg value="http://localhost:8984/solr"/>
</bean>

<bean id="DefSolrReindexServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg value="http://localhost:8984/solr/reindex"/>
</bean>

<bean id="DefSearchService" class="com.mycompany.core.search.service.solr.DefSolrSearchServiceImpl">
<constructor-arg name="solrServer" ref="DefSolrServer" />
<constructor-arg name="reindexServer" ref="DefSolrReindexServer" />
</bean>

<bean id="rebuildIndexJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="blSearchService" />
<property name="targetMethod" value="rebuildIndex" />
</bean>

<bean id="rebuildIndexTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="rebuildIndexJobDetail" />
<property name="startDelay" value="${solr.index.start.delay}" />
<property name="repeatInterval" value="${solr.index.repeat.interval}" />
</bean>

<bean id="rebuildAbcIndexJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="blAbcSearchService" />
<property name="targetMethod" value="rebuildIndex" />
</bean>

<bean id="rebuildAbcIndexTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="rebuildAbcIndexJobDetail" />
<property name="startDelay" value="${solr.abc.index.start.delay}" />
<property name="repeatInterval" value="${solr.abc.index.repeat.interval}" />
</bean>

<bean id="rebuildDefIndexJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="blDefSearchService" />
<property name="targetMethod" value="rebuildIndex" />
</bean>

<bean id="rebuildDefIndexTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="rebuildDefIndexJobDetail" />
<property name="startDelay" value="${solr.def.index.start.delay}" />
<property name="repeatInterval" value="${solr.def.index.repeat.interval}" />
</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="rebuildDefIndexTrigger" />
<ref bean="rebuildAbcIndexTrigger" />
<ref bean="rebuildIndexTrigger" />
<!--<ref bean="purgeCartTrigger" />-->
<!--<ref bean="purgeCustomerTrigger" />-->
</list>
</property>
</bean>



But for all of those search services, I am using the same SolrContext class. Do I need to write SolrContext like classes of my own for each SearchService implementation?

Thanks in advance. Hope you will reply as asson as possible.

Re: How many solr servers can I add?

Posted: Tue Nov 04, 2014 5:54 pm
by phillipuniverse
"server" is probably a misnomer; this should actually just refer to cores. All of those will point to similar URLs in a clustered solr environment, you will just do some configuration to the standalone Solr instances to denote them as clustered. Then Solr does the job of making sure they are up and have failover.

The reason we have 3 parts here (admin, primary, reindex) is so that indexing can happen on a separate Solr core while the primary core is still active. In Solr 4.4+, they have a different URL for the admin to do things like swap the active core.

So I don't think you've configured this right. You can have as many servers as you want inside of a Solr cluster, but the configuration will only point to the master Solr server (I think).

Re: How many solr servers can I add?

Posted: Tue Nov 04, 2014 5:57 pm
by phillipuniverse
By the way, instead of using an HttpSolrServer you should look instead at LBHttpSolrServer, which is a sibling of HttpSolrServer designed for the scenario that I think you are trying to solve (high availability).