lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cheolgoo Kang <app...@gmail.com>
Subject Re: Concurrent read and write
Date Sun, 23 Jan 2005 14:50:59 GMT
Lucene's write lock is simple. There are four places that requires the
write lock.
Those are IndexReader.delete(int), IndexReader.setNorm(int,String,byte),
IndexReader.undeleteAll(), and IndexWriter.<init>. Once you've used
one of methods
above, you should close that IndexReader or IndexWriter instance to
release the write
lock (and to avoid the Lock-obtain-timed-out exception).

For example, the following sequence should be okay.
> IndexReader reader = IndexReader.open( DIR );
> reader.delete( new Term( "A", "B" ) );
> reader.close();
> IndexWriter writer = new IndexWriter( DIR, a, b );
> writer.add( oneDocument );
> writer.close();

But, a sequence following causes a "Lock obtain timed out" exception.
> IndexReader reader = IndexReader.open( DIR );
> reader.delete( new Term( "A", "B" ) );
> IndexWriter writer = new IndexWriter( DIR, a, b );

Because, the write lock obtained at IndexReader.delete() wouldn't be removed
by IndexReader.close() and "new IndexWriter()" sentence requires a write lock.


On Fri, 21 Jan 2005 08:20:12 -0800 (PST), Otis Gospodnetic
<otis_gospodnetic@yahoo.com> wrote:
> Hello Ashley,
> 
> You can read/search while modifying the index, but you have to ensure
> only one thread or only one process is modifying an index at any given
> time.  Both IndexReader and IndexWriter can be used to modify an index.
>  The former to delete Documents and the latter to add them.  You have
> to ensure these two operations don't overlap.
> c.f. http://www.lucenebook.com/search?query=concurrent
> 
> Otis
> 
> 
> --- Ashley Steigerwalt <asteigerwalt@mindbridge.com> wrote:
> 
> > I am a little fuzzy on the thread-safeness of Lucene, or maybe just
> > java.
> > From what I understand, and correct me if I'm wrong, Lucene takes
> > care of
> > concurrency issues and it is ok to run a query while writing to an
> > index.
> >
> > My question is, does this still hold true if the reader and writer
> > are being
> > executed as separate programs?  I have a cron job that will update
> > the index
> > periodically.  I also have a search application on a web form.  Is
> > this going
> > to cause trouble if someone runs a query while the indexer is
> > updating?
> >
> > Ashley
> >
> > ---------------------------------------------------------------------
> > 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
> 
> 


-- 
Cheolgoo, Kang

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


Mime
View raw message