0

我有以下问题:

我有一个分布式系统,在选择领导者时,我需要以一种或另一种方式达成共识。

我有一组players通过消息相互交流。为了让这些玩家从一个阶段进步到另一个阶段,必须有人跟踪他们的进步。目前,有两种类型的玩家:
leader---当他收到 N-1done条消息(针对N-1玩家)时,他负责向所有其他用户广播状态变化
follower---他负责获取领导者的消息并更新他的内部状态机。

每个玩家从 2 个管道接收消息:
- Status pipeline- 他接收一个类型数组, [user1,user2,user3...userN] 其中每个元素是在线用户。
- -Message pipeline基于推送的通知。追随者用户将在此处发布他们已准备好进行下一步的消息。领导者将跟踪DONE计数器,当达到阈值时,他将广播ADVANCE to next step

为了更好的主意,我附上了一张图片:

在此处输入图像描述

我不知道如何处理领导人连任。如果领导者断开连接(这可以通过超时实现),其他节点如何决定谁是下一个领导者,如果他们随机选择,当前领导者是否应该存储在数据库中?我的意思是他们只交换消息,服务器上没有任何东西,比如全局变量或其他东西。

4

1 回答 1

0

What you basically need is to implement both 2 phase commit and a leader election recipe. Now, either you can implement them on your own (2 phase commit is well documented, and yes, you would need a shared storage), or if you have the flexibility to use a distributed open source co-ordination service, zookeeper would be your best bet. Have a look at the below article on apache zookeeper's page where they discuss both the recipes which you need. Hope this helps.

https://zookeeper.apache.org/doc/current/recipes.html#sc_recipes_twoPhasedCommit

于 2018-08-28T22:14:45.240 回答