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 Khawaja Shams <ks...@gmail.com> on 2008/10/15 04:35:32 UTC
Closing Index Reader
Hello, I am using the reopen method in the IndexReader class. In the case
of the IndexReader being updated, I would like to create a new IndexSearcher
and close the old IndexReader. When closing an instance of IndexReader, do I
have to wait for currently executing searches (through an IndexSearcher with
this instance of the IndexReader) to complete? The javadoc states that I
should not invoke any method on the reader after the close is called, but I
am curious about the state of the searches that are using the reader when
the close is called.
I would appreciate any thoughts on the question and on my approach.
Thanks!
Re: Closing Index Reader
Posted by Michael McCandless <lu...@mikemccandless.com>.
That is correct, as long as you incRef the reader before starting each
query, and decRef the reader after finishing each query.
If you call close() during this time, the reader is not actually
closed until decRef is called for all previous incRefs.
Be certain that once you close() a reader there is no way a new query
can grab that reader. That would be a thread hazard that could result
in using an already closed reader.
Also be certain you always decRef, eg in a finally clause.
Mike
Khawaja Shams wrote:
> Hello, Thank you for your ideas. While these look promising, it
> seems like
> there are many places within Lucene's codebase that are invoking the
> incRef
> and decRef methods. Upon a shallow analysis of the code, it seems
> like I
> can call close, and the doClose method does not get called until
> refCount is
> 0. Can anyone correct or confirm my assumption that you can call
> close and
> any query in progress as you call close will succeed because the
> reader
> won't be closed until the refCount is 0. Thanks again!
>
> On Wed, Oct 15, 2008 at 3:10 AM, Michael McCandless <
> lucene@mikemccandless.com> wrote:
>
>>
>> As of 2.4.0 they are public.
>>
>> Mike
>>
>>
>> Ganesh wrote:
>>
>> incRef/decRef methods are protected. Is there any other way to use
>> these
>>> methods without extending it?
>>>
>>> Regards
>>> Ganesh
>>>
>>> ----- Original Message ----- From: "Michael McCandless" <
>>> lucene@mikemccandless.com>
>>> To: <ja...@lucene.apache.org>
>>> Sent: Wednesday, October 15, 2008 2:31 PM
>>> Subject: Re: Closing Index Reader
>>>
>>>
>>>
>>>> Ganesh wrote:
>>>>
>>>> Yes. Once the Indexreader is closed, you should not do make any
>>>> calls
>>>>> with that object.
>>>>> Extend the IndexReader to add support for reference count. Close
>>>>> the
>>>>> reader once the count is zero.
>>>>>
>>>>
>>>> Actually you can just use the [expert] incRef/decRef methods on
>>>> IndexReader to track in-flight searches still using it. You
>>>> shouldn't have
>>>> to extend it.
>>>>
>>>> Mike
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>>>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>>>
>>>
>>> Send instant messages to your online friends
>>> http://in.messenger.yahoo.com
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Closing Index Reader
Posted by Khawaja Shams <ks...@gmail.com>.
Hello, Thank you for your ideas. While these look promising, it seems like
there are many places within Lucene's codebase that are invoking the incRef
and decRef methods. Upon a shallow analysis of the code, it seems like I
can call close, and the doClose method does not get called until refCount is
0. Can anyone correct or confirm my assumption that you can call close and
any query in progress as you call close will succeed because the reader
won't be closed until the refCount is 0. Thanks again!
On Wed, Oct 15, 2008 at 3:10 AM, Michael McCandless <
lucene@mikemccandless.com> wrote:
>
> As of 2.4.0 they are public.
>
> Mike
>
>
> Ganesh wrote:
>
> incRef/decRef methods are protected. Is there any other way to use these
>> methods without extending it?
>>
>> Regards
>> Ganesh
>>
>> ----- Original Message ----- From: "Michael McCandless" <
>> lucene@mikemccandless.com>
>> To: <ja...@lucene.apache.org>
>> Sent: Wednesday, October 15, 2008 2:31 PM
>> Subject: Re: Closing Index Reader
>>
>>
>>
>>> Ganesh wrote:
>>>
>>> Yes. Once the Indexreader is closed, you should not do make any calls
>>>> with that object.
>>>> Extend the IndexReader to add support for reference count. Close the
>>>> reader once the count is zero.
>>>>
>>>
>>> Actually you can just use the [expert] incRef/decRef methods on
>>> IndexReader to track in-flight searches still using it. You shouldn't have
>>> to extend it.
>>>
>>> Mike
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>>
>>
>> Send instant messages to your online friends
>> http://in.messenger.yahoo.com
>> ---------------------------------------------------------------------
>> 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
>
>
Re: Closing Index Reader
Posted by Michael McCandless <lu...@mikemccandless.com>.
As of 2.4.0 they are public.
Mike
Ganesh wrote:
> incRef/decRef methods are protected. Is there any other way to use
> these methods without extending it?
>
> Regards
> Ganesh
>
> ----- Original Message ----- From: "Michael McCandless" <lucene@mikemccandless.com
> >
> To: <ja...@lucene.apache.org>
> Sent: Wednesday, October 15, 2008 2:31 PM
> Subject: Re: Closing Index Reader
>
>
>>
>> Ganesh wrote:
>>
>>> Yes. Once the Indexreader is closed, you should not do make any
>>> calls with that object.
>>> Extend the IndexReader to add support for reference count. Close
>>> the reader once the count is zero.
>>
>> Actually you can just use the [expert] incRef/decRef methods on
>> IndexReader to track in-flight searches still using it. You
>> shouldn't have to extend it.
>>
>> Mike
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>
> Send instant messages to your online friends http://in.messenger.yahoo.com
> ---------------------------------------------------------------------
> 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
Re: Closing Index Reader
Posted by Ganesh <em...@yahoo.co.in>.
incRef/decRef methods are protected. Is there any other way to use these
methods without extending it?
Regards
Ganesh
----- Original Message -----
From: "Michael McCandless" <lu...@mikemccandless.com>
To: <ja...@lucene.apache.org>
Sent: Wednesday, October 15, 2008 2:31 PM
Subject: Re: Closing Index Reader
>
> Ganesh wrote:
>
>> Yes. Once the Indexreader is closed, you should not do make any calls
>> with that object.
>> Extend the IndexReader to add support for reference count. Close the
>> reader once the count is zero.
>
> Actually you can just use the [expert] incRef/decRef methods on
> IndexReader to track in-flight searches still using it. You shouldn't
> have to extend it.
>
> Mike
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
Send instant messages to your online friends http://in.messenger.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Closing Index Reader
Posted by Michael McCandless <lu...@mikemccandless.com>.
Ganesh wrote:
> Yes. Once the Indexreader is closed, you should not do make any
> calls with that object.
> Extend the IndexReader to add support for reference count. Close the
> reader once the count is zero.
Actually you can just use the [expert] incRef/decRef methods on
IndexReader to track in-flight searches still using it. You shouldn't
have to extend it.
Mike
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Closing Index Reader
Posted by Ganesh <em...@yahoo.co.in>.
Yes. Once the Indexreader is closed, you should not do make any calls with
that object.
Extend the IndexReader to add support for reference count. Close the reader
once the count is zero.
Regards
Ganesh
----- Original Message -----
From: "Khawaja Shams" <ks...@gmail.com>
To: <ja...@lucene.apache.org>
Sent: Wednesday, October 15, 2008 8:05 AM
Subject: Closing Index Reader
> Hello, I am using the reopen method in the IndexReader class. In the case
> of the IndexReader being updated, I would like to create a new
> IndexSearcher
> and close the old IndexReader. When closing an instance of IndexReader, do
> I
> have to wait for currently executing searches (through an IndexSearcher
> with
> this instance of the IndexReader) to complete? The javadoc states that I
> should not invoke any method on the reader after the close is called, but
> I
> am curious about the state of the searches that are using the reader when
> the close is called.
>
>
> I would appreciate any thoughts on the question and on my approach.
>
>
> Thanks!
>
Send instant messages to your online friends http://in.messenger.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org