[ 
https://issues.apache.org/jira/browse/LUCENE-5738?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14019689#comment-14019689
 ] 

Uwe Schindler commented on LUCENE-5738:
---------------------------------------

Hi Simon,

looks good. Sorry for confusing responses. The issue is, as you say, the 
combination of 2 issues, of which one is a real bug in the JDK:
- 

About the patch:
I like it, much simplier than before Robert's cleanup. One small thing: In Java 
7 we should use IOUtils only if required, for the use case here (the finally 
block) we can use a cool "trick". The pros for doing it like that is, that no 
Exceptions may be supressed, the are recorded:

Replace:
{code:java}
} finally {
  if (obtained == false) { // not successful - clear up and move out
    clearMarkedLock(path);
    final FileChannel toClose = channel;
    channel = null;
    IOUtils.closeWhileHandlingException(toClose);
  }
}
{code}

by

{code:java}
} finally {
  if (obtained == false) { // not successful - clear up and move out
    try (FileChannel toClose = channel) {
      clearMarkedLock(path);
      channel = null;
    }
  }
}
{code}

I will look into the LockStressTest, but for now it looks fine.

You can run the stress tester for very long time using some system properties 
(like running it the whole night).

> 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
>
>         Attachments: LUCENE-5738.patch, LUCENE-5738.patch
>
>
> 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: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to