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 "Zhang, Lisheng" <Li...@broadvision.com> on 2004/12/03 01:09:45 UTC

Thread safety

Hi,

I have an urgent question about thread safety in lucene,
from lucene doc and code I could not get a clear answer.

1. is Searcher (IndexSearcher, MultiSearcher ..) thread
    safe, can multi-users call search(..) method on the
    same object at the same time?

2. if on the same object, one user calls close( ) and
    another calls search(..), I assume we should have a
    meaningful error message?

3. what would happen if one user calls Searcher.search(..),
    but at the same time another user tries to delete that
    document from index files by calling IndexReader.delete(..)
    (either through two threads or two separate processes)?

A brief answer would be good enough for me now, thanks
very much in advance!

Lisheng

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


Re: Thread safety

Posted by Justin Swanhart <gr...@gmail.com>.
You can only have one open writer at a time.  A writer is either an
IndexWriter object, or an IndexReader object that has modified the
index, by deleting documents for instance.

You must close your existing writer before you open a new one.

You should not get lock exceptions with IndexSearchers.  The only time
the locks come into play is when you are trying to open a writer when
a writer process already has the lock, or the write process died w/out
removing the lock so you have a stale lock left behind.

I've run into FileNotFound exceptions on occasion, and have pretty
much pinned it down to modifying the index on a slow device (NFS) with
a very large index and trying to instantiate a new searcher.  I solved
the problem by catching the exception and trying to create the
searcher again.  That resolved the problem for me.


On Fri, 03 Dec 2004 08:58:41 +0100, sergiu gordea
<gs...@ifit.uni-klu.ac.at> wrote:
> Otis Gospodnetic wrote:
> 
> >1. yes
> >2. yes error, meaningful, it depends what you find meaningful :)
> >3. searcher will still find the document, unless you close it and
> >reopen it (searcher)
> >
> >
> ... What about LockException? I tried to index objects in a thread and
> to use a IndexSearcher
> to search objects, but I have had problems with this.
> I tried to create a new  IndexSearcher object if  the index version  was
> changed, but unfortunately
> I got some Lock Exceptions and FileNotFound Exceptions.
> 
>  If the answer number 3. is correct, then why did I get these exceptions.
> 
>  Sergiu
> 
> 
> 
> >Otis
> >
> >--- "Zhang, Lisheng" <Li...@broadvision.com> wrote:
> >
> >
> >
> >>Hi,
> >>
> >>I have an urgent question about thread safety in lucene,
> >>from lucene doc and code I could not get a clear answer.
> >>
> >>1. is Searcher (IndexSearcher, MultiSearcher ..) thread
> >>    safe, can multi-users call search(..) method on the
> >>    same object at the same time?
> >>
> >>2. if on the same object, one user calls close( ) and
> >>    another calls search(..), I assume we should have a
> >>    meaningful error message?
> >>
> >>3. what would happen if one user calls Searcher.search(..),
> >>    but at the same time another user tries to delete that
> >>    document from index files by calling IndexReader.delete(..)
> >>    (either through two threads or two separate processes)?
> >>
> >>A brief answer would be good enough for me now, thanks
> >>very much in advance!
> >>
> >>Lisheng
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> >>
> >>
> >>
> >>
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> 
>

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


Re: Thread safety

Posted by sergiu gordea <gs...@ifit.uni-klu.ac.at>.
Otis Gospodnetic wrote:

>1. yes
>2. yes error, meaningful, it depends what you find meaningful :)
>3. searcher will still find the document, unless you close it and
>reopen it (searcher)
>  
>
... What about LockException? I tried to index objects in a thread and 
to use a IndexSearcher
to search objects, but I have had problems with this.
I tried to create a new  IndexSearcher object if  the index version  was 
changed, but unfortunately
I got some Lock Exceptions and FileNotFound Exceptions.

 If the answer number 3. is correct, then why did I get these exceptions.

 Sergiu

>Otis
>
>--- "Zhang, Lisheng" <Li...@broadvision.com> wrote:
>
>  
>
>>Hi,
>>
>>I have an urgent question about thread safety in lucene,
>>from lucene doc and code I could not get a clear answer.
>>
>>1. is Searcher (IndexSearcher, MultiSearcher ..) thread
>>    safe, can multi-users call search(..) method on the
>>    same object at the same time?
>>
>>2. if on the same object, one user calls close( ) and
>>    another calls search(..), I assume we should have a
>>    meaningful error message?
>>
>>3. what would happen if one user calls Searcher.search(..),
>>    but at the same time another user tries to delete that
>>    document from index files by calling IndexReader.delete(..)
>>    (either through two threads or two separate processes)?
>>
>>A brief answer would be good enough for me now, thanks
>>very much in advance!
>>
>>Lisheng
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>>
>>
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>
>  
>


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


Re: Thread safety

Posted by Otis Gospodnetic <ot...@yahoo.com>.
1. yes
2. yes error, meaningful, it depends what you find meaningful :)
3. searcher will still find the document, unless you close it and
reopen it (searcher)

Otis

--- "Zhang, Lisheng" <Li...@broadvision.com> wrote:

> Hi,
> 
> I have an urgent question about thread safety in lucene,
> from lucene doc and code I could not get a clear answer.
> 
> 1. is Searcher (IndexSearcher, MultiSearcher ..) thread
>     safe, can multi-users call search(..) method on the
>     same object at the same time?
> 
> 2. if on the same object, one user calls close( ) and
>     another calls search(..), I assume we should have a
>     meaningful error message?
> 
> 3. what would happen if one user calls Searcher.search(..),
>     but at the same time another user tries to delete that
>     document from index files by calling IndexReader.delete(..)
>     (either through two threads or two separate processes)?
> 
> A brief answer would be good enough for me now, thanks
> very much in advance!
> 
> Lisheng
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> 
> 


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