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: Is Searcher Manager in Lucene in Action 2nd Edition Correct ?
Date Thu, 03 Nov 2011 16:13:29 GMT
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 <paul_t100@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


Mime
View raw message