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/

猜你喜欢

转载自huanglz19871030.iteye.com/blog/1595302