From 375228273f8a550ea47886b8113ecf4efb24e94d Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Mon, 3 Jun 2019 09:31:28 +0200 Subject: [PATCH] Improve logging in DistributedData extension (#27051) * and don't load extension from ClusterReceptionist since that will trigger the warning logging if role is defined --- akka-cluster-typed/src/main/resources/reference.conf | 2 ++ .../ddata/typed/scaladsl/DistributedData.scala | 12 ++++++++++-- .../internal/receptionist/ClusterReceptionist.scala | 6 ++++-- .../scala/akka/cluster/ddata/DistributedData.scala | 12 ++++++++++-- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/akka-cluster-typed/src/main/resources/reference.conf b/akka-cluster-typed/src/main/resources/reference.conf index 73c251051b..42c86438d1 100644 --- a/akka-cluster-typed/src/main/resources/reference.conf +++ b/akka-cluster-typed/src/main/resources/reference.conf @@ -23,6 +23,8 @@ akka.cluster.typed.receptionist { # Settings for the Distributed Data replicator used by Receptionist. # Same layout as akka.cluster.distributed-data. distributed-data = ${akka.cluster.distributed-data} + # make sure that by default it's for all roles (Play loads config in different way) + distributed-data.role = "" } akka { diff --git a/akka-cluster-typed/src/main/scala/akka/cluster/ddata/typed/scaladsl/DistributedData.scala b/akka-cluster-typed/src/main/scala/akka/cluster/ddata/typed/scaladsl/DistributedData.scala index ecb9a7633a..f17dc00e92 100644 --- a/akka-cluster-typed/src/main/scala/akka/cluster/ddata/typed/scaladsl/DistributedData.scala +++ b/akka-cluster-typed/src/main/scala/akka/cluster/ddata/typed/scaladsl/DistributedData.scala @@ -6,6 +6,7 @@ package akka.cluster.ddata.typed.scaladsl import akka.actor.typed.{ ActorRef, ActorSystem, Extension, ExtensionId, Props } import akka.actor.ExtendedActorSystem +import akka.cluster.Cluster import akka.cluster.{ ddata => dd } import akka.cluster.ddata.SelfUniqueAddress @@ -39,8 +40,15 @@ class DistributedData(system: ActorSystem[_]) extends Extension { */ val replicator: ActorRef[Replicator.Command] = if (isTerminated) { - system.log.warning( - "Replicator points to dead letters: Make sure the cluster node is not terminated and has the proper role!") + val log = system.log.withLoggerClass(getClass) + if (Cluster(untypedSystem).isTerminated) + log.warning("Replicator points to dead letters, because Cluster is terminated.") + else + log.warning( + "Replicator points to dead letters. Make sure the cluster node has the proper role. " + + "Node has roles [], Distributed Data is configured for roles []", + Cluster(untypedSystem).selfRoles.mkString(","), + settings.roles.mkString(",")) system.deadLetters } else { val underlyingReplicator = dd.DistributedData(untypedSystem).replicator diff --git a/akka-cluster-typed/src/main/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionist.scala b/akka-cluster-typed/src/main/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionist.scala index 243e583816..b94ebce145 100644 --- a/akka-cluster-typed/src/main/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionist.scala +++ b/akka-cluster-typed/src/main/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionist.scala @@ -12,7 +12,6 @@ import akka.actor.typed.scaladsl.{ ActorContext, Behaviors } import akka.actor.typed.{ ActorRef, Behavior, Terminated } import akka.annotation.InternalApi import akka.cluster.ClusterEvent.MemberRemoved -import akka.cluster.ddata.typed.scaladsl.DistributedData import akka.cluster.ddata.{ ORMultiMap, ORMultiMapKey, Replicator } import akka.cluster.{ Cluster, ClusterEvent, UniqueAddress } import akka.remote.AddressUidExtension @@ -25,6 +24,7 @@ import akka.cluster.ClusterEvent.ClusterShuttingDown import akka.cluster.ClusterEvent.MemberJoined import akka.cluster.ClusterEvent.MemberUp import akka.cluster.ClusterEvent.MemberWeaklyUp +import akka.cluster.ddata.SelfUniqueAddress // just to provide a log class /** INTERNAL API */ @@ -75,7 +75,9 @@ private[typed] object ClusterReceptionist extends ReceptionistBehaviorProvider { case _ => throw new IllegalStateException("Cannot actually happen") } val cluster = Cluster(untypedSystem) - implicit val selfNodeAddress = DistributedData(ctx.system).selfUniqueAddress + // don't use DistributedData.selfUniqueAddress here, because that will initialize extension, which + // isn't used otherwise by the ClusterReceptionist + implicit val selfNodeAddress = SelfUniqueAddress(cluster.selfUniqueAddress) val replicator = ctx.actorOf(Replicator.props(settings.replicatorSettings), "replicator") diff --git a/akka-distributed-data/src/main/scala/akka/cluster/ddata/DistributedData.scala b/akka-distributed-data/src/main/scala/akka/cluster/ddata/DistributedData.scala index b177b2e47a..260ef20ce3 100644 --- a/akka-distributed-data/src/main/scala/akka/cluster/ddata/DistributedData.scala +++ b/akka-distributed-data/src/main/scala/akka/cluster/ddata/DistributedData.scala @@ -11,6 +11,7 @@ import akka.actor.Extension import akka.actor.ExtensionId import akka.actor.ExtensionIdProvider import akka.cluster.{ Cluster, UniqueAddress } +import akka.event.Logging object DistributedData extends ExtensionId[DistributedData] with ExtensionIdProvider { override def get(system: ActorSystem): DistributedData = super.get(system) @@ -37,8 +38,15 @@ class DistributedData(system: ExtendedActorSystem) extends Extension { */ val replicator: ActorRef = if (isTerminated) { - system.log.warning( - "Replicator points to dead letters: Make sure the cluster node is not terminated and has the proper role!") + val log = Logging(system, getClass) + if (Cluster(system).isTerminated) + log.warning("Replicator points to dead letters, because Cluster is terminated.") + else + log.warning( + "Replicator points to dead letters. Make sure the cluster node has the proper role. " + + "Node has roles [], Distributed Data is configured for roles []", + Cluster(system).selfRoles.mkString(","), + settings.roles.mkString(",")) system.deadLetters } else { system.systemActorOf(Replicator.props(settings), ReplicatorSettings.name(system, None))