Cluster sharing without persistence? How to relay entity id to props?

161 views
Skip to first unread message

kraythe

unread,
Jun 6, 2016, 1:19:11 PM6/6/16
to Akka User List
I have an actor that I would like to use cluster sharing for but the thing is that the actor will restore its state from a database in the event of migration and so on. So there is no need to journal the messages and thus no need for Akka persistence. I have the vast majority of it sorted, but what I can't figure out how to pass the entity id to the actor when the sharing system creates the actor. I this would be important to bind the actor to the entity so the same actor will be consulted later for information on the entity. How can I get the sharing system to pass the id to the props when the actor is created? Also how can I get the sharing system to create these actors in bulk because I might have to start several thousand at once and would rather not have to make several thousand DB calls but rather one call. 

Thanks in advance. 

Justin du coeur

unread,
Jun 6, 2016, 2:24:48 PM6/6/16
to akka...@googlegroups.com
On Mon, Jun 6, 2016 at 1:19 PM, kraythe <kra...@gmail.com> wrote:
I have an actor that I would like to use cluster sharing for but the thing is that the actor will restore its state from a database in the event of migration and so on. So there is no need to journal the messages and thus no need for Akka persistence. I have the vast majority of it sorted, but what I can't figure out how to pass the entity id to the actor when the sharing system creates the actor.

Just get it from the Actor's name.  Actors can always see their own name.  That's how I often do it.  (For example, see here.)
 
I this would be important to bind the actor to the entity so the same actor will be consulted later for information on the entity. How can I get the sharing system to pass the id to the props when the actor is created? Also how can I get the sharing system to create these actors in bulk because I might have to start several thousand at once and would rather not have to make several thousand DB calls but rather one call.

There's nothing built in for this, AFAIK.  Indeed, I don't see how this would be possible in principle, since the Sharding system has no a priori concept of all the possible entities.

This actually seems fairly tricky, since it is binding the actors together in a way that isn't normal for Akka.  My best guess would be to have a single Actor that does the mammoth DB call, sucks all the data in, and then when the entities get created by Cluster Sharding they ping that master data manager for their init data.  (Or something like that.)

Akka Team

unread,
Jun 9, 2016, 5:57:04 AM6/9/16
to Akka User List
Hi,

By "sharing" you mean "sharding" right?

It is completely possible to use sharding without akka-persistence. You can use custom persistence to achieve saving and restoring state of an actor. Alternatively, you can use persistence with only snapshots, and you might use your own SnapshotStore plugin to store the state as you see fit.

sharing system creates the actor. I this would be important to bind the actor to the entity so the same actor will be consulted later for information on the entity. How can I get the sharing system to pass the id to the props when the actor is created?

Even when you use Akka persistence, the persistenceId of the sharded actor usually consists of the actor name, which corresponds to the entityId (see the sample here: http://doc.akka.io/docs/akka/2.4.7/scala/cluster-sharding.html#An_Example esp the comment "self.path.name is the entity identifier (utf-8 URL-encoded)")

 
Also how can I get the sharing system to create these actors in bulk because I might have to start several thousand at once and would rather not have to make several thousand DB calls but rather one call. 

There is no built-in support for that. If you are using akka-persistence with only snapshots, and you provide your own snapshot store plugin, then you are able to implement batch writes on your own if you want, but the higher level sharding service has no way of implementing this.

-Endre
 

Thanks in advance. 

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Akka Team
Typesafe - Reactive apps on the JVM
Blog: letitcrash.com
Twitter: @akkateam
Reply all
Reply to author
Forward
0 new messages