[Solr实践]Solr复制类ReplicationHandler使用介绍
Posted in solr on 七月 24th, 2010 by kafka0102
solr1.4中引入ReplicationHandler代替外部脚本来复制索引数据,ReplicationHandler使得复制索引数据更自动化。对于使用者来说,只要简单的配置好,就可以一劳永逸的享受solr的复制功能了。下面介绍其使用相关内容。
1、配置
ReplicationHandler是个RequestHandler,如果需要使用它,也就是在solrconfig.xml中配置它,下面介绍ReplicationHandler的配置参数。
1.1、Master
master的配置示例如下:
<requestHandler name="/replication" class="solr.ReplicationHandler" > <lst name="master"> <!--Replicate on 'startup' and 'commit'. 'optimize' is also a valid value for replicateAfter. --> <str name="replicateAfter">startup</str> <str name="replicateAfter">commit</str> <!--Create a backup after 'optimize'. Other values can be 'commit', 'startup'. It is possible to have multiple entries of this config string. Note that this is just for backup, replication does not require this. --> <!-- <str name="backupAfter">optimize</str> --> <!--If configuration files need to be replicated give the names here, separated by comma --> <str name="confFiles">schema.xml,stopwords.txt,elevate.xml</str> <!--The default value of reservation is 10 secs.See the documentation below . Normally , you should not need to specify this --> <str name="commitReserveDuration">00:00:10</str> </lst> </requestHandler>
说明:
1)replicateAfter可取startup、commit、optimize,表示触发复制的时机。使用中,这三个值都可以配上。
2)backupAfter表示备份时机,如果需要备份,solr会在配置的时机自动生成备份。
3)confFiles表示在复制时需要复制到slave的文件列表。
4)commitReserveDuration默认是10秒,这个值通常你通常不需要修改,除非你的网络慢到传输5M数据需要10秒以上的时间。
1.2、Slave
Slave的配置示例如下:
<requestHandler name="/replication" class="solr.ReplicationHandler" > <lst name="slave"> <!--fully qualified url for the replication handler of master . It is possible to pass on this as a request param for the fetchindex command--> <str name="masterUrl">http://master_host:port/solr/corename/replication</str> <!--Interval in which the slave should poll master .Format is HH:mm:ss . If this is absent slave does not poll automatically. But a fetchindex can be triggered from the admin or the http API --> <str name="pollInterval">00:00:20</str> <!-- THE FOLLOWING PARAMETERS ARE USUALLY NOT REQUIRED--> <!--to use compression while transferring the index files. The possible values are internal|external if the value is 'external' make sure that your master Solr has the settings to honour the accept-encoding header. see here for details http://wiki.apache.org/solr/SolrHttpCompression If it is 'internal' everything will be taken care of automatically. USE THIS ONLY IF YOUR BANDWIDTH IS LOW . THIS CAN ACTUALLY SLOWDOWN REPLICATION IN A LAN--> <str name="compression">internal</str> <!--The following values are used when the slave connects to the master to download the index files. Default values implicitly set as 5000ms and 10000ms respectively. The user DOES NOT need to specify these unless the bandwidth is extremely low or if there is an extremely high latency--> <str name="httpConnTimeout">5000</str> <str name="httpReadTimeout">10000</str> <!-- If HTTP Basic authentication is enabled on the master, then the slave can be configured with the following --> <str name="httpBasicAuthUser">username</str> <str name="httpBasicAuthPassword">password</str> </lst> </requestHandler>
说明:上面的参数也不需要太多解释,其中pollInterval参数表明slave从master复制数据的频率。如果对实时性要求不高,通常5-10分钟即可,也避免slave的indexsearcher频繁的切换,同时,master的commit频率也可相对保持一致。
2、HTTP API
solr的ReplicationHandler提供了一系列http命令(参数command),支持的可选值如下:
1)indexversion:slave从master获取最新的索引点信息。
2)filecontent:slave从master下载指定文件的内容。
3)filelist:slave从master获取指定indexversion的索引文件列表(及需要复制的配置文件)。
4)backup:备份索引。如果担心索引有损坏的可能性,可以定期备份索引。
5)fetchindex:手动复制数据,和slave自动复制相当。
6)disablepoll:停止slave的复制。
7)enablepoll:开启slave的复制。
8)abortfetch:终止slave上正在进行的下载文件过程。
9)commits:show当前仍旧保留的IndexCommit信息。
10)details:show slave当前的复制细节信息。
11)enablereplication:启动master对所有slave的复制功能
12)disablereplication:关闭master对所有slave的复制功能
4、性能
solr的ReplicationHandler使用http的分段连续的下载索引文件数据,而代替经典的rsync,solr wiki上给出的性能测试对比图如下:

可以看到,性能方面差别不大,不必有太多的担心。
4、参考文章
http://wiki.apache.org/solr/SolrReplication
=============================== 华丽的终止符 ================================
相关日志
One Response
Leave a Comment
七月 25th, 2010 at 12:44 上午
[...] 在上一文《solr ReplicationHandler使用介绍》的基础上,本文接着对solr的ReplicationHandler实现细节做些分析,这个分析原则上没有摘取大段代码,窃以为摘了代码后未见得有很好的阐述效果,但不摘取后窃又发现,阐述的效果依旧不好。归结起来,还是窃的表达不够深入浅出所致。闲言少叙,直接上内容。 [...]