Solr鎖機制

Lucene索引,然後讓solr能及時查詢到lucene做的索引方案:

 

1、Lucene索引。(先刪除鎖)

while (IndexWriter.isLocked(directory) )

{

      IndexWriter.unlock(directory);

}

 

2、solr提交數據後有一個reopen索引操作,lucene雖然做了索引,但是solr並沒有進行這個動作,所以要調用solr手動來實現。(這邊無法調用刪除鎖的接口)

http://localhost:8081/solr/admin/cores?action=RELOAD&core=event

 

3、lucene調用indexWrite.close();包括解鎖(刪除write.lock)和釋放。

 

 

 

 

1、 修改solrconfig.xml中的配置文件:

<unlockOnStartup>true</unlockOnStartup>

將solrcore啓動時不設置鎖。

 

<lockType>${solr.lock.type:simple} </lockType>

提供了四種索引鎖機制,single,native,simple,Defaults,默認是native,如果是Lucene索引,想要solr來識別,則要改爲simple。

 

 single = SingleInstanceLockFactory - suggested for a

                  read-only index or when thereis no possibility of

                 another process trying tomodify the index.

 native = NativeFSLockFactory - uses OS native file locking.

                  Do not use when multiple solrwebapps in the same

                  JVM are attempting to share asingle index.

 simple = SimpleFSLockFactory  -uses a plain file for locking

 

  Defaults: 'native' is default for Solr3.6 andlater, otherwise

                   'simple' is the default

 

然後lucene中一定要釋放該鎖,native的鎖lucene釋放不了。

 

 

發佈了39 篇原創文章 · 獲贊 7 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章