lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
Subject Re: Reusing same IndexSearcher
Date Wed, 05 Mar 2008 17:41:06 GMT

Actually you do need to make a new IndexSearcher every time you  
reopen a new IndexReader.

However, that should not lead to leaking file descriptors.  All open  
files are held by IndexReader (not IndexSearcher), so as long as you  
are properly closing your IndexReader's you shouldn't use up file  
descriptors.

Mike

Mindaugas ?ak?auskas wrote:

> Hi,
>
> Another newbie here...using Lucene 2.3.1 on Linux. Hopefully anyone
> could advice me on /subj/.
>
> Both IndexSearcher Javadoc and Lucene FAQ says the IndexSearcher
> should be reused as it's thread safe. That's OK.
> Now if I have index changed, I need to reopen the IndexReader that is
> associated with it. How do I do this as IndexSearcher has no setter
> method for IndexReader?
>
> Let's speak in Java. Say, we've got a static singletone accessor  
> method:
>
> ...
> private static Searcher instance;
> ...
> public static Searcher getLuceneSearcher () {
>    if( instance == null ) {
>       IndexReader reader = IndexReader.open( "/tmp/index_folder" );
>       instance = new IndexSearcher( reader );    // simple yet boring
>    } else {                                    // here goes the fun  
> part
>       IndexReader r_old = instance.getIndexReader();
>       IndexReader r_new = r_old.reopen();
>       if( r_old != r_new ) {
>          r_old.close();                  // thanks for nice  
> Javadoc, guys!
>          // what to do now? there's no instance.setIndexReader 
> ( r_new )!
>       }
>    }
>    return instance;
> }
>
> Of course, I could create a new IndexSearcher on the else branch and
> return it. However, this approach resulted the infamous "too many open
> files" exception. Lifting the `ulimit -n` to hundreds of thousands of
> files didn't really help as the same exception was still being thrown
> (actual resource usage fluctuating around 2000 of open files). Then
> from `lsof` output I noticed that the same segment file was being open
> more than once, apparently from different instances of
> IndexSearchers/IndexReaders and went the path shown above. Maybe I'm
> just plain wrong.
>
> Really appreciate your advice.
>
> Regards,
> Mindaugas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message