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

ASF GitHub Bot commented on CURATOR-171:
----------------------------------------

GitHub user oza opened a pull request:

    https://github.com/apache/curator/pull/195

    [CURATOR-171] LeaderLatch isn't aware if it's own ephemeral node goes away

    The root cause of the problem reported on CURATOR-171 is that LeaderLatch 
is not aware of losing self znode after acquire lock. This PR fixes that 
LeaderLatch is aware of my znode losing and marking itself "not leader".

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/oza/curator CURATOR-171

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/curator/pull/195.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #195
    
----
commit 3d9aed6a71a7bf59299a0b50f4469d200c29d01c
Author: Tsuyoshi Ozawa <[email protected]>
Date:   2017-01-12T09:24:19Z

    CURATOR-171 - LeaderLatch isn't aware if it's own ephemeral node goes away

----


> LeaderLatch isn't aware if it's own ephemeral node goes away
> ------------------------------------------------------------
>
>                 Key: CURATOR-171
>                 URL: https://issues.apache.org/jira/browse/CURATOR-171
>             Project: Apache Curator
>          Issue Type: Bug
>          Components: Recipes
>            Reporter: John Vines
>
> Running the following code- {code}  public static void main(String args[]) 
> throws Exception {
>     CuratorFramework curator = 
> CuratorFrameworkFactory.builder().connectString("localhost:2181").retryPolicy(new
>  ExponentialBackoffRetry(1000, 5))
>         .authorization("digest", "accumulo:DEFAULT".getBytes()).build();
>     curator.start();
>     LeaderLatch latch = new LeaderLatch(curator, "/latch", "test");
>     LeaderLatch latch2 = new LeaderLatch(curator, "/latch", "test2");
>     latch.addListener(new LeaderLatchListener() {
>       @Override
>       public void isLeader() {
>         System.out.println("Became leader!");
>       }
>       @Override
>       public void notLeader() {
>         System.out.println("Lost leadership!");
>       }
>     });
>     latch.start();
>     latch.await();
>     latch2.start();
>     Thread.sleep(1000);
>     System.out.println("Does latch1 have leadership? " + 
> latch.hasLeadership());
>     System.out.println("Does latch2 have leadership? " + 
> latch2.hasLeadership());
>     for (String child : curator.getChildren().forPath("/latch"))
>       if (Arrays.equals(curator.getData().forPath(ZKPaths.makePath("/latch", 
> child)), "test".getBytes()))
>           
> curator.delete().deletingChildrenIfNeeded().forPath(ZKPaths.makePath("/latch",
>  child));
>     Thread.sleep(1000);
>     System.out.println("Does latch1 have leadership? " + 
> latch.hasLeadership());
>     System.out.println("Does latch2 have leadership? " + 
> latch2.hasLeadership());
>     
>     Thread.sleep(1000 * 40);
>     System.out.println("Does latch1 have leadership? " + 
> latch.hasLeadership());
>     System.out.println("Does latch2 have leadership? " + 
> latch2.hasLeadership());
>     
>     latch.close();
>     latch2.close();
>     curator.close();
>   }{code}
> I get the following output-{noformat}Became leader!
> Does latch1 have leadership? true
> Does latch2 have leadership? false
> Does latch1 have leadership? true
> Does latch2 have leadership? true
> Does latch1 have leadership? true
> Does latch2 have leadership? true
> {noformat}
> I expect that when the ephemeral node is deleted, latch1 no longer reports 
> itself as having leadership. Furthermore, I expect it to trigger the 
> notLeader call.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to