akka.net icon indicating copy to clipboard operation
akka.net copied to clipboard

[Akka.Cluster.Sharding]: Add ability to query ShardRegion to see if a specific entity exists

Open Aaronontheweb opened this issue 5 years ago • 7 comments

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?

Aaronontheweb avatar Dec 12 '19 15:12 Aaronontheweb

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.

ismaelhamed avatar Dec 15 '19 13:12 ismaelhamed

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.

Aaronontheweb avatar Dec 15 '19 13:12 Aaronontheweb

This would be super useful for me, any way I can help out to get this added?

newmancodes avatar Mar 19 '20 13:03 newmancodes

@goodisontoffee A pull request would be great - we'd need to add:

  1. 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
  2. Need to run the build.cmd protobuf command to generate a new C# Protobuf class for that.
  3. 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
  4. Need to configure the ShardRegion and Shard 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?

Aaronontheweb avatar Mar 19 '20 13:03 Aaronontheweb

Perfect!

newmancodes avatar Mar 19 '20 13:03 newmancodes

@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.

Aaronontheweb avatar Mar 19 '20 13:03 Aaronontheweb

Roger lots of small change heading back to trunk. Most of it dormant until the whole thing is in place. Makes total sense.

newmancodes avatar Mar 19 '20 13:03 newmancodes

Completed this as part of Akka.NET v1.4.42 and 1.4.43.

Aaronontheweb avatar Oct 05 '22 20:10 Aaronontheweb