Skip to content
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

Implement service-level payload #11517

Merged
merged 11 commits into from
Mar 2, 2023
Merged

Implement service-level payload #11517

merged 11 commits into from
Mar 2, 2023

Conversation

mytang0
Copy link
Member

@mytang0 mytang0 commented Feb 9, 2023

What is the purpose of the change

Implement service-level payload. Issue #10773

Brief changelog

Verifying this change

Checklist

  • Make sure there is a GitHub_issue field for the change (usually before you start working on it). Trivial changes like typos do not require a GitHub issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.

  • Each commit in the pull request should have a meaningful subject line and body.

  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.

  • Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7

  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.

  • Add some description to dubbo-website project if you are requesting to add a feature.

  • GitHub Actions works fine on your own branch.

  • If this contribution is large, please follow the Software Donation Guide.

@mytang0 mytang0 changed the title Implement service-level payload. Implement service-level payload Feb 9, 2023
@codecov-commenter
Copy link

codecov-commenter commented Feb 9, 2023

Codecov Report

Merging #11517 (68f37e8) into 3.2 (638b193) will increase coverage by 0.04%.
The diff coverage is n/a.

@@             Coverage Diff              @@
##                3.2   #11517      +/-   ##
============================================
+ Coverage     69.34%   69.39%   +0.04%     
  Complexity        2        2              
============================================
  Files          1452     1452              
  Lines         61350    61382      +32     
  Branches       9056     9060       +4     
============================================
+ Hits          42542    42593      +51     
+ Misses        14630    14624       -6     
+ Partials       4178     4165      -13     
Impacted Files Coverage Δ
.../registry/zookeeper/ZookeeperServiceDiscovery.java 70.51% <0.00%> (-3.85%) ⬇️
.../dubbo/monitor/support/AbstractMonitorFactory.java 80.00% <0.00%> (-3.34%) ⬇️
...org/apache/dubbo/config/AbstractServiceConfig.java 94.25% <0.00%> (-2.18%) ⬇️
...bo/rpc/cluster/support/AbstractClusterInvoker.java 80.92% <0.00%> (-0.66%) ⬇️
...ubbo/config/deploy/DefaultApplicationDeployer.java 74.06% <0.00%> (-0.36%) ⬇️
...java/org/apache/dubbo/rpc/cluster/RouterChain.java 80.28% <0.00%> (ø)
...n/java/org/apache/dubbo/common/utils/NetUtils.java 66.84% <0.00%> (+0.26%) ⬆️
...exchange/support/header/HeaderExchangeChannel.java 83.01% <0.00%> (+0.32%) ⬆️
...mon/src/main/java/org/apache/dubbo/common/URL.java 52.02% <0.00%> (+0.43%) ⬆️
...va/org/apache/dubbo/remoting/exchange/Request.java 94.91% <0.00%> (+0.47%) ⬆️
... and 16 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@mytang0 mytang0 requested a review from AlbumenJ February 10, 2023 08:20
Copy link
Member

@wxbty wxbty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a payload to the request at the communication layer is unnecessary and risky. The verification of the payload is in the following fragment. The payload itself is obtained through the url. We may modify the corresponding value in the current url through filter or other interception.

protected static int getPayload(Channel channel) {
    if (channel != null && channel.getUrl() != null) {
        return channel.getUrl().getParameter(Constants.PAYLOAD_KEY, Constants.DEFAULT_PAYLOAD);
    }
    return Constants.DEFAULT_PAYLOAD;
}

@mytang0
Copy link
Member Author

mytang0 commented Feb 11, 2023

Adding a payload to the request at the communication layer is unnecessary and risky. The verification of the payload is in the following fragment. The payload itself is obtained through the url. We may modify the corresponding value in the current url through filter or other interception.

protected static int getPayload(Channel channel) {
    if (channel != null && channel.getUrl() != null) {
        return channel.getUrl().getParameter(Constants.PAYLOAD_KEY, Constants.DEFAULT_PAYLOAD);
    }
    return Constants.DEFAULT_PAYLOAD;
}

I am thinking about the following:

  1. Channel is shared, so modifying it is complicated and risky
  2. Channel's URL payload is a protocol payload
  3. The payload property of Request is not passed over the network , so it will not increase network overhead and affect the packaging and unpacking of messages

@mytang0 mytang0 requested review from wxbty and removed request for AlbumenJ February 11, 2023 05:57
@wxbty
Copy link
Member

wxbty commented Feb 11, 2023

channel.getUrl() The attributes here come from app-config, service-config and other external configurations, so at least they are shared at the service level.
Since the parameters are obtained from the url, maybe we can achieve the payload configuration at the service level without doing anything. As the following example:

@DubboService(parameters = {"payload", "3000"})
public class GameServiceImpl2 implements GameService {
    public String play(String name) {
        return "hello 2181:" + name;
    }
}

image

@wxbty
Copy link
Member

wxbty commented Feb 11, 2023

The configuration of parameters parameters may not be obvious to users, so it should be necessary to add attributes to @DubboService

@mytang0
Copy link
Member Author

mytang0 commented Feb 13, 2023

Thank you very much for your suggestion. It is true that the solution you suggested is the best implementation when the channel is not shared. Consumers share channels through provider address (host + port), each channel holds the url of the service that created it. Therefore, in the sharing mode, it cannot be guaranteed that the payload obtained through the channel is accurate.

@mytang0 mytang0 requested review from AlbumenJ and removed request for wxbty February 13, 2023 06:57
@wxbty
Copy link
Member

wxbty commented Feb 13, 2023

/**
 * Get dubbo channel by netty channel through channel cache.
 * Put netty channel into it if dubbo channel don't exist in the cache.
 *
 * @param ch      netty channel
 * @param url
 * @param handler dubbo handler that contain netty's handler
 * @return
 */
static NettyChannel getOrAddChannel(Channel ch, URL url, ChannelHandler handler) {
    if (ch == null) {
        return null;
    }
    NettyChannel ret = CHANNEL_MAP.get(ch);
    if (ret == null) {
        NettyChannel nettyChannel = new NettyChannel(ch, url, handler);
        if (ch.isActive()) {
            nettyChannel.markActive(true);
            ret = CHANNEL_MAP.putIfAbsent(ch, nettyChannel);
        }
        if (ret == null) {
            ret = nettyChannel;
        }
    } else {
        ret.markActive(true);
    }
    return ret;
}

@AlbumenJ NettyChannel seems to have a bug here. The key of CHANNEL_MAP is indeed the original channel of netty, and the url is not included, which means that when calling service2, the channel(created by first service) obtained contains the url of service1. The same goes for actual testing. Maybe we can solve it like this: the key of CHANNEL_MAP uses Channel+url instead of Channel

@mytang0
Copy link
Member Author

mytang0 commented Feb 13, 2023

private List<ReferenceCountExchangeClient> getSharedClient(URL url, int connectNum) {

        String key = url.getAddress();

        Object clients = referenceClientMap.get(key);
        if (clients instanceof List) {
            List<ReferenceCountExchangeClient> typedClients = (List<ReferenceCountExchangeClient>) clients;
            if (checkClientCanUse(typedClients)) {
                batchClientRefIncr(typedClients);
                return typedClients;
            }
        }
        ......
}

In this place, cause the url may already be inaccurate. I think Url is used as a property container, and the remoting layer mainly transmits the configuration properties of the remoting layer. Therefore, when dealing with sharing, Url seems to be less important.

@AlbumenJ
Copy link
Member

/**
 * Get dubbo channel by netty channel through channel cache.
 * Put netty channel into it if dubbo channel don't exist in the cache.
 *
 * @param ch      netty channel
 * @param url
 * @param handler dubbo handler that contain netty's handler
 * @return
 */
static NettyChannel getOrAddChannel(Channel ch, URL url, ChannelHandler handler) {
    if (ch == null) {
        return null;
    }
    NettyChannel ret = CHANNEL_MAP.get(ch);
    if (ret == null) {
        NettyChannel nettyChannel = new NettyChannel(ch, url, handler);
        if (ch.isActive()) {
            nettyChannel.markActive(true);
            ret = CHANNEL_MAP.putIfAbsent(ch, nettyChannel);
        }
        if (ret == null) {
            ret = nettyChannel;
        }
    } else {
        ret.markActive(true);
    }
    return ret;
}

