From aaa620c35e8356a418fb592375ad42aa560cc886 Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Mon, 4 May 2015 08:35:46 +0200 Subject: [PATCH] =clu #17362 Make cluster.joinSeedNodes equivalent to conf seed-nodes * the difference was in the retry of failed join attempt * also clarify the documentation --- .../scala/akka/cluster/ClusterDaemon.scala | 27 ++++++++++--------- akka-docs/rst/java/cluster-usage.rst | 15 ++++++----- akka-docs/rst/scala/cluster-usage.rst | 15 ++++++----- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/akka-cluster/src/main/scala/akka/cluster/ClusterDaemon.scala b/akka-cluster/src/main/scala/akka/cluster/ClusterDaemon.scala index 7d9a7ec924..f91cf9f972 100644 --- a/akka-cluster/src/main/scala/akka/cluster/ClusterDaemon.scala +++ b/akka-cluster/src/main/scala/akka/cluster/ClusterDaemon.scala @@ -239,6 +239,7 @@ private[cluster] class ClusterCoreDaemon(publisher: ActorRef) extends Actor with val statsEnabled = PublishStatsInterval.isFinite var gossipStats = GossipStats() + var seedNodes = SeedNodes var seedNodeProcess: Option[ActorRef] = None var seedNodeProcessCounter = 0 // for unique names var leaderActionCounter = 0 @@ -279,10 +280,10 @@ private[cluster] class ClusterCoreDaemon(publisher: ActorRef) extends Actor with case _ ⇒ // auto-down is disabled } - if (SeedNodes.isEmpty) + if (seedNodes.isEmpty) logInfo("No seed-nodes configured, manual cluster join required") else - self ! JoinSeedNodes(SeedNodes) + self ! JoinSeedNodes(seedNodes) } override def postStop(): Unit = { @@ -296,7 +297,7 @@ private[cluster] class ClusterCoreDaemon(publisher: ActorRef) extends Actor with def uninitialized: Actor.Receive = { case InitJoin ⇒ sender() ! InitJoinNack(selfAddress) case ClusterUserAction.JoinTo(address) ⇒ join(address) - case JoinSeedNodes(seedNodes) ⇒ joinSeedNodes(seedNodes) + case JoinSeedNodes(newSeedNodes) ⇒ joinSeedNodes(newSeedNodes) case msg: SubscriptionMessage ⇒ publisher forward msg } @@ -306,14 +307,15 @@ private[cluster] class ClusterCoreDaemon(publisher: ActorRef) extends Actor with case ClusterUserAction.JoinTo(address) ⇒ becomeUninitialized() join(address) - case JoinSeedNodes(seedNodes) ⇒ + case JoinSeedNodes(newSeedNodes) ⇒ becomeUninitialized() - joinSeedNodes(seedNodes) + joinSeedNodes(newSeedNodes) case msg: SubscriptionMessage ⇒ publisher forward msg case _: Tick ⇒ if (deadline.exists(_.isOverdue)) { + // join attempt failed, retry becomeUninitialized() - if (SeedNodes.nonEmpty) joinSeedNodes(SeedNodes) + if (seedNodes.nonEmpty) joinSeedNodes(seedNodes) else join(joinWith) } } @@ -371,21 +373,22 @@ private[cluster] class ClusterCoreDaemon(publisher: ActorRef) extends Actor with def initJoin(): Unit = sender() ! InitJoinAck(selfAddress) - def joinSeedNodes(seedNodes: immutable.IndexedSeq[Address]): Unit = { - if (seedNodes.nonEmpty) { + def joinSeedNodes(newSeedNodes: immutable.IndexedSeq[Address]): Unit = { + if (newSeedNodes.nonEmpty) { stopSeedNodeProcess() + seedNodes = newSeedNodes // keep them for retry seedNodeProcess = - if (seedNodes == immutable.IndexedSeq(selfAddress)) { + if (newSeedNodes == immutable.IndexedSeq(selfAddress)) { self ! ClusterUserAction.JoinTo(selfAddress) None } else { // use unique name of this actor, stopSeedNodeProcess doesn't wait for termination seedNodeProcessCounter += 1 - if (seedNodes.head == selfAddress) { - Some(context.actorOf(Props(classOf[FirstSeedNodeProcess], seedNodes). + if (newSeedNodes.head == selfAddress) { + Some(context.actorOf(Props(classOf[FirstSeedNodeProcess], newSeedNodes). withDispatcher(UseDispatcher), name = "firstSeedNodeProcess-" + seedNodeProcessCounter)) } else { - Some(context.actorOf(Props(classOf[JoinSeedNodeProcess], seedNodes). + Some(context.actorOf(Props(classOf[JoinSeedNodeProcess], newSeedNodes). withDispatcher(UseDispatcher), name = "joinSeedNodeProcess-" + seedNodeProcessCounter)) } } diff --git a/akka-docs/rst/java/cluster-usage.rst b/akka-docs/rst/java/cluster-usage.rst index 6fb9d5db85..791ca11324 100644 --- a/akka-docs/rst/java/cluster-usage.rst +++ b/akka-docs/rst/java/cluster-usage.rst @@ -88,7 +88,9 @@ seed nodes in the existing cluster. If you don't configure seed nodes you need to join the cluster programmatically or manually. Manual joining can be performed by using ref:`cluster_jmx_java` or :ref:`cluster_command_line_java`. -Joining programatically can be performed with ``Cluster.get(system).join``. +Joining programatically can be performed with ``Cluster.get(system).join``. Unsuccessful join attempts are +automatically retried after the time period defined in configuration property ``retry-unsuccessful-join-after``. +Retries can be disabled by setting the property to ``off``. You can join to any node in the cluster. It does not have to be configured as a seed node. Note that you can only join to an existing cluster member, which means that for bootstrapping some @@ -99,11 +101,12 @@ which is attractive when dynamically discovering other nodes at startup by using When using ``joinSeedNodes`` you should not include the node itself except for the node that is supposed to be the first seed node, and that should be placed first in parameter to ``joinSeedNodes``. -Unsuccessful join attempts are automatically retried after the time period defined in -configuration property ``retry-unsuccessful-join-after``. When using ``seed-nodes`` this -means that a new seed node is picked. When joining manually or programatically this means -that the last join request is retried. Retries can be disabled by setting the property to -``off``. +Unsuccessful attempts to contact seed nodes are automatically retried after the time period defined in +configuration property ``seed-node-timeout``. Unsuccessful attempt to join a specific seed node is +automatically retried after the configured ``retry-unsuccessful-join-after`. Retrying means that it +tries to contact all seed nodes and then joins the node that answers first. The first node in the list +of seed nodes will join itself if it cannot contact any of the other seed nodes within the +configured ``seed-node-timeout``. An actor system can only join a cluster once. Additional attempts will be ignored. When it has successfully joined it must be restarted to be able to join another diff --git a/akka-docs/rst/scala/cluster-usage.rst b/akka-docs/rst/scala/cluster-usage.rst index b0312c0d38..7319840b6e 100644 --- a/akka-docs/rst/scala/cluster-usage.rst +++ b/akka-docs/rst/scala/cluster-usage.rst @@ -82,7 +82,9 @@ seed nodes in the existing cluster. If you don't configure seed nodes you need to join the cluster programmatically or manually. Manual joining can be performed by using ref:`cluster_jmx_scala` or :ref:`cluster_command_line_scala`. -Joining programatically can be performed with ``Cluster(system).join``. +Joining programatically can be performed with ``Cluster(system).join``. Unsuccessful join attempts are +automatically retried after the time period defined in configuration property ``retry-unsuccessful-join-after``. +Retries can be disabled by setting the property to ``off``. You can join to any node in the cluster. It does not have to be configured as a seed node. Note that you can only join to an existing cluster member, which means that for bootstrapping some @@ -94,11 +96,12 @@ When using ``joinSeedNodes`` you should not include the node itself except for t supposed to be the first seed node, and that should be placed first in parameter to ``joinSeedNodes``. -Unsuccessful join attempts are automatically retried after the time period defined in -configuration property ``retry-unsuccessful-join-after``. When using ``seed-nodes`` this -means that a new seed node is picked. When joining manually or programatically this means -that the last join request is retried. Retries can be disabled by setting the property to -``off``. +Unsuccessful attempts to contact seed nodes are automatically retried after the time period defined in +configuration property ``seed-node-timeout``. Unsuccessful attempt to join a specific seed node is +automatically retried after the configured ``retry-unsuccessful-join-after`. Retrying means that it +tries to contact all seed nodes and then joins the node that answers first. The first node in the list +of seed nodes will join itself if it cannot contact any of the other seed nodes within the +configured ``seed-node-timeout``. An actor system can only join a cluster once. Additional attempts will be ignored. When it has successfully joined it must be restarted to be able to join another