* What algorithms there are for doing failover in a distributed system?
可能不是算法,而是系统。您需要围绕所提出的问题设计架构。
* What algorithms there are for consensus in a distributed system?
你可能希望实现 Paxos。实现简单 Paxos 并不太难。如果你想要让它更加鲁棒,请阅读 Google 的“Paxos Made Live”论文。如果你希望让它高性能,请看 Multi-Paxos。
* How should the nodes in the cluster determine that a node is down?
这要看情况。心跳检测实际上是一种相当不错的方法。问题是你会出现假阳性,但这种情况有点不可避免,而且在同一局域网上、负载可控的集群中,它们是准确的。Paxos 算法的好处是可以自动处理假阳性。然而,如果你需要针对其他目的获取故障信息,则需要确保即使检测到一个节点失败,但它实际上只是负载较高,需要时间来响应心跳。
* How should the nodes determine that what database entries had their master copy on the failed node at the time of failure, so that other nodes may recover those entries?
* How to decide that which node(s) has the latest secondary copy of some entry?
* How to decide that which node's secondary copy should be promoted to be the new master copy?
我认为你可以从阅读Google File System的论文中获益匪浅。在GFS中,有一个专用的主节点来跟踪哪个节点有哪些块。这种方案可能适合你,但关键是要尽量减少对这个主节点的访问。
如果你不把这些信息存储在专用节点上,你就必须在任何地方都存储它。试着用主持人的id给数据打上标记。
* How to handle it, if the node which was though to be down, suddenly comes back as if nothing happened?
请参考上文,但基本点是要小心,因为不再是主节点的节点可能会误以为自己是主节点。有一件事情我认为你还没有解决: 如何使更新到达主节点——也就是说,客户端如何知道要将更新发送到哪个节点?
* How to avoid split-brain scenarios, where the network is temporarily split into two, and both sides think that the other side has died?
Paxos在这里通过防止发生完美拆分的情况来避免进展。否则,就像以前一样,您必须非常小心。
总的来说,解决知道哪个节点作为主节点获取哪个数据项的问题,您将迈出修复架构的重要一步。请注意,您不能仅让接收更新的节点成为主节点-如果两个更新同时发生会怎么样?也不要依赖同步全局时钟-那样会产生疯狂的结果。如果可能的话,您可能希望避免在每次写入时运行共识,因此可以采用慢的主故障转移协议和快速的写入路径。
如果您想了解更多细节,请随时给我发送邮件。我的博客http://the-paper-trail.org涉及很多这方面的内容。
谢谢,
Henry