This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.1 by this push:
     new 8663a12ca2 feat: add unloadClusterRelated in ReferenceConfig which can 
uninstall the directory, router and load balance related to the cluster (#10498)
8663a12ca2 is described below

commit 8663a12ca27df3bc94345e1f1f8c12e1c8fcc71b
Author: conghuhu <[email protected]>
AuthorDate: Sat Aug 27 17:07:12 2022 +0800

    feat: add unloadClusterRelated in ReferenceConfig which can uninstall the 
directory, router and load balance related to the cluster (#10498)
---
 .../apache/dubbo/common/constants/CommonConstants.java   |  5 +++++
 .../org/apache/dubbo/config/ReferenceConfigBase.java     | 16 ++++++++++++++++
 .../apache/dubbo/config/annotation/DubboReference.java   |  8 ++++++++
 .../java/org/apache/dubbo/config/ReferenceConfig.java    |  7 ++++++-
 .../src/main/resources/META-INF/compat/dubbo.xsd         |  8 ++++++++
 .../src/main/resources/META-INF/dubbo.xsd                |  8 ++++++++
 6 files changed, 51 insertions(+), 1 deletion(-)

diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
 
b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
index eb8643cb2b..321d8e2fb5 100644
--- 
a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
+++ 
b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
@@ -570,4 +570,9 @@ public interface CommonConstants {
      */
     String DEFAULT_CLUSTER_DOMAIN = "cluster.local";
 
+    /**
+     * @since 3.1.0
+     */
+    String UNLOAD_CLUSTER_RELATED = "unloadClusterRelated";
+
 }
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java 
b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java
index 73a668a834..7d7e2417b7 100644
--- 
a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java
+++ 
b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java
@@ -38,6 +38,7 @@ import java.util.Map;
 import java.util.Properties;
 
 import static org.apache.dubbo.common.constants.CommonConstants.DUBBO;
+import static 
org.apache.dubbo.common.constants.CommonConstants.UNLOAD_CLUSTER_RELATED;
 
 /**
  * ReferenceConfig
@@ -66,6 +67,12 @@ public abstract class ReferenceConfigBase<T> extends 
AbstractReferenceConfig {
      */
     protected ConsumerConfig consumer;
 
+    /**
+     * In the mesh mode, uninstall the directory, router and load balance 
related to the cluster in the currently invoked invoker.
+     * Delegate retry, load balancing, timeout and other traffic management 
capabilities to Sidecar.
+     */
+    protected Boolean unloadClusterRelated;
+
     public ReferenceConfigBase() {
         serviceMetadata = new ServiceMetadata();
         serviceMetadata.addAttribute(ORIGIN_CONFIG, this);
@@ -257,6 +264,15 @@ public abstract class ReferenceConfigBase<T> extends 
AbstractReferenceConfig {
         this.consumer = consumer;
     }
 
+    @Parameter(key = UNLOAD_CLUSTER_RELATED)
+    public Boolean getUnloadClusterRelated() {
+        return unloadClusterRelated;
+    }
+
+    public void setUnloadClusterRelated(Boolean unloadClusterRelated) {
+        this.unloadClusterRelated = unloadClusterRelated;
+    }
+
     public ServiceMetadata getServiceMetadata() {
         return serviceMetadata;
     }
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/config/annotation/DubboReference.java
 
b/dubbo-common/src/main/java/org/apache/dubbo/config/annotation/DubboReference.java
index e33797e9b1..10afb4f6c9 100644
--- 
a/dubbo-common/src/main/java/org/apache/dubbo/config/annotation/DubboReference.java
+++ 
b/dubbo-common/src/main/java/org/apache/dubbo/config/annotation/DubboReference.java
@@ -368,4 +368,12 @@ public @interface DubboReference {
      * Weather the reference is refer asynchronously
      */
     boolean referAsync() default false;
+
+    /**
+     * unload Cluster related in mesh mode
+     *
+     * @see ReferenceConfigBase#unloadClusterRelated
+     * @since 3.1.0
+     */
+    boolean unloadClusterRelated() default false;
 }
diff --git 
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
 
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
index 8dd76c073a..8749a4668d 100644
--- 
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
+++ 
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
@@ -81,6 +81,7 @@ import static 
org.apache.dubbo.common.constants.CommonConstants.SEMICOLON_SPLIT_
 import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.SVC;
 import static org.apache.dubbo.common.constants.CommonConstants.TRIPLE;
+import static 
org.apache.dubbo.common.constants.CommonConstants.UNLOAD_CLUSTER_RELATED;
 import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDED_BY;
 import static 
org.apache.dubbo.common.constants.RegistryConstants.SUBSCRIBED_SERVICE_NAMES_KEY;
 import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost;
@@ -505,6 +506,8 @@ public class ReferenceConfig<T> extends 
ReferenceConfigBase<T> {
      */
     private boolean checkMeshConfig(Map<String, String> referenceParameters) {
         if (!"true".equals(referenceParameters.getOrDefault(MESH_ENABLE, 
"false"))) {
+            // In mesh mode, unloadClusterRelated can only be false.
+            referenceParameters.put(UNLOAD_CLUSTER_RELATED, "false");
             return false;
         }
 
@@ -598,7 +601,9 @@ public class ReferenceConfig<T> extends 
ReferenceConfigBase<T> {
         if (urls.size() == 1) {
             URL curUrl = urls.get(0);
             invoker = protocolSPI.refer(interfaceClass, curUrl);
-            if (!UrlUtils.isRegistry(curUrl)) {
+            // registry url, mesh-enable and unloadClusterRelated is true, not 
need Cluster.
+            if (!UrlUtils.isRegistry(curUrl) &&
+                    !curUrl.getParameter(UNLOAD_CLUSTER_RELATED, false)) {
                 List<Invoker<?>> invokers = new ArrayList<>();
                 invokers.add(invoker);
                 invoker = Cluster.getCluster(scopeModel, 
Cluster.DEFAULT).join(new StaticDirectory(curUrl, invokers), true);
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd 
b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd
index ed55e23fb4..99b34ee817 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd
+++ 
b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd
@@ -1070,6 +1070,14 @@
                         <xsd:documentation><![CDATA[ The service protocol. 
]]></xsd:documentation>
                     </xsd:annotation>
                 </xsd:attribute>
+                <xsd:attribute name="unloadClusterRelated" type="xsd:boolean">
+                    <xsd:annotation>
+                        <xsd:documentation>
+                            <![CDATA[ In the mesh mode, uninstall the 
directory, router and load balance related to the cluster in the currently 
invoked invoker.
+                            Delegate retry, load balancing, timeout and other 
traffic management capabilities to Sidecar. ]]>
+                        </xsd:documentation>
+                    </xsd:annotation>
+                </xsd:attribute>
                 <xsd:anyAttribute namespace="##other" processContents="lax"/>
             </xsd:extension>
         </xsd:complexContent>
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd 
b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd
index f2a38c4a9a..3af0886e65 100644
--- a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd
+++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd
@@ -1241,6 +1241,14 @@
                         </xsd:documentation>
                     </xsd:annotation>
                 </xsd:attribute>
+                <xsd:attribute name="unloadClusterRelated" type="xsd:boolean">
+                    <xsd:annotation>
+                        <xsd:documentation>
+                            <![CDATA[ In the mesh mode, uninstall the 
directory, router and load balance related to the cluster in the currently 
invoked invoker.
+                            Delegate retry, load balancing, timeout and other 
traffic management capabilities to Sidecar. ]]>
+                        </xsd:documentation>
+                    </xsd:annotation>
+                </xsd:attribute>
                 <xsd:anyAttribute namespace="##other" processContents="lax"/>
             </xsd:extension>
         </xsd:complexContent>

Reply via email to