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

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


The following commit(s) were added to refs/heads/3.2 by this push:
     new 9577d464a0 Triple set resolve fallback enable as default (#12575)
9577d464a0 is described below

commit 9577d464a092596085bdc8f7c78ea3f482767246
Author: Albumen Kevin <[email protected]>
AuthorDate: Wed Jun 21 13:22:27 2023 +0800

    Triple set resolve fallback enable as default (#12575)
    
    * Triple set resolve fallback enable as default
    
    * use throw
---
 .../java/org/apache/dubbo/rpc/PathResolver.java    |  4 +++-
 .../dubbo/rpc/protocol/tri/TriplePathResolver.java |  9 +++++--
 .../dubbo/rpc/protocol/tri/TripleProtocol.java     | 28 ++++++++++++++++++----
 3 files changed, 33 insertions(+), 8 deletions(-)

diff --git 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/PathResolver.java 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/PathResolver.java
index c3e910a56d..83c5979cb8 100644
--- 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/PathResolver.java
+++ 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/PathResolver.java
@@ -27,7 +27,9 @@ import org.apache.dubbo.common.extension.SPI;
 @SPI(value = CommonConstants.TRIPLE, scope = ExtensionScope.FRAMEWORK)
 public interface PathResolver {
 
-    void add(String path, Invoker<?> invoker);
+    Invoker<?> add(String path, Invoker<?> invoker);
+
+    Invoker<?> addIfAbsent(String path, Invoker<?> invoker);
 
     Invoker<?> resolve(String path);
 
diff --git 
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriplePathResolver.java
 
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriplePathResolver.java
index a508e936cf..f3f9ebbc68 100644
--- 
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriplePathResolver.java
+++ 
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriplePathResolver.java
@@ -28,8 +28,13 @@ public class TriplePathResolver implements PathResolver {
     private final ConcurrentHashMap<String, Object> nativeStub = new 
ConcurrentHashMap<>();
 
     @Override
-    public void add(String path, Invoker<?> invoker) {
-        path2Invoker.put(path, invoker);
+    public Invoker<?> add(String path, Invoker<?> invoker) {
+        return path2Invoker.put(path, invoker);
+    }
+
+    @Override
+    public Invoker<?> addIfAbsent(String path, Invoker<?> invoker) {
+        return path2Invoker.putIfAbsent(path, invoker);
     }
 
     @Override
diff --git 
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java
 
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java
index 49650083be..4ec09e4a56 100644
--- 
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java
+++ 
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java
@@ -44,9 +44,9 @@ import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.ExecutorService;
 
+import static org.apache.dubbo.config.Constants.SERVER_THREAD_POOL_NAME;
 import static org.apache.dubbo.rpc.Constants.H2_IGNORE_1_0_0_KEY;
 import static 
org.apache.dubbo.rpc.Constants.H2_RESOLVE_FALLBACK_TO_DEFAULT_KEY;
-import static org.apache.dubbo.config.Constants.SERVER_THREAD_POOL_NAME;
 import static org.apache.dubbo.rpc.Constants.H2_SUPPORT_NO_LOWER_HEADER_KEY;
 
 public class TripleProtocol extends AbstractProtocol {
@@ -65,7 +65,7 @@ public class TripleProtocol extends AbstractProtocol {
 
     public static boolean IGNORE_1_0_0_VERSION = false;
 
-    public static boolean RESOLVE_FALLBACK_TO_DEFAULT = false;
+    public static boolean RESOLVE_FALLBACK_TO_DEFAULT = true;
 
     public TripleProtocol(FrameworkModel frameworkModel) {
         this.frameworkModel = frameworkModel;
@@ -77,7 +77,7 @@ public class TripleProtocol extends AbstractProtocol {
         IGNORE_1_0_0_VERSION = 
ConfigurationUtils.getEnvConfiguration(ApplicationModel.defaultModel())
             .getBoolean(H2_IGNORE_1_0_0_KEY, false);
         RESOLVE_FALLBACK_TO_DEFAULT = 
ConfigurationUtils.getEnvConfiguration(ApplicationModel.defaultModel())
-            .getBoolean(H2_RESOLVE_FALLBACK_TO_DEFAULT_KEY, false);
+            .getBoolean(H2_RESOLVE_FALLBACK_TO_DEFAULT_KEY, true);
         Set<String> supported = 
frameworkModel.getExtensionLoader(DeCompressor.class)
             .getSupportedExtensions();
         this.acceptEncodings = String.join(",", supported);
@@ -113,9 +113,27 @@ public class TripleProtocol extends AbstractProtocol {
 
         invokers.add(invoker);
 
-        pathResolver.add(url.getServiceKey(), invoker);
+        Invoker<?> previous = pathResolver.add(url.getServiceKey(), invoker);
+        if (previous != null) {
+            if 
(url.getServiceKey().equals(url.getServiceModel().getServiceModel().getInterfaceName()))
 {
+                logger.info("Already exists an invoker[" + previous.getUrl() + 
"] on path[" + url.getServiceKey()
+                    + "], dubbo will override with invoker[" + url + "]");
+            } else {
+                throw new IllegalStateException("Already exists an invoker[" + 
previous.getUrl() + "] on path[" +
+                    url.getServiceKey() + "], failed to add invoker[" + url +
+                    "] , please use unique serviceKey.");
+            }
+        }
         if (RESOLVE_FALLBACK_TO_DEFAULT) {
-            
pathResolver.add(url.getServiceModel().getServiceModel().getInterfaceName(), 
invoker);
+            previous = 
pathResolver.addIfAbsent(url.getServiceModel().getServiceModel().getInterfaceName(),
 invoker);
+            if (previous != null) {
+                logger.info("Already exists an invoker[" + previous.getUrl() + 
"] on path[" +
+                    url.getServiceModel().getServiceModel().getInterfaceName() 
+
+                    "], dubbo will skip override with invoker[" + url + "]");
+            } else {
+                logger.info("Add fallback triple invoker[" + url + "] to 
path[" +
+                    url.getServiceModel().getServiceModel().getInterfaceName() 
+ "] with invoker[" + url + "]");
+            }
         }
 
         // set service status

Reply via email to