a blog for those who code

Friday 24 August 2018

Master Slave Replication in Solr

We can use SOLR backend for searching, and to reduce the load on a single server we can do replication as a Master Server and Slave Server where the complete copy of a master server is copied over to one or more slave server.

The the main motto of using Master-Slave Configuration is that you can keep one system to completely do the indexing i.e. if any new documents comes in it will be added by the Master and once done slave will show it to the User by getting the updated list from the master that is called searching. All queries or the result are handled by the slaves.

To start with the Master-Slave Replication you need atleast 2 system where one acts as a master and one as a slave. You can have more than one slave too, which all the slaves will act as a query processing server and it just removes the work load from all the servers.

The configuration of the server is rather simple where you need to add the replication request handler as shown below in solrconfig.js.

<requestHandler name="/replication" class="solr.ReplicationHandler" >
    <lst name="master">
        <str name="enable">true</str>
        <str name="replicateAfter">commit</str>
        <str name="confFiles">schema.xml,stopwords.txt,elevate.xml</str>
        <str name="commitReserveDuration">00:00:20</str>
        <str name="backupAfter">optimize</str>
     </lst>
     <lst name="slave">
        <str name="enable">false</str>
        <str name="masterUrl">MASTER_URL/replication</str>
        <str name="pollInterval">00:00:60</str>
        <str name="compression">internal</str>
        <str name="httpConnTimeout">5000</str>
        <str name="httpReadTimeout">10000</str>
     </lst>
  </requestHandler>

If it is a master you have to make <str name="enable"></str> as true and when it is slave it should be true for that server. We want the replication should be done after all the files are indexed that's why it is replication after commit as shown in the code above. In the confFiles you need to write what all the files which you want to replicate like which files to copy. Here we are keeping schema.xml,stopwords.txt and elevate.xml.

In the slave we have to say which is the Master URL and what is the poll interval of finding the new documents from the master.

That way you can create Master-Slave configuration and thus the load is balanced between two system and not one.

Please like and share the CodingDefined.com blog if you find it useful and helpful.


No comments:

Post a Comment