You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "ShenFeng312 (via GitHub)" <gi...@apache.org> on 2023/04/20 01:49:07 UTC

[GitHub] [dubbo] ShenFeng312 opened a new pull request, #12140: Fix #10681 Support dynamic cluster

ShenFeng312 opened a new pull request, #12140:
URL: https://github.com/apache/dubbo/pull/12140

   ## What is the purpose of the change
   
   
   
   ## Brief changelog
   
   
   ## Verifying this change
   
   
   <!-- Follow this checklist to help us incorporate your contribution quickly and easily: -->
   
   ## Checklist
   - [x] Make sure there is a [GitHub_issue](https://github.com/apache/dubbo/issues) 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](https://github.com/apache/dubbo-samples) project.
   - [ ] Add some description to [dubbo-website](https://github.com/apache/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](https://github.com/apache/dubbo/wiki/Software-donation-guide).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #12140: Fix #10681 Support dynamic cluster

Posted by "AlbumenJ (via GitHub)" <gi...@apache.org>.
AlbumenJ commented on code in PR #12140:
URL: https://github.com/apache/dubbo/pull/12140#discussion_r1176054828


##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/DynamicClusterInvoker.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dubbo.rpc.cluster.support;
+
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.Directory;
+import org.apache.dubbo.rpc.cluster.LoadBalance;
+import org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CLUSTER_KEY;
+
+public class DynamicClusterInvoker<T> extends AbstractClusterInvoker<T> {
+
+    private final Function<String, AbstractCluster> builder;
+
+
+    private final Map<String, AbstractClusterInvoker<T>> clusterInvokerMap = new ConcurrentHashMap<>();
+
+    public DynamicClusterInvoker(Directory<T> directory, Function<String, AbstractCluster> clusterBuilder) {
+        super(directory);
+        this.builder = clusterBuilder;
+    }
+
+
+    @Override
+    protected Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
+        String cluster;
+        cluster = invocation.getAttachment(CLUSTER_KEY);
+
+        if (StringUtils.isEmpty(cluster)) {
+            cluster = RpcContext.getServiceContext().getConsumerUrl().getMethodParameter(invocation.getMethodName(), CLUSTER_KEY);
+        }
+        if (StringUtils.isEmpty(cluster)) {
+            cluster = RpcContext.getServiceContext().getConsumerUrl().getParameter(DEFAULT_CLUSTER_KEY);
+        }
+
+        String finalCluster = cluster;
+        AbstractClusterInvoker<T> abstractClusterInvoker = clusterInvokerMap.computeIfAbsent(cluster,
+            (key) -> (AbstractClusterInvoker<T>) builder.apply(finalCluster).join(directory, false));

Review Comment:
   Can we just add a wrapper like adaptive extension? Do not create cluster impl on runtime.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] ShenFeng312 commented on pull request #12140: Fix #10681 Support dynamic cluster

Posted by "ShenFeng312 (via GitHub)" <gi...@apache.org>.
ShenFeng312 commented on PR #12140:
URL: https://github.com/apache/dubbo/pull/12140#issuecomment-1519511262

   > ![image](https://user-images.githubusercontent.com/9292748/233311936-7f9de4a7-4e9f-4212-af45-3630abf6ab4c.png) Please fix failed test cases
   
   fixed


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] ShenFeng312 commented on a diff in pull request #12140: Fix #10681 Support dynamic cluster

Posted by "ShenFeng312 (via GitHub)" <gi...@apache.org>.
ShenFeng312 commented on code in PR #12140:
URL: https://github.com/apache/dubbo/pull/12140#discussion_r1179871731


##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/DynamicClusterInvoker.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dubbo.rpc.cluster.support;
+
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.Directory;
+import org.apache.dubbo.rpc.cluster.LoadBalance;
+import org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CLUSTER_KEY;
+
+public class DynamicClusterInvoker<T> extends AbstractClusterInvoker<T> {
+
+    private final Function<String, AbstractCluster> builder;
+
+
+    private final Map<String, AbstractClusterInvoker<T>> clusterInvokerMap = new ConcurrentHashMap<>();
+
+    public DynamicClusterInvoker(Directory<T> directory, Function<String, AbstractCluster> clusterBuilder) {
+        super(directory);
+        this.builder = clusterBuilder;
+    }
+
+
+    @Override
+    protected Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
+        String cluster;
+        cluster = invocation.getAttachment(CLUSTER_KEY);
+
+        if (StringUtils.isEmpty(cluster)) {
+            cluster = RpcContext.getServiceContext().getConsumerUrl().getMethodParameter(invocation.getMethodName(), CLUSTER_KEY);
+        }
+        if (StringUtils.isEmpty(cluster)) {
+            cluster = RpcContext.getServiceContext().getConsumerUrl().getParameter(DEFAULT_CLUSTER_KEY);
+        }
+
+        String finalCluster = cluster;
+        AbstractClusterInvoker<T> abstractClusterInvoker = clusterInvokerMap.computeIfAbsent(cluster,
+            (key) -> (AbstractClusterInvoker<T>) builder.apply(finalCluster).join(directory, false));

Review Comment:
   想了想要改成adaptive 的话 需要把 之前的cluster 实现改造掉。 并且解开ClusterInvoker和directory的直接依赖 改为通过参数传递的方式。因为getExtension和getActivateExtension都不支持带参数的构造函数



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] codecov-commenter commented on pull request #12140: Fix #10681 Support dynamic cluster

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #12140:
URL: https://github.com/apache/dubbo/pull/12140#issuecomment-1516177161

   ## [Codecov](https://codecov.io/gh/apache/dubbo/pull/12140?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#12140](https://codecov.io/gh/apache/dubbo/pull/12140?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (a218f5d) into [3.2](https://codecov.io/gh/apache/dubbo/commit/d6f9d8d38fb6ac804cb8375f4770079337279538?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (d6f9d8d) will **decrease** coverage by `0.37%`.
   > The diff coverage is `n/a`.
   
   ```diff
   @@             Coverage Diff              @@
   ##                3.2   #12140      +/-   ##
   ============================================
   - Coverage     69.94%   69.57%   -0.37%     
   + Complexity      341        2     -339     
   ============================================
     Files          3403     1595    -1808     
     Lines        159313    65440   -93873     
     Branches      26427     9527   -16900     
   ============================================
   - Hits         111429    45530   -65899     
   + Misses        38217    15531   -22686     
   + Partials       9667     4379    -5288     
   ```
   
   
   [see 1862 files with indirect coverage changes](https://codecov.io/gh/apache/dubbo/pull/12140/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] sonarcloud[bot] commented on pull request #12140: Fix #10681 Support dynamic cluster

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #12140:
URL: https://github.com/apache/dubbo/pull/12140#issuecomment-1516166169

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_dubbo&pullRequest=12140)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=12140&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=12140&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=12140&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=12140&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=12140&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=12140&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=12140&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=12140&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=12140&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=12140&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=12140&resolved=false&types=CODE_SMELL) [5 Code Smells](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=12140&resolved=false&types=CODE_SMELL)
   
   [![74.5%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png '74.5%')](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=12140&metric=new_coverage&view=list) [74.5% Coverage](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=12140&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=12140&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=12140&metric=new_duplicated_lines_density&view=list)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org