Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my Lucene index getting locked?

I had an issue with my search not return the results I expect.

I tried to run Luke on my index, but it said it was locked and I needed to Force Unlock it (I'm not a Jedi/Sith though)

I tried to delete the index folder and run my recreate-indicies application but the folder was locked. Using unlocker I've found that there are about 100 entries of w3wp.exe (same PID, different Handle) with a lock on the index.

Whats going on?

I'm doing this in my NHibernate configuration:

c.SetListener(ListenerType.PostUpdate, new FullTextIndexEventListener());
c.SetListener(ListenerType.PostInsert, new FullTextIndexEventListener());
c.SetListener(ListenerType.PostDelete, new FullTextIndexEventListener());

And here is the only place i query the index:

var fullTextSession = NHibernate.Search.Search.CreateFullTextSession(this.unitOfWork.Session);

var fullTextQuery = fullTextSession.CreateFullTextQuery(query, typeof (Person));
fullTextQuery.SetMaxResults(100);

return fullTextQuery.List<Person>();

Whats going on? What am i doing wrong?

Thanks

like image 715
Andrew Bullock Avatar asked Jan 22 '23 12:01

Andrew Bullock


1 Answers

The Lucene.Net index only blocks concurrent write operations on the index. You can have as many threads as you like searching / reading from the index and they wont block - either on each other or on anyone doing a write, however if you have two threads doing a write on the index at the same time then there is a chance that one of them will block on the other.

If lucene tells you your index is locked then this means that either someone is currently writing to the index, or (this sounds more likely) something that was writing to the index was killed during writing and so couldn't remove the lock. You should make sure that you properly dispose of any Lucene objects that write to the index as soon as they are done.

To remove the lock manually there is a .lock file that you need to delete inside the Lucene directory (my big book of Lucene is not near me at the moment, so I don't know exactly where it is, but doing a search for "lock", or ".lock" in the Lucene directory should find it)

The handles that w3wp.exe had on this directory were probably the handles owned by the threads reading from the lucene index - although these will prevent you from deleting the directory, they shouldn't prevent you from searching or writing to the index.

like image 69
Justin Avatar answered May 10 '23 03:05

Justin