The indexing process is totally synchronized in our system. Thus if an Indexing thread starts up and the index exists, but is locked, I know this to be the only indexing processing running so the lock must be from a process that got stopped before it could finish.
So right before I begin writing to the index I have this check: //if we have gotten to here that this is the only index running. //the index should not be locked. if it is, the lock is "stale" //and must be released before we can continue try { if (index.exists() && IndexReader.isLocked(indexFileLocation)) { Trace.ERROR("INDEX INFO: Had to clear a stale index lock"); IndexReader.unlock(FSDirectory.getDirectory(index, false)); } } catch (IOException e3) { Trace.ERROR("INDEX ERROR: Was unable to clear a stale index lock: " + e3); } Luke ----- Original Message ----- From: "Claes Holmerson" <[EMAIL PROTECTED]> To: "Lucene Users List" <lucene-user@jakarta.apache.org> Sent: Thursday, February 03, 2005 12:02 PM Subject: Lock failure recovery > Hello > > A commit.lock can get left by a process that dies in the middle of > reading the index, for example because of an OutOfMemoryError. How can I > handle such a left lock gracefully the next time the process runs? > Checking if there is a lock is straight forward - but how can I be sure > that it is not just a current lock created by another thread? The only > methods I find to deal with the lock is IndexReader.isLocked() and > IndexReader.unlock(). I would like to know the lock age - if it is older > than a certain age then I can remove it. How do other people deal with > left over locks? > > Claes > -- > > Claes Holmerson > Polopoly - Cultivating the information garden > Kungsgatan 88, SE-112 27 Stockholm, SWEDEN > Direct: +46 8 506 782 59 > Mobile: +46 704 47 82 59 > Fax: +46 8 506 782 51 > [EMAIL PROTECTED], http://www.polopoly.com > > > --------------------------------------------------------------------- > 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]