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
<[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
Cheolgoo, Kang

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to