You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lucenenet.apache.org by in...@whentotrade.com on 2018/01/05 20:08:46 UTC

Problem with MultiReader and IndexWriter comitting to one of the Directories

Dear Lucene-Experts,

Happy New Year! I am getting crazy during the last days with the following
implementation and maybe someone of you might have an idea. (using nuget
lucene 4.8 beta0005) 

Here is my problem:

#1. A reader pool is maintained and managed for each index
----------------------------------------------------------------------------
---
I open one DirectoryReader per index. Each reader is kept up-to-date while
periodically checking ".IsCurrent" and disposing/opening a new one if true.
This way, I keep a static singleton for each reader that will be used by the
application. This reader pool management is completely independent from all
other search/writer operations to always have up-to-date static reader.

#2. Searching done via MultiReader/IndexSearcher
----------------------------------------------
Performing search is done by creating a NEW multireader for each search and
the static readers from the pool as array:  

  mainreader = new MultiReader(readersPoolArray, false); 
  searcher = new IndexSearcher(mainreader);

Important here is "false" during multireader setup to NOT close the
subreaders as they are managed by the readerspool (see #1) The MultiReader
and IndexSearcher are closed after each search. (assuming that the
MultIReader/IndexSearcher is just a wrapper and does not create much
overhead?)

This scenario works great in regards to searching.

The problem now comes into play, when in parallel a new indexing process is
starting with a new IndexWriter adding and committing documents to one
index. A new indexwriter for one directory is opened and new documents are
written to the index. Now, Lucene throws an INTERNAL exception with a
System.IO error. This happens when the writer executes the writer.commit() -
some files are blocked/still in use (e.g. some .cfs or other files can not
be overwritten). Therefore the writer commit process fails. Important is
that it fails only if a multireader was opened/closed before with that
directoryreader in the array. If the multireader was NOT used before, the
update works.

The process also works, if I use 
    mainreader = new MultiReader(readersPoolArray, true);

However, this makes no sense as all subreaders will be closed and need to be
reopened for each search. So it is clearly related to a multireader with
closeSubreaders set to false. There are always some files which will be
blocked after this mutireader was used and this prevents a new indexwriter
to commit...

Any idea if I am doing something wrong? Or is there something with the
MultiReader that might not work as expected?

I would be looking forward for any idea on how to move forward as this
implementation throws internal System.IO exceptions because lucene writer
fails during commit.

Thanks for your time!
Regards,
Lars von Thienen