简体   繁体   中英

getting current leader of election recipe in kazoo

I am able to get current contenders using election.lock._get_sorted_children() and respective identifiers using election.lock.contenders() . But election.lock.contenders() also sorts the list, so will election.lock.contenders()[0] always be the leader?

Note, election = zk.Election("/path", "uuid") where zk is the KazooClient

Is there any better way to verify the leader?

Kazoo follows zookepeers recommendation that the node with smallest index should acquire the lock. The Lock::_inner_acquire ensures that the lock is acquired by the smallest index, by always waiting for predecessors to finish before acquiring lock. Hence, election.lock.contenders()[0] will always be the leader (unless the list is empty of-course).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM