This is the code mentioned on kazoo readthedocs
election=zk.Election("/electionpath", "my-identifier")
what are the input arguments to be passed to make particular node as leader? (i.e what does /electionpath and my-identifier refers here?)
This is the code mentioned on kazoo readthedocs
election=zk.Election("/electionpath", "my-identifier")
what are the input arguments to be passed to make particular node as leader? (i.e what does /electionpath and my-identifier refers here?)
In Short: "/electionpath" is your path of interest where you will be creating nodes, adding data and watching nodes using dataWatchers. "my-identifier" is identifier to the non re-entrant lock which will be used to verify who is the leader out of the contenders and allow writes only to leader.
In Detail: To simplify it explaining first why there should be leader in zookeeper. It is the leader who does all the write operations and connection related handling. Consider following example to understand concept of leader election.
In [1]: zk_client.create('test_zk/path_of_interest/test_ephemeral', ephemeral=True)
In [9]: zk_client.get("test_zk/path_of_interest/test_ephemeral")
Out [9]: ('',ZnodeStat(czxid=678608988239, mzxid=687195015354, ctime=1476960597584, mtime=1477310417594, version=1145, cversion=0, aversion=0, ephemeralOwner=0, dataLength=185, numChildren=0, pzxid=678608988239))
The node with the smallest creation id(czxid) will be elected as leader post leader election process.
Leader election internally gives a non re-entrant lock to elected node(smallest czxid) and sets some identifier to that lock which will be used to verify who is the leader out of the contenders(your "my-identifier").
Now let's see actual code to elect leader.
In [7]: election = zk_client.Election('/test_zk/path_of_interest', 'test-election')
In [8]: def leader_func():
...: print 'Election Completed...!'
...:
In [9]: election.run(leader_func)
Election Completed...!
A callable is passed to run method to do some post election stuff.
I hope this helps.