[
https://issues.apache.org/jira/browse/LUCENE-5738?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14019659#comment-14019659
]
Simon Willnauer commented on LUCENE-5738:
-----------------------------------------
bq. It is waht is happening. The close() of the file handle is releasing the
lock of the other file handle in the same process. This has nothing to do with
the problem of the lock aquire failing, its just whats documented. So a single
process should never try to aquire the lock multiple times through filesystem.
We should only use the native lock between processes, for the single process
case we should use the map.
no you are not reading it right... what I am saying is that:
* obtain lock
* try again from same process, (this fails & closes the channel & release the
nativ lock on the FS)
* try again from same process (this fails again while another process can
succeed)
this is a problem here since it seems that the JVM prevents itself from
obtaining it twice. That is what I am arguing about and we can't detect this
with a unittest in a single process.
> NativeLock is release if Lock is closed after obtain failed
> -----------------------------------------------------------
>
> Key: LUCENE-5738
> URL: https://issues.apache.org/jira/browse/LUCENE-5738
> Project: Lucene - Core
> Issue Type: Bug
> Affects Versions: 4.8.1
> Reporter: Simon Willnauer
> Assignee: Simon Willnauer
> Fix For: 4.9, 5.0
>
>
> if you obtain the NativeFSLock and try to obtain it again in the same JVM and
> close if if it fails another process will be able to obtain it. This is
> pretty trappy though. If you execute the main class twice the problem becomes
> pretty obvious.
> {noformat}
> import org.apache.lucene.store.Lock;
> import org.apache.lucene.store.NativeFSLockFactory;
> import java.io.File;
> import java.io.IOException;
> public class TestLock {
> public static void main(String[] foo) throws IOException,
> InterruptedException {
> NativeFSLockFactory lockFactory = new NativeFSLockFactory(new
> File("/tmp"));
> Lock lock = lockFactory.makeLock("LOCK");
> if (lock.obtain()) {
> System.out.println("OBTAINED");
> } else {
> lock.close();
> System.out.println("FAILED");
> }
> // try it again and close it if it fails
> lock = lockFactory.makeLock("LOCK"); // <<<<==== this is a new lock
> if (lock.obtain()) {
> System.out.println("OBTAINED AGAIN");
> } else {
> lock.close(); // <<<<==== this releases the lock we obtained
> System.out.println("FAILED on Second");
> }
> Thread.sleep(Integer.MAX_VALUE);
> }
> }
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.2#6252)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]