Looking for some advise regarding Akka Persistence and ensuring atomic command operations where they involve more than one persistent actor.
The trick is handling error scenarios where one persistent actor successfully persists but another does not (leaving an inconsistent state).
My current idea to solve this is for the process manager actor (responsible for calling the persistent actors involved) to request the current Sequence Number from each persistent actor prior to calling persist on each of them.
If any problems occur mid process then the process manager would force the persistent actors involved to restart themselves and use the ‘Recover(toSequenceNr = X)’ to replay all the events up to the point prior to the whole process starting.
What I’m stuck on is how on earth to ask a persistent actor to restart itself to a given Sequence Number.
To my understanding causing an actor to restart will replace the backing instance of that actor, so passing the toSequenceNr value to the actor in the restart message is useless (as the value will be lost upon restart).
The only way I can think of to pass the toSequenceNr value to a persistence actor is for the persistent actor’s parent to stop the child completely and then recreate it while passing the toSequenceNr as a props parameter value.
This seems like a bit of overkill to me (pardon the pun) so I’m wondering if there is another way to restart a persistent actor and have it recover to a given sequence number?
Or am I barking up the wrong tree entirely trying to solve the atomic issue this way?
Any help much appreciated!