GitHub user vio-lin edited a discussion: [Q/A][Java SDK (Component)] Should 
RpcInvocation attribute reused in MergeableCluster

### Pre-check

- [X] I am sure that all the content I provide is in English.


### Apache Dubbo Component

Java SDK (apache/dubbo)

### Details

In my case, i need some thing to pass concurrency counter from request to 
response.    

```mermaid
graph TB
  subgraph sync_same_reference
    A[request1] -->|concurrency +1| B[invoker1]
    B --> |concurrency -1|C[request2]
    C-->|currency+1|D[invoker2]
    D-->|currency-1|E[reference]
  end

  subgraph async
    D[request1] -->|concurrency +1| E[invoker1]
    H[request2] -->|concurrency +1| I[invoker2]
    F[response1] --> |concurrency -1|G[Reference]
    J[response2] --> |concurrency -1|K[Reference]
  end
```

i use invocation.attribute to save this concurrencyCounter.   
it work well in almost case. but in case 'MergeableClusterInvoker'  

org.apache.dubbo.rpc.cluster.support.MergeableClusterInvoker#doInvoke
```java
Map<String, Result> results = new HashMap<>();
        for (final Invoker<T> invoker : invokers) {
            RpcInvocation subInvocation = new RpcInvocation(invocation, 
invoker);
            subInvocation.setAttachment(Constants.ASYNC_KEY, "true");
            try {
                results.put(invoker.getUrl().getServiceKey(), 
invokeWithContext(invoker, subInvocation));
            } catch (RpcException
```
as invocation reused attribute, the [last] async call back response may 
decrease concurrency count for [next] request.  

org.apache.dubbo.rpc.cluster.support.BroadcastClusterInvoker#doInvoke create 
attribte by it self.
```java
 try {
                RpcInvocation subInvocation = new RpcInvocation(
                        invocation.getTargetServiceUniqueName(),
                        invocation.getServiceModel(),
                        invocation.getMethodName(),
                        invocation.getServiceName(),
                        invocation.getProtocolServiceKey(),
                        invocation.getParameterTypes(),
                        invocation.getArguments(),
                        invocation.copyObjectAttachments(),
                        invocation.getInvoker(),
                        Collections.synchronizedMap(new 
HashMap<>(invocation.getAttributes())),
                        invocation instanceof RpcInvocation ? ((RpcInvocation) 
invocation).getInvokeMode() : null);
```

some similar use case in 
`org.apache.dubbo.rpc.filter.ActiveLimitFilter#getElapsed`  may encounter same 
problem.    

should it use an other api for pass attribute or optimise rpcInvokcation 
recreate logic  


### Code of Conduct

- [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)


GitHub link: https://github.com/apache/dubbo/discussions/15427

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to