I am trying to follow best practices and apply error kernel pattern in Akka. According to this quote from here:
If one actor carries very important data (i.e. its state shall not be lost if avoidable), this actor should source out any possibly dangerous sub-tasks to children it supervises and handle failures of these children as appropriate. Depending on the nature of the requests, it may be best to create a new child for each request, which simplifies state management for collecting the replies. This is known as the “Error Kernel Pattern” from Erlang.
... it is a good idea to create children and delegate error prone work to them, concentrating important state in parent/supervisor actor.
In this scenario if actor with important state gets restarted for some reason, do I need to handle messages from it's stale children (that was created before restart)?
Lets illustrate this with example.
Lets asuume I have actors 3 actors: A
(is parent/supervisor of B
), B
(is parent/supervisor of C
, contains important state) and C
.
A
's supervision strategy is configured to restart it's children on exception.
C
gets created in B
's constructor.
Lets then assume that message bc
is sent form B
to C
. C
starts to process it (lets imagine that it runs long running computation there) and, once done will reply to B
with cb
.
Now, lets assume that before cb
is sent to and processed by B
A
sends message ab
to B
. This message causes B
to throw an exception and as a result of A
's supervision strategy decision B
will be restarted.
As a child of B
C
will be stopped during B
's restart (new C'
will be created in B
's constructor).
Will restarted B
receive cb
from C
that was sent before B
got restarted?
If yes, will sender
of cb
(C
) be considered a child of restarted B
? And will actor ref's of C
and C'
be equal (assuming C
and C'
s names are equal)?