Whose Responsibility Creates Children Acc Akka When It Fails?

The documentation for Akka documentation matches:

The exact sequence of events during a restart is as follows: Pause the action (which means that it will not process normal messages until resumed) and recursively pause all children.

The misleading quote says:

Resuming an actor resumes the work of all subordinates, restarting the actor entails a restart of all subordinates, similarly, the completion of an actorโ€™s action will also lead to the termination of all his subordinates

I suspect that we are responsible for creating child (ren) in the preStart method, because the term Akka RESTART is not reSTART unless you create the preStart() method recursively and explicitly in your parent method. >

Example (using Akka 2.0 and 2.2-SNAPSHOT): no matter what I try, the children always just stop, never restart in this case. I create a Supervisor First Second relationship and throw an exception in Supervisor . It happens that Supervisor restarts and First and Second stopped.

  test("restart test") { val system = ActorSystem("test") val supervisor = system.actorOf(Props(new Supervisor), "supervisor") supervisor ! CREATE(Props(new First), "first") Thread.sleep(500) val first = system.actorFor("akka://test/user/supervisor/first") first ! CREATE(Props(new Second), "second") Thread.sleep(500) supervisor ! WTF Thread.sleep(20000) } case object WTF case class CREATE(p: Props, name: String) class Supervisor extends Actor { override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 10) { case _: IllegalStateException => Restart case _: IllegalArgumentException => Stop case _: Exception => Restart } override def preStart() { println(s"$self starts") } override def postStop() { println(s"$self stopped") } override def receive = { case WTF => println("throwing exception"); throw new IllegalStateException() case CREATE(p, name) => context.actorOf(p, name) } } class First extends Actor { override def preStart() { println(s"$self starts") } override def postStop() { println(s"$self stopped") } override def receive = { case WTF => println("throwing exception"); throw new IllegalStateException() case CREATE(p, name) => context.actorOf(p, name) } } class Second extends Actor { override def preStart() { println(s"$self starts") } override def postStop() { println(s"$self stopped") } override def receive = { case WTF => println("throwing exception"); throw new IllegalStateException() case CREATE => sender ! "ok" } } 

Actor [akka: // test / user / supervisor # 1599926629] starts Actor [akka: // test / user / supervisor / first # 2012011668] starts Actor [akka: // test / user / supervisor / first / second # 1750038710] begins

throwing exception Actor [akka: // test / user / supervisor # 1599926629] stopped [ERROR] [06/26/2013 11: 11: 16.899] [test-akka.actor.default-dispatcher-4] [akka: // test / user / supervisor] null java.lang.IllegalStateException at com.fg.mail.smtp.IntegrationSuite $ methodologists $$ anonfun $ get $ 1.applyOrElse (IntegrationSuite.scala: 40) at akka.actor.ActorCell.receiveMessage (ActorCell. scala: 498) at Account. akka.dispatch.Mailbox.processMailbox (Mailbox.scala: 237) at akka.dispatch.Mailbox.run (Mailbox.scala: 219) at akka.dispatch.ForkJoinExecutorConfigurator $ AkkaForkJoinTask.exec (AbstractDispatcher.scalacur 386) .forkjoin.ForkJoinTask.doExec (ForkJoinTask.java:262) in scala.concurrent.forkjoin.ForkJoinPool $ WorkQueue.runTask (ForkJoinPool.java:975) in scala.concurrent.forkjoin.ForkJoinPoolrun.javaPoolrun scala.concurrent.forkjoin.ForkJoinWorkerThread.run (ForkJoinWorkerThread.java:104)

Actor [aka: // test / user / supervisor / first / second # 1750038710] stopped Actor [akka: // test / user / supervisor / first # 2012011668] stopped Actor [akka: // test / user / supervisor # 1599926629] starts up

+6
source share
1 answer

Your suspicion is true. If you look at the 7-step description of the restart process at http://doc.akka.io/docs/akka/snapshot/general/supervision.html , you will see:

2 .... by default sends completion requests for all children ...

and

6. send a reboot request to all children who were not killed

So, you need to either redefine the parent hook of preRestart to stop Akka by killing the children, or redefine postRestart to recreate all the killed children.

What you choose really depends on the semantics of your application. Sometimes itโ€™s useful to kill the whole hierarchy and start from scratch, sometimes not.

+5
source

Source: https://habr.com/ru/post/948119/


All Articles