How to elect a master node among the nodes running in a cluster?

别来无恙 提交于 2019-11-28 08:59:06

Leader election algorithms typically consider the split brain as a fault case to support. If you assume that it's not the nodes that fail but the networking, you may run into the case where all nodes are up, but fail to talk to each other. Then, you may end up with two masters.

If you can exclude "split brain" from your fault model (i.e. if you consider only node failures), your algorithm (leader is the one with the smallest address) is fine.

Spike Gronim

Use Apache ZooKeeper. It solves exactly this problem (and many more).

If your nodes also need to agree on things and their total order, you might want to consider Paxos. It's complicated, but nobody's come up with an easier solution for distributed consensus.

Me like this algorithm:

  • Each node calculates the lowest known node id and sends a vote for leadership to this node
  • If a node receives sufficiently many votes and the node also voted for itself, then it takes on the role of leader and starts publishing cluster state.

and at link below have some many algorithm of election master-node in cluster: https://www.elastic.co/blog/found-leader-election-in-general#the-zen-way

Also can see Raft-algorithm: https://raft.github.io

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!