gpt4 book ai didi

Akka 2.2 ClusterSingletonManager 发送 HandOverToMe 到 [None]

转载 作者:行者123 更新时间:2023-12-03 02:04:41 25 4
gpt4 key购买 nike

我正在使用 Akka 2.2 contrib 的项目 ClusterSingletonManager 来保证集群中始终存在且只有一种特定类型的参与者(master)。然而,我观察到了一种奇怪的行为(顺便说一句,这可能是预料之中的,但无法理解为什么)。每当主节点退出集群并稍后加入时,就会发生以下操作序列:

[INFO] [04/30/2013 17:47:35.805] [ClusterSystem-akka.actor.default-dispatcher-9] [akka://ClusterSystem/system/cluster/core/daemon] Cluster Node [akka.tcp://ClusterSystem@127.0.0.1:2551] - Welcome from [akka.tcp://ClusterSystem@127.0.0.1:2552]
[INFO] [04/30/2013 17:47:48.703] [ClusterSystem-akka.actor.default-dispatcher-8] [akka://ClusterSystem/user/singleton] Member removed [akka.tcp://ClusterSystem@127.0.0.1:52435]
[INFO] [04/30/2013 17:47:48.712] [ClusterSystem-akka.actor.default-dispatcher-2] [akka://ClusterSystem/user/singleton] ClusterSingletonManager state change [Start -> BecomingLeader]
[INFO] [04/30/2013 17:47:49.752] [ClusterSystem-akka.actor.default-dispatcher-9] [akka://ClusterSystem/user/singleton] Retry [1], sending HandOverToMe to [None]
[INFO] [04/30/2013 17:47:50.850] [ClusterSystem-akka.actor.default-dispatcher-21] [akka://ClusterSystem/user/singleton] Retry [2], sending HandOverToMe to [None]
[INFO] [04/30/2013 17:47:51.951] [ClusterSystem-akka.actor.default-dispatcher-20] [akka://ClusterSystem/user/singleton] Retry [3], sending HandOverToMe to [None]
[INFO] [04/30/2013 17:47:53.049] [ClusterSystem-akka.actor.default-dispatcher-3]

...

[INFO] [04/30/2013 17:48:10.650] [ClusterSystem-akka.actor.default-dispatcher-21] [akka://ClusterSystem/user/singleton] Retry [20], sending HandOverToMe to [None]
[INFO] [04/30/2013 17:48:11.751] [ClusterSystem-akka.actor.default-dispatcher-4] [akka://ClusterSystem/user/singleton] Timeout in BecomingLeader. Previous leader unknown, removed and no TakeOver request.
[INFO] [04/30/2013 17:48:11.752] [ClusterSystem-akka.actor.default-dispatcher-4] [akka://ClusterSystem/user/singleton] Singleton manager [akka.tcp://ClusterSystem@127.0.0.1:2551] starting singleton actor
[INFO] [04/30/2013 17:48:11.754] [ClusterSystem-akka.actor.default-dispatcher-4] [akka://ClusterSystem/user/singleton] ClusterSingletonManager state change [BecomingLeader -> Leader]

为什么它尝试将 HandOverToMe 发送到 [None]?它需要大约 20 秒(重试 20 次)才能成为新的领导者,尽管在这种特殊情况下,前一个领导者是众所周知的......

最佳答案

我不确定这是否能回答您的问题,但是在查看ClusterSingletonManager的源代码时,您可以看到导致这种情况的事件链。该类使用 Akka 中的有限状态机逻辑,并且您所看到的行为是由于从 Start -> BecomingLeader 的状态转换而启动的。首先,查看Start状态:

when(Start) {
case Event(StartLeaderChangedBuffer, _) ⇒
leaderChangedBuffer = context.actorOf(Props[LeaderChangedBuffer].withDispatcher(context.props.dispatcher))
getNextLeaderChanged()
stay

case Event(InitialLeaderState(leaderOption, memberCount), _) ⇒
leaderChangedReceived = true
if (leaderOption == selfAddressOption && memberCount == 1)
// alone, leader immediately
gotoLeader(None)
else if (leaderOption == selfAddressOption)
goto(BecomingLeader) using BecomingLeaderData(None)
else
goto(NonLeader) using NonLeaderData(leaderOption)
}

这里要查看的部分是:

    else if (leaderOption == selfAddressOption)
goto(BecomingLeader) using BecomingLeaderData(None)

对我来说,这篇文章似乎在说“如果我是领导者,请将开始更改为成为领导者,并将 None 作为 previousLeader 选项”

然后,如果您查看 BecomingLeader 状态:

when(BecomingLeader) {
...
case Event(HandOverRetry(count), BecomingLeaderData(previousLeaderOption)) ⇒
if (count <= maxHandOverRetries) {
logInfo("Retry [{}], sending HandOverToMe to [{}]", count, previousLeaderOption)
previousLeaderOption foreach { peer(_) ! HandOverToMe }
setTimer(HandOverRetryTimer, HandOverRetry(count + 1), retryInterval, repeat = false)
} else if (previousLeaderOption forall removed.contains) {
// can't send HandOverToMe, previousLeader unknown for new node (or restart)
// previous leader might be down or removed, so no TakeOverFromMe message is received
logInfo("Timeout in BecomingLeader. Previous leader unknown, removed and no TakeOver request.")
gotoLeader(None)
} else
throw new ClusterSingletonManagerIsStuck(
s"Becoming singleton leader was stuck because previous leader [${previousLeaderOption}] is unresponsive")
}

这是不断重复您在日志中看到的消息的 block 。它基本上看起来像是试图让前任领导者将责任移交给不知道前任领导者是谁的人,因为在状态转换中,它传递了 None 作为前任领导者。值(value)百万美元的问题是“如果它不知道前任领导者是谁,为什么还要继续尝试永远不会成功的交接?”。

关于Akka 2.2 ClusterSingletonManager 发送 HandOverToMe 到 [None],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16305194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com