集群脑裂
问题和影响
系统集群化后,出现物理机崩溃的情况,或者节点奔溃,如果没有从集群成员中剔除,系统会一直尝试连接。而网络分区、以及进程高负载无响应情况,则会引发脑裂现象。当一个节点观察到另外节点异常时,系统无法判定它暂时性故障还是永久性故障,所以我们把这些情况一起处理。
脑裂会把集群划分成多个集群,且独立运行,如果使用了类似Singleton唯一性业务的功能,就会有问题。
期望
发生崩溃时,我们希望集群立即把崩溃的节点从成员资格中剔除;网络分区或者无响应时,我们希望等待一会,再检查节点是否治愈,如果治愈了就保持成员资格,如果还是无法响应就得关闭其中一侧的节点。
这里有个难点,不知道哪一侧应该保留,那一侧关闭,因为两侧也不能互相通讯。所以我们希望,双方都能自己做出决定,并且哪一侧继续运行哪一侧自行关闭得做出相同的决定。
策略
前提
所有策略的前提是集群处于一个稳定的(stable)状态。
# To enable the split brain resolver you first need to enable the provider in your application.conf:
# akka.cluster.downing-provider-class = "com.lightbend.akka.sbr.SplitBrainResolverProvider"
akka.cluster.split-brain-resolver {
# Select one of the available strategies (see descriptions below):
# static-quorum, keep-majority, keep-oldest, keep-referee, down-all
# if left "off" when the downing provider is enabled cluster startup will fail.
active-strategy = off
# Time margin after which shards or singletons that belonged to a downed/removed
# partition are created