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

ASF GitHub Bot commented on TWILL-129:
--------------------------------------

Github user chtyim commented on a diff in the pull request:

    https://github.com/apache/incubator-twill/pull/34#discussion_r30922444
  
    --- Diff: 
twill-zookeeper/src/test/java/org/apache/twill/internal/zookeeper/LeaderElectionTest.java
 ---
    @@ -278,6 +279,54 @@ public void follower() {
         }
       }
     
    +  @Test
    +  public void testRace() throws InterruptedException {
    +    ExecutorService executor = Executors.newFixedThreadPool(2);
    +    final AtomicInteger leaderCount = new AtomicInteger(0);
    +    final CountDownLatch completeLatch = new CountDownLatch(2);
    +
    +    // Starts two threads and try to compete for leader and immediate drop 
leadership.
    +    // This is to test the case when a follower tries to watch for leader 
node, but the leader is already gone
    +    for (int i = 0; i < 2; i++) {
    +      final ZKClientService zkClient = 
ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
    +      zkClient.startAndWait();
    +      executor.execute(new Runnable() {
    +        @Override
    +        public void run() {
    +          try {
    +            for (int i = 0; i < 1000; i++) {
    +              final CountDownLatch leaderLatch = new CountDownLatch(1);
    --- End diff --
    
    it's for making the thread blocked until it becomes leader so that the test 
will fail with timeout if the race happened.


> Race condition in leader election if leader quitted before follower set the 
> watch
> ---------------------------------------------------------------------------------
>
>                 Key: TWILL-129
>                 URL: https://issues.apache.org/jira/browse/TWILL-129
>             Project: Apache Twill
>          Issue Type: Bug
>          Components: zookeeper
>    Affects Versions: 0.4.0-incubating, 0.5.0-incubating, 0.4.1-incubating
>            Reporter: Terence Yim
>            Assignee: Terence Yim
>            Priority: Blocker
>
> In the LeaderElection implementation, if the leader quit and delete its node 
> before the next-in-line follower try to set the watch through the exists() 
> call, the follower will fail silently without noticing the leader node is 
> gone.



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

Reply via email to