Categories
Java

The Lucene Lock

After putting together my application with Lucene I was sad to stubmle across the following error that occurred whenever I attempted to get a Lucene indexing going:

Lock obtain timed out: Lock@C:\WINDOWS\TEMP\lucene

Lucene puts a file lock on its index or tries to obtain it prior to making any operation as means of mutual exclusion.

The Lucene documentation also mentions that the place where Lucene uses as temporary directory is the system temporary directory or Tomcat’s temp directory
and as means to modify that temporary directory, one can change System properties.

So I went ahead and set a new timeout value and tried to also change the lock directory using:

Properties p = new Properties(System.getProperties());
p.setProperty("org.apache.lucene.lockDir", context.getInitParameter("LUCENE_INDEX_DIR")); // where I wanted the lock to go
p.setProperty("org.apache.lucene.writeLockTimeout", "60000");
p.setProperty("org.apache.lucene.commitLockTimeout", "60000");

The timouts took effect, but the lock, well, it still went where it was (and contrary to the aforementioned resource’s advice) – the system tempdirectory – C:/Windows/Temp in my case.

I finally arrived at this message board posting that pretty much suggested finding a lock file and deleting it. It worked.

Conclusion: if you get the aforementioned error – Lock obtain timed out: – go to the directory mentioned in the exception, and delete the file there called lucene...

Hope this helped.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

 

Share