4

我正在使用 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]

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

4

1 回答 1

5

我不确定这是否会回答您的问题,但是在查看 的源代码时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)

对我来说,这篇文章看起来像是在说“如果我是领导者,请将 start 更改为成为领导者,并且 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")
  }

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

于 2013-05-02T18:54:50.650 回答