Repository navigation
Conversation
| String actorId, | ||
| String methodName, | ||
| byte[] jsonPayload, | ||
| Map<String, String> headers) { |
There was a problem hiding this comment.
I assume the gRPC implementation is still in progress for this.
There was a problem hiding this comment.
Yes, the problem here is that the protobuf doesn't appear to expose Metadata to us, so I think this change might require a protobuf update.
| this.runtimeContext = runtimeContext; | ||
| this.actorMethods = new ActorMethodInfoMap(runtimeContext.getActorTypeInformation().getInterfaces()); | ||
| this.activeActors = Collections.synchronizedMap(new HashMap<>()); | ||
| this.actorReentrancyContext = new ActorReentrancyContext(); |
There was a problem hiding this comment.
The reentrancy context is per method, not?
Still, I don't think this will work because it would need a way to garbage collect. Imagine that the call stack failed, there would need to be a way to understand that the call stack is over and release the id.
I like the idea of providing the context via an argument to the Actor's method is Reentrancy annotation is present. This way, it remains a stateless solution.
The preferred solution would still be to have this context passed through via Mono. I think we should move this to the next release since it will require more investigation.
There was a problem hiding this comment.
The reentrancy context is per method, not?
The context is per actor id/type combo.
I like the idea of providing the context via an argument to the Actor's method is Reentrancy annotation is present. This way, it remains a stateless solution.
I avoided passing it through via a method because we originally wanted to have the passthrough happen without downstream actor's having to touch it. I don't think we can achieve that just by passing it through so we'd have to make that call about experience.
Still, I don't think this will work because it would need a way to garbage collect. Imagine that the call stack failed, there would need to be a way to understand that the call stack is over and release the id.
This is actually one of the few places where Reactor was able to help us. On the original call into the actor we can setup a terminal event (currently we just have onSuccess) that clears the ID. This comes in both success and error flavors. If the actual Java runtime crashes, the data is cleared anyway, so I think this is fine.
The preferred solution would still be to have this context passed through via Mono. I think we should move this to the next release since it will require more investigation.
As for passing the context through via Mono's SubscriberContext, I don't think we're actually using Reactor in a way that this is possible. The SubscriberContext as we need it is available in a single call chain. Since our chain involves a method that can call into other methods (thus creating a nested mono), we lose access to the original pipeline and context in the nested monos.
I agree this change has gotten a lot more complex than anticipated and we shouldn't try and rush it into the release on the day of code freeze.
04d253d to
79ed286
Compare
This adds the new Reentrancy field to the actor runtime config and perserves the Dapr-Reentrancy-Id header which is required for all reentrant calls. dapr#533
This commit adds unit tests and associated changes for supporting Actor Reentrancy in the Java SDK.
017224c to
2c695b4
Compare
Codecov Report
@@ Coverage Diff @@
## master #545 +/- ##
============================================
+ Coverage 80.75% 81.36% +0.61%
- Complexity 986 1058 +72
============================================
Files 88 94 +6
Lines 3039 3183 +144
Branches 332 353 +21
============================================
+ Hits 2454 2590 +136
- Misses 419 422 +3
- Partials 166 171 +5
Continue to review full report at Codecov.
|
artursouza
left a comment
There was a problem hiding this comment.
I saw some key points that we need to address before proceeding with this change.
@skyao @xiazuojie can we get some help from Alibaba in using Mono's context here?
| * @param invocationContext Additional information associated with this invocation. | ||
| * @return Asynchronous result with the Actor's response. | ||
| */ | ||
| Mono<byte[]> invoke(String actorType, |
There was a problem hiding this comment.
Is there a way to avoid adding this public method? This is a one way street and we cannot take it out afterwards. I am concerned because the new parameter is a workaround for the feature and not really needed to invoke the actor method if we could properly set the context.
| * @return this | ||
| */ | ||
| public ActorProxyBuilder<T> withActorRuntime(ActorRuntime actorRuntime) { | ||
| if (actorRuntime == null) { |
There was a problem hiding this comment.
This is not really required because the code handles null in the build() method.
| * @param actorClient Dapr client for Actor APIs. | ||
| */ | ||
| ActorProxyImpl(String actorType, ActorId actorId, DaprObjectSerializer serializer, ActorClient actorClient) { | ||
| this(actorType, actorId, serializer, actorClient, ActorRuntime.getInstance()); |
There was a problem hiding this comment.
This is a little bit odd because it adds a dependency between the client (ActorProxy) and the server (ActorRuntime). An actor client does not need to register any of the actors in the runtime.
| String actorId, | ||
| String methodName, | ||
| byte[] jsonPayload, | ||
| ActorInvocationContext invocationContext) { |
There was a problem hiding this comment.
Does it mean that reentrancy still remain to be implemented for gRPC?
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class ActorInvocationContext { |
There was a problem hiding this comment.
This looks a lot like the Context from Mono.
| }).thenReturn(true); | ||
| } | ||
|
|
||
| Mono<Optional<String>> getReentrancyId(String actorId, String actorType) { |
There was a problem hiding this comment.
No need to use Mono if values are "static".
| .flatMap(r -> actor.onPostActorMethodInternal(context).thenReturn(r)) | ||
| .onErrorMap(throwable -> { | ||
| actor.rollback(); | ||
| actor.rollback(context); |
There was a problem hiding this comment.
Why is this needed? Does it break telemetry?
| * @param reentrancyId Id used to match reentrant requests. | ||
| * @return Response for the actor method. | ||
| */ | ||
| public Mono<byte[]> invoke(String actorTypeName, |
There was a problem hiding this comment.
Again, another public method that will force us to keep supporting this, while passing context as a param instead of using Mono's context.
There was a problem hiding this comment.
Hi all,
This PR is a beutiful one 👍 and is coming with some super nice additions to the actors.
However, it looks like it is a bit stale atm. @halspang @skyao @xiazuojie , any chance that you
can look into Arthurs comments?
Thanks in advance and have a nice weekend!
From a Dapr Java-SDK user :-)
/Dan
|
ping @halspang |
|
@halspang If you are not planning to work on this right now then feel free to assign it to me. I would like to continue on this. |
|
gentle ping - @halspang |
|
This hasn't been a priority for a while. It was discussed offline, but never here that others would take over this work. I'm not sure where that ended up or if they need this PR open anymore. Given how old this is, it's probably best to close the PR and start a new one with whoever decided to take this over. |
|
@pravinpushkar - if you are interested in adding this change to the java-sdk, please open up a follow up PR with the changes for this. I think we can close this one given @halspang's comment. |
Description
This adds the new Reentrancy field to the actor runtime config
and perserves the Dapr-Reentrancy-Id header which is required for
all reentrant calls.
Future Updates
Issue reference
Please reference the issue this PR will close: #533
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: