A few things:

What is RetryLoopExecutor? Curator does all retries internally. You should not 
have your own retry mechanism.
Calling blockUntilConnectedOrTimedOut() is unnecessary. Curator does this 
internally already.
What do you do with the "isConnected" value? That seems suspicious to me.
You do not get LOST until the session expires. How long is 
"coordinatorSessionTimeout"? You won't receive LOST until that has elapsed.

Other than that, I'd need to see the code for handleConnectionStateChange(), 
handleTakeSingletonRole() and RetryLoopExecutor. Also, the logs from the 
instance that doesn't get LOST would be helpful.

-Jordan

> On Feb 26, 2020, at 9:46 AM, Arpit Jain <jain.arp...@gmail.com> wrote:
> 
> Here is the setup I have :
> 
> 2 application instances using Curator (4.2.0) connected to Zookeeper (3.5.6) 
> running docker for leader election/locks/service discovery. The way I create 
> curator instance is below:
>         final CuratorFramework curatorFramework =
>             CuratorFrameworkFactory.newClient(coordinatorHosts, 
> coordinatorSessionTimeout, coordinatorConnectionTimeout, retryPolicy);
> 
>         curatorFramework.getConnectionStateListenable()
>             .addListener((client, newState) -> LOGGER.warn("ZOOKEEPER STATE 
> CHANGED TO : {}", newState));
> 
>          isConnected = RetryLoopExecutor.execute(curatorFramework, () -> {
>                    curatorFramework.start();
>                 
> curatorFramework.getZookeeperClient().blockUntilConnectedOrTimedOut();
>                 return curatorFramework.getZookeeperClient().isConnected();
> 
>          });
> 
> The Leader selection is done using below method:
> 
>     public void createSingletonServerSelector() throws Exception {
> 
>         if (_logger.isInfoEnabled()) {
>             _logger.info("Initializing SingletonServerSelector on Coordinator 
> ZNode [" + coordinatorZnode + "].");
>         }
>         _singletonServerSelector = new LeaderSelector(curatorFramework, 
> coordinatorZnode, new LeaderSelectorListener() {
> 
>             @Override
>             public final void stateChanged(final CuratorFramework client, 
> final ConnectionState newState) {
>                 handleConnectionStateChange(newState);
>             }
> 
>             @Override
>             public final void takeLeadership(final CuratorFramework client) 
> throws Exception {
>                 handleTakeSingletonRole();
>             }
>         });
>         _singletonServerSelector.setId(coordinatorID);
> 
>         _logger.info("SingletonServerSelector initialized.");
> 
>         _singletonServerSelector.autoRequeue();
> 
>         RetryLoopExecutor.execute(curatorFramework, () -> {
>             _singletonServerSelector.start();
>             return null; 
>         });
> 
>     }
> 
> Once I stop the Zookeeper container, I am getting LOST message in 
> "stateChanged" method above and I am shutting down my application in 
> "handleConnectionStateChange" method. But only weird thing is I don't get 
> "ZOOKEEPER STATE CHANGED TO : LOST" every time which I am printing in the 
> listener above.
> 
> I know this might still not be enough to diagnose the issue but I am not sure 
> what else code I can post. Its not critical for our application because we 
> are just printing log message in listener and LOST message is received.
> 
> Thanks
> 
> 
> On Wed, Feb 26, 2020 at 2:26 PM Jordan Zimmerman <jor...@jordanzimmerman.com 
> <mailto:jor...@jordanzimmerman.com>> wrote:
> Hi,
> 
> You sent two lines of code. I don't know how I'm supposed to help you with 
> just that. I have no information. 
> 
> -Jordan
> 
> > On Feb 26, 2020, at 9:25 AM, Arpit Jain <jain.arp...@gmail.com 
> > <mailto:jain.arp...@gmail.com>> wrote:
> > 
> > HI Jordan,
> > 
> > I am not sure what or how to provide the test case. Could you elaborate on 
> > how I can provide you the test case/scenario ?
> > 
> > Thanks
> 

Reply via email to