@AlbumenJ NettyChannel seems to have a bug here. The key of CHANNEL_MAP is indeed the original channel of netty, and the url is not included, which means that when calling service2, the channel(created by first service) obtained contains the url of service1. The same goes for actual testing. Maybe we can solve it like this: the key of CHANNEL_MAP uses Channel+url instead of Channel

We should prevent to get parameters from channel url. Channel should be shared among services.

@CrazyHZM
Copy link
Member

@mytang0 Regarding the payload configuration of this service level, is it possible to bind different services to different protocol configs to achieve the purpose?

@mytang0
Copy link
Member Author

mytang0 commented Feb 16, 2023

@mytang0 Regarding the payload configuration of this service level, is it possible to bind different services to different protocol configs to achieve the purpose?

Yes, it can be achieved by adding channels, but there is a little violation of channel sharing.

* mytang0/3.2: (33 commits)
  Fix conflict
  Update codecov config (apache#11580)
  Set timeout value to string (apache#11565)
  Skip mapping retry if metadata config is invalid (apache#11323)
  Fix stackoverflow in SerializeSecurityConfigurator (apache#11561)
  Revert clear response operation of timeoutfilter (apache#11562)
  Fix hessian2 serializable check (apache#11573)
  feat: fix oom (apache#11571)
  Enhance service discovery update interval (apache#11223)
  Metrics code opt: redundant, modifier, magic (apache#11553)
  Perfect some code (apache#11533)
  feat: dubbo provided by (apache#11390)
  Enhance serializable check option (apache#11460)
  Fix config absent when refresh (apache#11505)
  Enhance json util check (apache#11501)
  Fix the bug in LFUCache#put() method (apache#11538)
  Bump maven-assembly-plugin from 3.1.0 to 3.4.2 (apache#11547)
  Bump consul-api from 1.4.2 to 1.4.5 (apache#11545)
  Bump maven-core from 3.8.7 to 3.9.0 (apache#11546)
  Bump bytebuddy.version from 1.12.22 to 1.13.0 (apache#11548)
  ...

# Conflicts:
#	dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java
@mytang0 mytang0 requested review from CrazyHZM and removed request for AlbumenJ and chickenlj February 16, 2023 06:05
@mytang0
Copy link
Member Author

mytang0 commented Feb 16, 2023

PTAL @chickenlj

* origin/3.2: (32 commits)
  dubbo-security Jackson error (apache#11622)
  sync meter to spring boot management (apache#11630)
  Rest bugfix & optimization (apache#11617)
  Observability task: metadata center (apache#11593)
  Enhance the way to get dubbo version (apache#11574)
  Bump protobuf-java from 3.21.12 to 3.22.0 (apache#11615)
  Bump maven-surefire-plugin from 3.0.0-M8 to 3.0.0-M9 (apache#11613)
  Bump micrometer-bom from 1.10.3 to 1.10.4 (apache#11611)
  Bump libthrift from 0.17.0 to 0.18.0 (apache#11614)
  Bump maven-failsafe-plugin from 3.0.0-M8 to 3.0.0-M9 (apache#11612)
  Bump reactor-core from 3.5.2 to 3.5.3 (apache#11610)
  Bump byte-buddy from 1.13.0 to 1.14.0 (apache#11609)
  Bump maven-javadoc-plugin from 3.4.1 to 3.5.0 (apache#11608)
  Bump micrometer-tracing-bom from 1.0.1 to 1.0.2 (apache#11607)
  3.2 consumer proxy invocation handler (apache#11108)
  Update DubboReference.java (apache#11621)
  Bump version to 3.1.8-SNAPSHOT
  Add Consumer Metrics (apache#11542)
  Backport of remove apache-rat-plugin. (apache#11523) (apache#11592)
  Update codecov config (apache#11582)
  ...
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

75.5% 75.5% Coverage
0.0% 0.0% Duplication

@AlbumenJ AlbumenJ requested a review from chickenlj February 25, 2023 09:44
Copy link
Contributor

@chickenlj chickenlj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@mytang0 mytang0 requested review from AlbumenJ and removed request for CrazyHZM February 28, 2023 01:48
@AlbumenJ AlbumenJ merged commit a293e7e into apache:3.2 Mar 2, 2023
@mytang0 mytang0 mentioned this pull request Mar 22, 2023
8 tasks
lcb11 pushed a commit to lcb11/dubbo that referenced this pull request Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants