lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Umesh Prasad <umesh.i...@gmail.com>
Subject Re: Concurrent Issue
Date Fri, 08 Apr 2011 05:33:09 GMT
Building on Aditya's comments.

1. Lucene in Action has a SearchManager class which does most of 1-5 and
manages indexreaders.
2. Reference counting is not the best approach, it is too low level and
error prone. Instead
  Use ReadWriteLock
<http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/locks/ReentrantReadWriteLock.html>manage
index ( or do reference counting for u)

A ReadWriteLock maintains a pair of associated
locks<http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/locks/Lock.html>,
one for read-only operations and one for writing. The read
lock<http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/locks/ReadWriteLock.html#readLock%28%29>may
be held simultaneously by multiple reader threads, so long as there
are
no writers. The write
lock<http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/locks/ReadWriteLock.html#writeLock%28%29>is
exclusive.

So basically, you wrap the lucene's searcher into your SearchManager class,
which exposes its own API for search and forwards the requests to underlying
searcher.

 The search and reopen will sync up by using ReadWriteLock . search takes
readlock and reopen takes writelock and that will take care of any open
search results etc.

PS:  To speed up the reopening of index use indexreader.reopen() instead of
closing it off and then open again. It is much faster. (Documented)
Thanks & Regards
Umesh Prasad

On Thu, Apr 7, 2011 at 11:38 AM, findbestopensource <
findbestopensource@gmail.com> wrote:

> You are trying to access the reader which is already closed by some other
> thread.
>
> 1. Keep a reference count for the reader you create.
> 2. Have a common function through which all functions will retrieve Reader
> objects
> 3. Once the index got changed, create a new reader, do warmup
> 4. When the new reader is ready then the common function should return this
> for furture request and old reader should go in passive mode.
> 5. The old reader should be closed when the reference count is zero.
>
>


> Regards
> Aditya
> www.findbestopensource.com
>
>
> On Wed, Apr 6, 2011 at 7:20 PM, Piotr Pezik <piotr.pezik@gmail.com> wrote:
>
> > Only to second this explanation.
> >
> > I got the same exception in a web application with a single IndexReader,
> > accessed by many threads.
> >
> > The index gets updated every half hour or so, so I closed the old
> > IndexReader and opened a new one every now and then.
> >
> > Even though the method for obtaining the IndexReader was synchronized,
> with
> > tens of thousands of queries a day,
> > I started getting the AlreadyClosed exception when one thread triggered
> the
> > closure of the IndexReader which another thread was still using.
> >
> >
> >
> > Piotr
> >
> >
> > On 5 Apr 2011, at 15:46, Ian Lea wrote:
> >
> > > You don't say exactly how you are dealing with the concurrent access
> > > (one shared Reader/Searcher? Each user with own Reader/Searcher?
> > > Something else?) but the underlying problem is that the reader has
> > > been closed while something else is still using it.  This can easily
> > > happen in a multi-threaded setup: thread A might close the reader
> > > while thread B is still using it.
> > >
> > > Options include
> > >
> > > not closing the old reader straight away when open a new one, but
> > > instead stash it somewhere and close it later when you can be
> > > confident nothing else will be using it.
> > >
> > > using the SearcherManager class from Lucene In Action 2nd edition, or
> > > an equivalent.
> > >
> > > catching the AlreadyClosed exception and restarting the search with a
> > > current reader
> > >
> > >
> > > --
> > > Ian.
> > >
> > >
> > > On Tue, Apr 5, 2011 at 12:56 PM, Yogesh Dabhi <ydabhi@asite.com>
> wrote:
> > >> Hi
> > >>
> > >>
> > >>
> > >> My application is cluster in jobss application servers & lucene
> > >> directory was shared.
> > >>
> > >>
> > >>
> > >> Concurrently 5 user access same lucene directory for searching
> document
> > >>
> > >> That time I got bellow exception
> > >>
> > >> org.apache.lucene.store.AlreadyClosedException: this IndexReader is
> > >> closed
> > >>
> > >>
> > >>
> > >> is there a way to handle such error
> > >>
> > >>
> > >>
> > >> Thanks & Regards
> > >>
> > >> Yogesh
> > >>
> > >>
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > > For additional commands, e-mail: java-user-help@lucene.apache.org
> > >
> >
> >
>



-- 
---
Thanks & Regards
Umesh Prasad

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message