Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Lucene: Java-User

How to test if an IndexReader is still open?

 

 

Lucene java-user RSS feed   Index | Next | Previous | View Threaded


Chris.Bamford at scalix

Oct 1, 2009, 5:52 AM

Post #1 of 2 (386 views)
Permalink
How to test if an IndexReader is still open?

Hi,

In an attempt to balance searching efficiency against the number of open file descriptors on my system, I cache IndexSearchers with a "last used" timestamp. A background cache manager thread then periodically checks the cache for any that haven't been used in a while and removes them from the cache. In so doing, it also closes their underlying IndexReaders to force the files to be released. This works very well, but I have hit a very occasional race condition where search code grabs a searcher from the cache just as it is about to expire - causing an "AlreadyClosed" exception. Rather than attempt to synchronize my code, I figured it might be less expensive if search() (I have extended IndexSearcher) were to check that the underlying IndexReader is still open - and reopen() if necessary. However, I cannot find a way to detect this ... is there a way? Failing that, what is the cost of just issuing a reopen() anyway?

Thanks for any thoughts / ideas.

- Chris


hossman_lucene at fucit

Oct 6, 2009, 11:59 AM

Post #2 of 2 (314 views)
Permalink
Re: How to test if an IndexReader is still open? [In reply to]

: I figured it might be less expensive if search() (I have extended
: IndexSearcher) were to check that the underlying IndexReader is still

if you're extending IndexSearcher anyway you can override the close()
method to update a boolean and then add your own isClosed() method.

: open - and reopen() if necessary. However, I cannot find a way to

FWIW: I don't believe you can call the reopen() method on a close
IndexReader ... but you can of course "re" open a new IndexReader
instance.

: detect this ... is there a way? Failing that, what is the cost of just
: issuing a reopen() anyway?

if the index hasn't changed, it's free. If the index has changed
a lot, it's as expensive as open() ... if there are minor changes then
it's somewhere in between.



-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
For additional commands, e-mail: java-user-help [at] lucene

Lucene java-user RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.