lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Björn Ekengren <bjorn.ekeng...@avanza.se>
Subject SOLVED: Lock obtain timed out
Date Thu, 27 Jul 2006 09:06:34 GMT
Thancks everybody for the feedback. I now rewrote my app like this:

        synchronized (searcher.getWriteLock()){ 
            IndexReader reader = searcher.getIndexSearcher().getIndexReader();
            try {
                reader.deleteDocuments(new Term("id",id));
                reader.close(); 
                IIndexer indexer = searcher.getIndexer();
                addedDocuments = indexer.addDocument(id); //creates and close writer
                reader = IndexReader.open(searcher.getIndexDir());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

Now there are write locks only during the short period the synchronized block runs. It gets
a lot of opening and closing of the reader and writer but I guess that is the way is has to
be.

/B

-----Original Message-----
From: karl wettin [mailto:karl.wettin@gmail.com]
Sent: den 27 juli 2006 09:25
To: java-user@lucene.apache.org
Subject: RE: Lock obtain timed out
Importance: Low


On Thu, 2006-07-27 at 08:59 +0200, Björn Ekengren wrote:
> > > When I close my application containing index writers the
> > > lock files are left in the temp directory causing an "Lock obtain
> > > timed out" error upon the next restart.
> > 
> > My guess is that you keep a writer open even though there is no activity
> > involving adding new documents. Unless I have a massive never ending
> > stream of new data arriving (many thousand per minute) I usually try not
> > to have an open writer. Opening, adding documents and closing the writer
> > in iterations.
> 
> The application I'm writing is a server that keeps a reader and a
> writer open at all time. I realized last nigth this will not work
> since they both need a lock (reader when deleting and writer when
> adding) so I need a workaround. 

No offense, but your current solution is not viable. What you need is to
rewrite the code that handles your index, not a workaround. Or you could
wait for the new deleteDocument method in IndexWriter. Not sure when
that will be around though.

> Is it possible to temporarily let the reader release the lock so that
> the writer can add a document or do I need to close it and open it
> again when writer is finished ?

You release the lock by closing the reader... It is also possible to
plain old skip the creating of locks using -DdisableLuceneLocks=true,
but that might cause many other problems for you.

You are aware that no document will be deleted from the index until you
close the reader? If you keep a reader open at all times just for
deleting documents and never close it, they will not be deleted.

If you need to update lots of documents in your corpus (delete and add)
then first delete the documents with the reader, close it and add them
again with the writer. And then close the writer when you are done. And
don't open it again until you need to add documents again.


---------------------------------------------------------------------
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


Mime
View raw message