[ 
https://issues.apache.org/jira/browse/LUCENENET-112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12581210#action_12581210
 ] 

Digy commented on LUCENENET-112:
--------------------------------

If an application crashes while an IndexWriter is open, it leaves the lock 
file(writer.lock) behind.
Re-running the application results in an "Lock obtain timeout" exception because
SimpleFSLock#Obtain method tries to create the lock file with FileMode 
"CreateNew" and gets an exception.


Since the Init method of the IndexWriter calls the "directory.ClearLock" at the 
beginning,
removing the lock file -left behind- in that method could be a simple thing, I 
thought.

But, since the SimpleFSLock#Obtain method closes the lock file immediately 
after the creation, removing it 
in "directory.ClearLock" can result in a second thread/process obtain the lock. 
So I moved the code
closing the lockFile ("createdFile") to the method SimpleFSLock#Release, so 
that, when a process wants to delete
the lock file it gets an exception if it is used by another thread/process(or 
removes safely if it is remainder
of a previous crash).


But, when running unit tests(Store/TestLockFactory) I hit the failure in 
"TestFSDirectoryTwoCreates"
Which creates two IndexWriters and hoping not to get an exception while 
creating the second one. 

Current version of Lucene.Net passes this test since SimpleFSLock#Obtain 
returns false(means: index is locked) 
if the lock file exists. Yes, this behaviour provides an exclusive lock but 
ignores the problem of a 
application crash.

As a result, after applying the patch -I think-, 
TestLockFactory#TestFSDirectoryTwoCreates method is not 
applicable to Lucene.Net and should be removed from the unit tests.


Any Comments?


PS: In the mean time, I removed some some redundant codes in 
SimpleFSLockFactory#ClearLock and 
SimpleFSLock#Obtain.


DIGY




> orphan IndexWriter locks
> ------------------------
>
>                 Key: LUCENENET-112
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-112
>             Project: Lucene.Net
>          Issue Type: Bug
>            Reporter: Digy
>         Attachments: SimpleFSLockFactory.patch, TestLockFactory.patch
>
>
> If an application crashes while an IndexWriter is open, it leaves the lock 
> file(writer.lock) behind. Re-running the application results in an "Lock 
> obtain timeout" exception.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to