Reputation: 1397
I was looking at sharding example and noticed that the parent's name is used as part of the PersistenceId?
PersistenceId = Context.Parent.Path.Name + "-" + Self.Path.Name;
My questions:
Is the parent's name the ShardId?
What is the purpose of using it? Does it act like a composite key?
My EntityId is a guid and my MessageExtractor inherits from HashCodeMessageExtractor class. Since that will give me a consistent hash for ShardId based on the PersistenceId/Guid, do I still need to use the parents name as part of the PersistenceId? Also, does the hash value change for the same guid depending on different constructor values (maxNumberOfShards)?
Upvotes: 0
Views: 201
Reputation: 7542
This example is specific to Akka.Cluster.Sharding. While being managed by a cluster sharding extension, sharded actors (called entities) are still placed under standard akka actor hierarchy tree. It looks more or less like this:
While your actor is entity part in this tree, the rest is created by Akka.Cluster.Sharding plugin.
Another part is a way of localizing entity in the cluster. For this Akka.Cluster.Sharding uses a composite key in form of (shardId,entityId). Always.
HashCodeMessageExtractor
, you've mentioned - the shardId is generated/computed based solely on the entityId. In that case you don't need to include it anywhere, entityId is enough. Downside of using HashCodeMessageExtractor
is that you must provide max number of shards up front: brain-dead rule is to use 10 * max-number-of-nodes you expect to ever have in your cluster.You can find more detailed info about building shard ids here.
Upvotes: 1