You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Paul Taylor <pa...@fastmail.fm> on 2011/11/03 16:57:26 UTC

Is Searcher Manager in Lucene in Action 2nd Edition Correct ?

Been looking at the SearcherManager code to fix my code so that it 
doesn't close an IndexReader whilst still being used , but everytime I 
look at the SearchManager code it appears it will never close it, am I 
misunderstaning something  or is there a typo

This is how I see it

When an IndexSearcher from a reader is created getRef() returns 1
So a subsequent call to close for indexSearcher.getIndexReader() would 
reduce ref to zero and it would close.

In the SearchServer code, the ref count is increase on every usage via 
get() and decreased once finished with using release(). BUT the 
maybeReopen() method also calls get(), so even if the reader wasn't 
being used it refcount() would then be 2 and the so the call to 
release() within maybeReopen() will only take it down to one not zero, 
and hence it will never actually be closed ?

Paul



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


Re: Is Searcher Manager in Lucene in Action 2nd Edition Correct ?

Posted by Paul Taylor <pa...@fastmail.fm>.
On 03/11/2011 15:57, Paul Taylor wrote:
> Been looking at the SearcherManager code to fix my code so that it 
> doesn't close an IndexReader whilst still being used , but everytime I 
> look at the SearchManager code it appears it will never close it, am I 
> misunderstaning something  or is there a typo
>
> This is how I see it
>
> When an IndexSearcher from a reader is created getRef() returns 1
> So a subsequent call to close for indexSearcher.getIndexReader() would 
> reduce ref to zero and it would close.
>
> In the SearchServer code, the ref count is increase on every usage via 
> get() and decreased once finished with using release(). BUT the 
> maybeReopen() method also calls get(), so even if the reader wasn't 
> being used it refcount() would then be 2 and the so the call to 
> release() within maybeReopen() will only take it down to one not zero, 
> and hence it will never actually be closed ?
>
> Paul
>
Oh hangon, I missed the fact that swapSearcher also calls release() on 
the current server, so that would reduce 2 back down to 1 , and then 
doneReopen() takes it down to zero.

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


Re: Is Searcher Manager in Lucene in Action 2nd Edition Correct ?

Posted by Michael McCandless <lu...@mikemccandless.com>.
Reference counting is always tricky!

But I believe LIA2e's SearcherManager is correct.  You're right that
RC is 1 "on birth" and once it drops to 0 the IR is closed (and incRef
better not be called again).

Then, as long as every get is matched by a release, they all cancel to
net 0 change to the RC.  The app must call release for each get.  And,
yes, maybeReopen calls get() but it's matched (in try/finally) with a
call to release, so it too cancels to 0.

Then, finally, when swapSearcher() replaces the reader with a new one,
it decRefs the current one, thus dropping the 1 RC created at birth,
bringing it to 0.

So I think it all cancels to 0...

Note that the SearcherManager in Lucene (well, to be released with
3.5.0) has some improvements, so you should use that one instead of
the LIA2e version.

Mike McCandless

http://blog.mikemccandless.com

On Thu, Nov 3, 2011 at 11:57 AM, Paul Taylor <pa...@fastmail.fm> wrote:
> Been looking at the SearcherManager code to fix my code so that it doesn't
> close an IndexReader whilst still being used , but everytime I look at the
> SearchManager code it appears it will never close it, am I misunderstaning
> something  or is there a typo
>
> This is how I see it
>
> When an IndexSearcher from a reader is created getRef() returns 1
> So a subsequent call to close for indexSearcher.getIndexReader() would
> reduce ref to zero and it would close.
>
> In the SearchServer code, the ref count is increase on every usage via get()
> and decreased once finished with using release(). BUT the maybeReopen()
> method also calls get(), so even if the reader wasn't being used it
> refcount() would then be 2 and the so the call to release() within
> maybeReopen() will only take it down to one not zero, and hence it will
> never actually be closed ?
>
> Paul
>
>
>
> ---------------------------------------------------------------------
> 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