-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Akka.Cluster.Sharding: automatically handle ShardingEnvelope
and StartEntity
without forcing user to define handlers
#6717
Comments
So this is a bit of a problem: akka.net/src/contrib/cluster/Akka.Cluster.Sharding/ClusterSharding.cs Lines 1426 to 1444 in b7ec446
In order for this system to work properly, and we have to solve the same issue we ran into when implementing the
Really, the public delegate Option<(EntityId, Msg)> ExtractEntityId(Msg message);
public delegate ShardId ExtractShardId(EntityId entityId); The benefits of doing it that way:
But since they're not, that leave us in a pickle. We can either:
We should make a decision, but my guess is that the size and scope of this decision puts things somewhat out of reach for now. |
Wow! Since when do we need to handle
IMO, any improvements to the internals of the project that deviate from how the JVM works, it'd be wiser to bring them up with the original Team/Community so that they can also benefit from them. |
@ismaelhamed it's always been that way - we do handle it automatically here for a specific type of query: akka.net/src/contrib/cluster/Akka.Cluster.Sharding/ShardRegion.cs Lines 951 to 959 in 4f27bac
Technically it's true - the message only needs to be handled by the
So looking at how Akka 2.6.19 does things: @InternalApi private[akka] class ExtractorAdapter[E, M](delegate: ShardingMessageExtractor[E, M])
extends ShardingMessageExtractor[Any, M] {
override def entityId(message: Any): String = {
message match {
case ShardingEnvelope(entityId, _) => entityId null
case ClassicStartEntity(entityId) => entityId
case msg => delegate.entityId(msg.asInstanceOf[E])
}
}
override def shardId(entityId: String): String = delegate.shardId(entityId) They also do what I'm proposing here - and they redesigned their extractors to work as I described above: only the |
The |
In order for that adapter structure to work, we have to deprecate the old |
On #6863 I've been able to implement the basic structures needed to support this without any breaking changes - and it looks like there is automatic handling for |
…artEntity` and `ShardEnvelope` handling (#6863) * added new API to help address #6717 * integrating into `ShardRegion` and `Shard` * finished all API changes * API approvals * updated `ShardRegion` to use new APIs * optimized `Shard` * updated API approvals * aggressively inline hashcode message extractor calls * fixed `ShardedDaemon` message extractor * added `ExtractorAdapter` to automatically handle messages * fixed spec * perf * Revert "perf" This reverts commit 7c0a7f4. * fixed bugs with `StartEntity` * made `MessageExtractor` and `ShardIdExtractor` delegates obsolete
Is your feature request related to a problem? Please describe.
We have two built-in message types inside Akka.Cluster.Sharding that are designed to be routed automatically to entity actors:
ShardEnvelope
- used to wrap normal messages withEntityId
data so they can be routed correctly to the appropriate entity actor.akka.net/src/contrib/cluster/Akka.Cluster.Sharding/ShardedDaemonProcess.cs
Lines 76 to 93 in 24dec7f
This message is going to be used heavily in our reliable delivery system going forward
ShardRegion.StartEntity
- used to powerremember-entities=on
and currently we tell users they have to support this in their message extractors.akka.net/src/contrib/cluster/Akka.Cluster.Sharding/ShardRegion.cs
Lines 99 to 141 in 7533c92
Describe the solution you'd like
The
ShardRegion
should just handle both of these messages automatically, without requiring users to manually handle them inside their own message extractors. We know what these messages are for and we have all the data we need to route them, so why not?Additional context
It is possible that there can be a performance impact to doing this, as we now have to filter the messages twice instead of once - but erroring on the side of having better DX here seems like a no-brainer.
The text was updated successfully, but these errors were encountered: