curator-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arie Zilberstein <>
Subject LeaderSelector edge case - preventing timely leadership withdrawal
Date Mon, 09 Sep 2013 15:32:47 GMT

I'm fairly new with Zookeeper and Curator. I want to achieve a simple
leader election process.
But, I ran into trouble implementing the interruption behavior. I could not
find a reliable way to stop the leader (withdraw from leadership).
I think even the schoolbook example that Curator brings is flawed.
In leader.ExampleClient:

    public void stateChanged(CuratorFramework client, ConnectionState
        // you MUST handle connection state changes. This WILL happen in
production code.

        if ( (newState == ConnectionState.LOST) || (newState ==
ConnectionState.SUSPENDED) )
            if ( ourThread != null )

So in case of lost leadership, the ourThread thread is interrupted.
However, ourThread is set in the 2nd line of the takeLeadership() method.
Until then, it is null.

What happens if the connection is lost immediately after it is established,
and ourThread stays null? Won't it be the case that the thread will go on,
thinking that it is the leader, despite it being supposed to withdraw?


View raw message