How to handle multiple IndexWriter and multiple IndexWriter cross processes

I have been working on the Internet for two days ... I really need help.

I have an application with multiple threads trying to update the lucene index using the Open / Close IndexWriter for each update. Themes can start at any time.

Yes, the problem is with write.lock ! Thus, there can be two or more solutions:

1) check IndexWriter.IsLocked(index) , and if it is blocked, to sleep the thread.
2) Open IndexWriter and never close it. The problem is that I have another application using the same index. Also, when should I close the index and complete the whole process?

here are interesting publications
Lucene IndexWriter Stream Security
Lucene - open a private IndexWriter

Update: After about 2 years, I made a leisure API that wraps this , and all records and readings have been redirected to the API.

+6
source share
1 answer

Multiple threads, the same process:

Save IndexWriter and share it through several streams. IndexWriter is thread safe.

For several processes, your No. 1 solution is prone to problems with race conditions. You will need to use named Mutex to use it safely: http://msdn.microsoft.com/en-us/library/bwe34f1k.aspx

As I said, I personally chose the process of writing to the index and communicate with it using something like WCF.

+6
source

Source: https://habr.com/ru/post/925156/


All Articles