What is the correct way of disabling recovery of ReceivePersistentActor after some particular evert #7129
-
Dear Akka.Persistence Team, I'm using ReceivePersistentActor for representing Video Chat Session. Inside of Actor I'm storing current state and timers. I already implement the behavior I need but the problem is that after the Session finishes I don't need to recover this actor any more. So if the host restarted I don't need to restore all the old sessions. I need to restore state and timers only for active sessions. I resolved it by running a timer which sends a command 15 min after the Video Session End timer and then I execute DeleteMessages(long.MaxValue); It is working with only small issues - all actor's events deleted from the journal. I can see in the events table is_deleted column. Is there a way to set it to true from actor code and ignore duding recovery instead of deleting events from the table completely? Am I using DeleteMessages in the correct way? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
I am going to assume that you have 1 actor per Video Chat Session. The best approach here is to not activate those actors at all, if you can help it (i.e. don't ping them / raise them again) so they never even attempt to recover. But in the event that they are somehow activated anyway, here is what I'd recommend: // If you see this, this entity is dead and cannot be recovered
public sealed class SessionTombstone{
} "Tombstoning" is a popular strategy for setting a marker down in an event journal (in systems OUTSIDE of Akka.NET, FWIW) - have the actor do the following: case EndSessionCommand _: // or whatever
// When ending a session, instead of deleting messages,
// you could append a SessionTombstone event to mark its end.
Persist(new SessionTombstone(), tombstone =>
{
// Optionally perform additional cleanup or state updates here
Context.Stop(Self);
});
break; If you don't want any of your state, you can call When the actor "Recovers" and it notices the tombstone: Recover<SessionTombstone>(tombstone =>
{
// When a tombstone is recovered, stop the actor from recovering further.
// This effectively makes the actor ignore its past events and not perform any recovery logic.
Context.Stop(Self);
}); You can just show yourself down and not do any further processing this way. Does this help? |
Beta Was this translation helpful? Give feedback.
-
You're welcome! |
Beta Was this translation helpful? Give feedback.
Ah, this is your issue:
RememberEntities = true
- now this makes more sense. The "dead" entities are automatically being restarted.I have an even easier solution for you then - you just need to tell the Sharding system "stop remembering me" when the session is terminated. You can do this via the following:
Documentation showing how to do this is here: https://getakka.net/articles/clustering/cluster-sharding.html#terminatin…