akka.net
akka.net copied to clipboard
[Akka.Cluster.Sharding]: Add ability to query ShardRegion to see if a specific entity exists
Version: v1.4.0-beta*
It would be great if https://github.com/akkadotnet/akka.net/blob/dev/src/contrib/cluster/Akka.Cluster.Sharding/ShardingMessages.cs supported the ability to query a ShardRegion
to check to see if a specific entity exists or not.
I.e. HasEntity(string entityId, string shardId = null)
This should be able to be done without necessarily knowing which shard the entity is hosted inside of - but given that the shardId
parameter is optional, it's possible to limit the query to a specific shard.
Does this seem like something worth adding to the framework?
I guess HasEntity
might have different meanings, depending on your use case. For instance: an entity could do exist but passivated on disk, in which case the ShardRegion wouldn't know.
I guess I’d use it in the sense of whether or not this entity exists right now. Whether it has existed in the past or not opens us up to a lot of other complications.
Sent from my iPhone
On Dec 15, 2019, at 2:16 PM, Ismael Hamed [email protected] wrote:
I guess HasEntity might have different meanings, depending on your use case. For instance: an entity could do exist but passivated on disk, in which case the ShardRegion wouldn't know.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
This would be super useful for me, any way I can help out to get this added?
@goodisontoffee A pull request would be great - we'd need to add:
- A new protobuf message type, added to https://github.com/akkadotnet/akka.net/blob/dev/src/protobuf/ClusterShardingMessages.proto - need that to be able to send this query across nodes in the shard
- Need to run the
build.cmd protobuf
command to generate a new C# Protobuf class for that. - Need to add a C# message type that will be handled by the actors, and that type will also need to be mapped inside https://github.com/akkadotnet/akka.net/blob/dev/src/contrib/cluster/Akka.Cluster.Sharding/Serialization/ClusterShardingMessageSerializer.cs - you'll also want to add unit tests for that insidehttps://github.com/akkadotnet/akka.net/blob/dev/src/contrib/cluster/Akka.Cluster.Sharding.Tests/ClusterShardingMessageSerializerSpec.cs
- Need to configure the
ShardRegion
andShard
actors to handle this message, and you'll want to add a functional unit test to https://github.com/akkadotnet/akka.net/blob/dev/src/contrib/cluster/Akka.Cluster.Sharding.Tests.MultiNode/ClusterShardingGetStatsSpec.cs to validate that this query works (1) when the entity is available locally, (2) when the entity is available remotely, and (3) when the entity is not available anywhere
Does that help?
Perfect!
@goodisontoffee just to make sure you don't waste any time on this PR if you decide to do it, here is how I recommend doing the PR
- Do a simple PR with just the protobuf first and the C# objects you're going to pass between actors and leave the PR in a draft state. Have one of us give comments on the messaging protocol itself before you start implementing the bigger stuff, like serialization and actor code.
- Do serialization next, since that's relatively self-contained and easy to test.
- Implement the actor messaging protocol third.
- Implement the end to end tests last.
We can give reviews and feedback along the way - definitely easier to do it in small chunks like that rather than one big pull request.
Roger lots of small change heading back to trunk. Most of it dormant until the whole thing is in place. Makes total sense.
Completed this as part of Akka.NET v1.4.42 and 1.4.43.