-
Notifications
You must be signed in to change notification settings - Fork 2
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
ShoppingCartEntity with Akka Typed #1
Conversation
* and missing JsonCreator
This reverts commit 970352d. * because it would only solve a small part
I have updated and tried this more. My conclusion is that we can support rolling updates from Lagom's PersistentEntity to Akka's EventSourcedEntity with partial outage for some requests.
The reasons we can't (without much effort) support those cross-requests are:
I think that is anyway pretty good, since the partial failures heal once the full rollout is completed. |
This is what I have used for testing.
|
This looks great! We forgot, on the original code, to shard the tags and it'd be interesting to expose that too. It's a few lines of code but it'd be great to surface all the pieces Lagom does for free. Would this be enough? @Override
public Set<String> tagsFor(Event event) {
String entityId = getEntityId();
// When migrating, `numShards` should be extracted
// from the `AggregateEventShards.numShards`
String tag = entityId + selectShard(numShards, entityId);
// whatever idiom to build a Set with a single-item that's
// fancy in Java nowadays.
Set<String> set = new HashSet<>(1);
// TODO: memoize these (entityId,Set<String>) pairs
set.add(tag);
return set;
}
private String selectShard(int numShards, String entityId) {
return Math.abs(entityId.hashCode) % numShards;
} That, and some other repetition ( |
@ignasi35 I can probably make An implementation note about your suggestion is that the |
ah, ofc! 😅 |
FYI... We have an open issue in Lagom lagom/lagom#1877 that shows how the Note, there are two cases here. One thing is the distribution of shard entities and I don't care if we accidentally create one extra shard, probably containing one single instance - what are the odds we get two entities with an The other case is then we use this same strategy to shard tags. A tag sharded with a negative number will be invisible for read-side processors and topic producers (and upcoming, akka-projections). The problem is that when we later want to know what are the shard identifiers, we do things like: val allTags: Set[AggregateEventTag[Event]] = {
(for (shardNo <- 0 until numShards) yield new AggregateEventTag(
eventType,
AggregateEventTag.shardTag(tag, shardNo)
)).toSet
} This actually shows that we are expecting them to be all positive numbers. I don't know what is the best way to solve that in Lagom. Considering the unlikeness of running into this, maybe the best solution is to fix the sharded tagging in Lagom and leave a note to users to check their journal and eventually fix by hand in case they notice a tag with a negative shard number. |
how about lagom/lagom#1877 (comment) ? Stay backwards compatible and fixes |
@patriknw, can you explain "...but there are other problems so not worth recommending"? I imagine that this is mainly related with how we will be serializing/deserializing the commands, correct? So, here is the follow-up question... When an untyped node sends a command to a typed node, can we pimp the serialized command with an But to be honest, I consider the case of less importance. A partial outage with very quickly full recovery is mostly acceptable. And if not, users can still choose to not migrate to Typed. If we have a situation in which it's absolutely necessary to provide such a feature we could then consider the engineering effort for doing that. |
Mostly around sender() vs replyTo in message. Akka Typed doesn't know about the sender, and Lagom PersistentEntity doesn't know about the replyTo in the message. With tricks as I did in akka/akka-samples#110 we could probably get it working, at least for some of the cases, but it would require changes in Lagom and user code.
Adding a
I agree, let's decide that. |
@patriknw, this PR has served its purpose to demonstrate / experiment with some ideas. I'm closing it because the |
Thought I'd try to convert the Java ShoppingCart to Akka Typed.
First commit is only the copy of the original so look at second commit if you want to see a side-by-side comparison.
Not running yet, because I need the new serializer (for ActorRef). I intend to use this as a playground for rolling updates for Lagom to Akka Typed migration.