Search code examples
c#nhibernateconcurrencylucene.netnhibernate-search

Lucene.net & NHibernate search concurrency issues


I have a web application which uses Lucene.Net and NHibernate.Search as a full-text search engine. NHibernate.Search is setted up such that whenever a change is done in the database, it is propagated to the Lucene index.

The web application is running using 4 worker processes. First of all, is this an issue? I am noticing that the Lucene index is not 100% in sync with the database. Some changes to the database are not appearing in the Lucene index. However, when I manually try to re-index the data, this works fine.

Are there any concurrency implications with using Lucene.Net in a multi-process environment?


Solution

  • This sounds like an issue with an open IndexWriter keeping locks on the index directory. One worker process would lock the index for the other processes.

    Lucene.Net can be used in a multi-process environment as long as there's only one writer per index. Different directory implementations enforce this in different ways, usually involving a file named write.lock.

    A common solution is to have a separate search process which handles indexing and searching.