Login | Register
My pages Projects Community openCollabNet

Discussions > dev > Stale Lucene lock files and error handling

eyebrowse
Discussion topic

Back to topic list

Stale Lucene lock files and error handling

Reply

Author Daniel Rall <dlr at collab dot net>
Full name Daniel Rall <dlr at collab dot net>
Date 2003-04-15 11:16:08 PDT
Message On archives.apache.org, I often see stray Lucene lock files which
prevent indexing. The error messages go something like "Index locked
for write: Lock@/.../write.lock" (where "..." is the full path to the
index's lock file). I'm not sure under exactly what circumstances
this problem occurs, but did see a couple places where we might be
able to better handle the Lucene cursors used by Eyebrowse. Initial
examination of the Lucene source code shows that IndexWriter's
constructor and IndexReader's delete(int) method will throw this
error, and that IndexReader interacts with "write.lock" in other
places as well. Though we aren't (yet) using the latter, the former
is a place where we have some room for improvement.

The code in IndexWriter's constructor goes something like this:

    Lock writeLock = directory.makeLock("​write.lock");
    if (!writeLock.obtain()) // obtain write lock
      throw new IOException("Index locked for write: " + writeLock);

Here are some possible improvements for discussion:

* src/java/org/tigris/​eyebrowse/LuceneInde​xer.java
  Added more @see tags to header JavaDoc.

  

Index: LuceneIndexer.java
====================​====================​====================​=======
RCS file: /cvs/eyebrowse/src/j​ava/org/tigris/eyebr​owse/LuceneIndexer.j​ava,v
retrieving revision 1.17
diff -u -r1.17 LuceneIndexer.java
--- LuceneIndexer.java 6 Jan 2003 15:16:20 -0000 1.17
+++ LuceneIndexer.java 15 Apr 2003 18:01:42 -0000
@@ -56,6 +56,9 @@
  * @author Brian Goetz - Quiotix Corp
  * @since 1.0
  * @see IIndexer
+ * @see IIndexCreator
+ * @see IIndexSearcher
+ * @see IIndexMessageRemover
  */
 public class LuceneIndexer
     implements IIndexWriter, IIndexCreator, IIndexSearcher, IIndexMessageRemover
@@ -63,7 +66,8 @@
   private String filePath = null;
   private Searcher searcher = null;
   private IndexWriter writer = null;
- private IndexReader reader = null;
+ // Haven't yet started using our IndexReader reference.
+ //private IndexReader reader = null;
   private int docsAdded = 0;
 
   // This means: we only care about text parts, and we prefer plain text
@@ -92,14 +96,34 @@
    * @see IIndexCreator
    */
   public void createIndex() throws IndexerException {
+ // A temporary IndexWriter reference is used to avoid confusing
+ // creation with other indexing semantics.
+ IOException creationErr = null;
+ IndexWriter iw = null;
     try {
- IndexWriter iw = new IndexWriter(filePath, createAnalyzer(), true);
- iw.close();
+ iw = new IndexWriter(filePath, createAnalyzer(), true);
     }
     catch (IOException e) {
+ creationErr = e;
       throw new IndexerException("Error creating index " + filePath, e);
- };
- };
+ }
+ finally {
+ if (iw != null) {
+ // Make a best effort to close the IndexWriter before
+ // reporting any index creation problems.
+ try {
+ iw.close();
+ }
+ catch (IOException e) {
+ // Creation problems will be reported by the exception
+ // handling in the previous catch block.
+ if (creationErr == null)
+ throw new IndexerException("Error closing index " + filePath
+ + " after initial creation", e);
+ }
+ }
+ }
+ }
 
   /**
    * Constructor for LuceneIndexer class. The filePath argument
@@ -242,21 +266,25 @@
   public void close() throws IndexerException {
     try {
       if (writer != null) {
- if (docsAdded > 0)
- writer.optimize();
- writer.close();
- };
+ try {
+ if (docsAdded > 0)
+ writer.optimize();
+ }
+ finally {
+ writer.close();
+ }
+ }
       if (searcher != null)
         searcher.close();
     }
     catch (IOException e) {
- throw new IndexerException("Exception thrown while closing index", e);
+ throw new IndexerException("Error closing index", e);
     }
     finally {
- writer = null;
       searcher = null;
- };
- };
+ writer = null;
+ }
+ }
 
   /**
    * Creates a new instance of the type of <code>Analyzer​</code> used by

--------------------​--------------------​--------------------​---------
To unsubscribe, e-mail: dev-unsubscribe@eyeb​rowse.tigris.org
For additional commands, e-mail: dev-help at eyebrowse dot tigris dot org

« Previous message in topic | 1 of 4 | Next message in topic »

Messages

Show all messages in topic

Stale Lucene lock files and error handling Daniel Rall <dlr at collab dot net> Daniel Rall <dlr at collab dot net> 2003-04-15 11:16:08 PDT
     Re: Stale Lucene lock files and error handling Andreas Guenther <aguenther at collab dot net> Andreas Guenther <aguenther at collab dot net> 2003-04-15 12:44:44 PDT
         Re: Stale Lucene lock files and error handling edk Ed Korthof 2003-04-15 15:48:00 PDT
             Re: Stale Lucene lock files and error handling Andreas Guenther <aguenther at collab dot net> Andreas Guenther <aguenther at collab dot net> 2003-04-15 16:07:43 PDT
Messages per page: