views:

312

answers:

3

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

+1  A: 

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.

Kragen
Great, thanks for the explanation :) The part thats doing the writing is the NH.Search FullTextIndexEventListener, are you saying its likely that this is not threadsafe and two writes are occuring at the same time and one is getting blocked and then not properly disposed?
Andrew Bullock
hmmm looking at the source it does appear to take threading into account (doesn't mean its bug free). Any suggestions on how I can debug this? I don't see any reason (in my code) for an index write to fail
Andrew Bullock
A: 

Delete "write.lock" file in the index folder.

Mikos
the question is "why is it getting locked?" not, "tell me an arbitrary, manual solution"
Andrew Bullock
Check for any write operations. As @Kragen mentioned, it is more likely, your index write operation terminated and left the write.lock file. I would start with deleting write.lock and see if it gets recreated; if so, then I would look for processes that access the index.
Mikos