Ok Mike, opened https://issues.apache.org/jira/browse/LUCENE-2104. I'll figure how to reproduce this in a JUnit test, and then fix it.
Shai On Wed, Dec 2, 2009 at 5:28 PM, Michael McCandless < luc...@mikemccandless.com> wrote: > Sneaky! Can you open a bug? > > Mike > > On Wed, Dec 2, 2009 at 10:23 AM, Shai Erera <ser...@gmail.com> wrote: > > It seems that only NativeFSLock has a problem here. The rest either > attempt > > to delete the file or do something else. Only NativeFSLock does not do > > anything, if its 'lock' instance in null. Which will always be the case, > > because NativeFSLockFactory.makeLock always returns a new NativeFSLock. > So > > unless someone calls obtain(), the nothing will happen upon calling > > release(). > > > > Shai > > > > On Wed, Dec 2, 2009 at 4:51 PM, Shai Erera <ser...@gmail.com> wrote: > >> > >> Hi > >> > >> Not sure if I'm using it right, so apologize in advance if I posted to > the > >> wrong list. I tried to use IndexWriter.unlock, as according to my > >> understanding, it should unlock a directory if it's locked, and that's > by > >> deleting the lock file. But it doesn't work. Here's a short test: > >> > >> Directory dir = FSDirectory.open(indexDir, new > >> NativeFSLockFactory(indexDir)); > >> try { > >> new IndexWriter(dir, null, MaxFieldLength.UNLIMITED); > >> } catch (Exception e) { > >> IndexWriter.unlock(dir); > >> new IndexWriter(dir, null, MaxFieldLength.UNLIMITED); > >> } > >> > >> I run it two times in debug mode. The first, I stop after the first new > >> IndexWriter(), so the lock is kept held. The second time I run this, I > reach > >> the Exception clause (as expected), but then even after I invoke > unlock(), I > >> get the exception: > >> > >> Exception in thread "main" > >> org.apache.lucene.store.LockObtainFailedException: Lock obtain timed > out: > >> NativeFSLock@<dir>\write.lock > >> at org.apache.lucene.store.Lock.obtain(Lock.java:84) > >> at org.apache.lucene.index.IndexWriter.init(IndexWriter.java:1044) > >> at org.apache.lucene.index.IndexWriter.init(IndexWriter.java:1019) > >> at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:890) > >> at JustTest.main(JustTest.java:25) --> that's the line of the new > >> IndexWriter inside the catch clause > >> > >> So first, what IndexWriter.unlock does is call directory.makeLock() and > >> then release. But NativeFSLock's release() does not do anything, because > the > >> lock wasn't obtained yet. I think unlock() should have: > >> Lock l = dir.makeLock(indexDir); > >> l.obtain(); > >> l.release(); > >> > >> That way, unlock() would have notified a failure, which is IMO the right > >> behavior here. If no one uses the index, opening a new IndexWriter, even > if > >> the lock exists, will succeed, so no need to call unlock() at all. Which > >> brings the question what's the use of unlock(), unless it will fail > loudly > >> if it does not succeed to delete the lock. > >> > >> Shai > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org > For additional commands, e-mail: java-dev-h...@lucene.apache.org > >