Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception when updating Lucene index

Am a newbie to Lucene search API. I keep getting following exception when updating Lucene index...why do i get this error and how do i avoid it?

System.IO.IOException: Lock obtain timed out: SimpleFSLock@C:\Indexes\write.lock
   at Lucene.Net.Store.Lock.Obtain(Int64 lockWaitTimeout)
   at Lucene.Net.Index.IndexWriter.Init(Directory d, Analyzer a, Boolean create, Boolean closeDir)
   at Lucene.Net.Index.IndexWriter.Init(String path, Analyzer a, Boolean create)
   at Lucene.Net.Index.IndexWriter..ctor(String path, Analyzer a, Boolean create)

Thanks for reading.

like image 535
Steve Chapman Avatar asked Dec 17 '22 08:12

Steve Chapman


2 Answers

Lucene creates lock file when the index is opened in write mode. This lock file is removed when you cleanly close the index. While writing the index, if the program exits without closing the lucene IndexWriter, you will get this exception next time when you try to write to it. If you remove the lock file from the index directory, you will not see this exception.

You can choose to disable the locking with FSDirectory.setDisableLocks(false) but that is not advisable as the errors are being ignored silently.

like image 55
Shashikant Kore Avatar answered Dec 27 '22 07:12

Shashikant Kore


I think you can also get this error if an index write takes longer than the timeout value and another index write comes along after the lock expires and before the index write finishes - at least it seemed like that was what was happening.

I started having that same problem when I started approaching 50% or so of the maximum number of files in a single Windows directory. This slowed writes down enough to cause the problem. (Win2k3)

I believe that you can recompile Lucene to change the timeout value.

like image 39
R Ubben Avatar answered Dec 27 '22 07:12

R Ubben