Solr Replication(复制)是怎样工作的

        luence有一个IndexDeletePolicy接口,这个接口是提供luence删除索引文件的两个时机,分别是init和commit,

init是在IndexWirter创建时执行的。commit是在有索引文件更新,提交是执行的。而indexDeletePolicy这两个方法都会得到一个提交点集合即(IndexCommit),IndexCommit是luence的一个抽象类,从它可以取到该提交点相关的段文件名,所有的索引文件,索引目录,索引版本,最后修改时间等,具体的方法如下:

   /**

   * Get the segments file (<code>segments_N</code>) associated 

   * with this commit point.

   */

  public abstract String getSegmentsFileName();

  /**

   * Returns all index files referenced by this commit point.

   */

  public abstract Collection<String> getFileNames() throws IOException;

 

  /**

   * Returns the {@link Directory} for the index.

   */

  public abstract Directory getDirectory();

 

/** Returns the version for this IndexCommit.  This is the

   *  same value that {@link IndexReader#getVersion} would

   *  return if it were opened on this commit. */

  public abstract long getVersion();

/** Convenience method that returns the last modified time

   *  of the segments_N file corresponding to this index

   *  commit, equivalent to

   *  getDirectory().fileModified(getSegmentsFileName()). */

  public long getTimestamp() throws IOException {

    return getDirectory().fileModified(getSegmentsFileName());

  }

 

所以通过indexCommit,Solr能知道那些文件是需要复制的。

 

复制索引文件

 

      Solr复制是从机Slave不断的向主机发起轮询操作,看主机的索引文件版本是否发生变化,如果发生了变化,则从机就下载索引文件到一个临时目录,如果下载期间出现通讯故障,则会从断点出继续下载。下载完所有的文件时,把下载的文件移动到索引目录,通过ReplicationHandler发起一个commit命令,重新加载索引文件。

 

转载自:http://ronxin999.blog.163.com/blog/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值