0

I want to have a scheduler in my cluster that would send some messages after some time. From what I see scheduler is per actorsystem, from my tests only for local actor system. Not the cluster one. So If schedule something on one node, if it get's down then all scheduled tasks are discarded.

If I create a Cluster Singleton which would be responsible for scheduling, could the already made schedules survive recreation on some other node? Or should I keep it as a persistent actor with structure of already created schedules metadata and in preStart phase reschedule everything that was persisted?

Levi Ramsey
  • 18,884
  • 1
  • 16
  • 30
jtyb
  • 43
  • 5

1 Answers1

2

A cluster singleton will reincarnate on another node if the node it was previously on is downed or leaves the cluster.

That reincarnation will start with a clean slate: it won't remember its "past lives".

However, if it's a persistent actor (or, equivalently, its behavior is an EventSourcedBehavior in Akka Typed), it will on startup recover its state from the event stream (and/or snapshots). For a persistent actor, this typically doesn't require anything to be done preStart: the persistence implementation will take care of replaying the events.

Depending on how many tasks are scheduled and if you want the schedule to be discarded on a full cluster restart, it may be possible to use Akka Distributed Data to have the schedule metadata distributed around the cluster (with tuneable consistency) and then have a cluster singleton scheduling actor read that metadata.

Levi Ramsey
  • 18,884
  • 1
  • 16
  • 30
  • hey, thanks for your answear. So seems like I had good idea with this persistent singleton actor. Pity there is no out of the box solution for cluster scheduler. – jtyb Feb 01 '21 at 11:13
  • hej, one more question. With Cluster Singleton i have always only one working actor of course. So if I use this replicator from DD would the starting singleton actor on some other node would receive all the historical events replicator got? Or just the ones starting from subscription? – jtyb Feb 04 '21 at 08:38
  • 1
    With ddata, the singleton can expect to eventually receive all updates, including previous ones (assuming that the updates are made with a quorum appropriate for the expected rate and size of cluster membership changes). – Levi Ramsey Feb 04 '21 at 12:36