You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2022/07/06 06:27:57 UTC

[dubbo] branch 3.1 updated (2e5941f879 -> 8a93fceed6)

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

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


    from 2e5941f879 [3.1] Fix group key in Nacos Service Discovery (#10253)
     new 3435872229 fix UnsupportedOperationException in invokeSetParameters (#10262)
     new 2dab2d7fdb [3.0] Fixed the problem that the service was offline for a long time without re-registration (#10200)
     new 90370b4bc2 [3.0] Fix dependencies pom hibernate version (#10270)
     new d82310292e Cancel availability check for NopServiceDiscovery (#10271)
     new 7e7fc2807c refactor: Modify the parameter validation log level to info (#10275)
     new fd48e1cc28 using guard clause to refactor CacheFilter (#10274)
     new 8a93fceed6 feat: remove the unnecessary class of SaveProperties and loadding Properties use try-resource (#10276)

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/dubbo/config/AbstractConfig.java    |  7 +++-
 dubbo-dependencies-bom/pom.xml                     |  1 +
 .../org/apache/dubbo/cache/filter/CacheFilter.java | 43 ++++++++++---------
 .../validation/support/jvalidation/JValidator.java |  2 +-
 .../support/jvalidation/JValidatorNew.java         |  2 +-
 .../registry/client/ServiceDiscoveryRegistry.java  |  8 +++-
 .../dubbo/registry/support/AbstractRegistry.java   | 49 +++++++---------------
 .../zookeeper/curator/CuratorZookeeperClient.java  | 40 +++++++++++++++++-
 8 files changed, 91 insertions(+), 61 deletions(-)


[dubbo] 02/07: [3.0] Fixed the problem that the service was offline for a long time without re-registration (#10200)

Posted by al...@apache.org.
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

commit 2dab2d7fdb69a7a391b377eb02fb8d92424819fb
Author: 一个不知名的Java靓仔 <cl...@gmail.com>
AuthorDate: Mon Jul 4 19:49:29 2022 +0800

    [3.0] Fixed the problem that the service was offline for a long time without re-registration (#10200)
    
    * 修复因网络抖动导致服务长时间下线没有重新注册的问题
    
    * lazy init CuratorWatcher executor and destroyed on shutdown
    
    * add lock on close
---
 .../zookeeper/curator/CuratorZookeeperClient.java  | 40 +++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java
index 975e10fd19..d1bbb5e960 100644
--- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java
+++ b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.config.configcenter.ConfigItem;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.utils.NamedThreadFactory;
 import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperClient;
 import org.apache.dubbo.remoting.zookeeper.ChildListener;
@@ -49,6 +50,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
 import static org.apache.dubbo.common.constants.CommonConstants.SESSION_KEY;
@@ -84,6 +87,7 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZooke
             if (!connected) {
                 throw new IllegalStateException("zookeeper not connected");
             }
+            CuratorWatcherImpl.closed = false;
         } catch (Exception e) {
             close();
             throw new IllegalStateException(e.getMessage(), e);
@@ -256,6 +260,13 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZooke
     public void doClose() {
         super.close();
         client.close();
+        CuratorWatcherImpl.closed = true;
+        synchronized (CuratorWatcherImpl.class) {
+            if (CuratorWatcherImpl.CURATOR_WATCHER_EXECUTOR_SERVICE != null) {
+                CuratorWatcherImpl.CURATOR_WATCHER_EXECUTOR_SERVICE.shutdown();
+                CuratorWatcherImpl.CURATOR_WATCHER_EXECUTOR_SERVICE = null;
+            }
+        }
     }
 
     @Override
@@ -354,10 +365,24 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZooke
 
     static class CuratorWatcherImpl implements CuratorWatcher {
 
+        private static volatile ExecutorService CURATOR_WATCHER_EXECUTOR_SERVICE;
+
+        private static volatile boolean closed = false;
+
         private CuratorFramework client;
         private volatile ChildListener childListener;
         private String path;
 
+        private static void initExecutorIfNecessary() {
+            if (!closed && CURATOR_WATCHER_EXECUTOR_SERVICE == null) {
+                synchronized (CuratorWatcherImpl.class) {
+                    if (!closed && CURATOR_WATCHER_EXECUTOR_SERVICE == null) {
+                        CURATOR_WATCHER_EXECUTOR_SERVICE = Executors.newSingleThreadExecutor(new NamedThreadFactory("Dubbo-CuratorWatcher"));
+                    }
+                }
+            }
+        }
+
         public CuratorWatcherImpl(CuratorFramework client, ChildListener listener, String path) {
             this.client = client;
             this.childListener = listener;
@@ -380,7 +405,20 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZooke
             }
 
             if (childListener != null) {
-                childListener.childChanged(path, client.getChildren().usingWatcher(this).forPath(path));
+                Runnable task = new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            childListener.childChanged(path, client.getChildren().usingWatcher(CuratorWatcherImpl.this).forPath(path));
+                        } catch (Exception e) {
+                            logger.warn("client get children error", e);
+                        }
+                    }
+                };
+                initExecutorIfNecessary();
+                if (!closed && CURATOR_WATCHER_EXECUTOR_SERVICE != null) {
+                    CURATOR_WATCHER_EXECUTOR_SERVICE.execute(task);
+                }
             }
         }
     }


[dubbo] 06/07: using guard clause to refactor CacheFilter (#10274)

Posted by al...@apache.org.
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

commit fd48e1cc28571f54f9177c7b8c55ee49055fe90b
Author: cheese8 <yi...@163.com>
AuthorDate: Wed Jul 6 10:24:05 2022 +0800

    using guard clause to refactor CacheFilter (#10274)
    
    * using guard clause to refactor CacheFilter
    
    * Update CacheFilter.java
---
 .../org/apache/dubbo/cache/filter/CacheFilter.java | 43 ++++++++++++----------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java
index 3122a8eee4..209776d3a5 100644
--- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java
+++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java
@@ -91,26 +91,31 @@ public class CacheFilter implements Filter {
      */
     @Override
     public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
-        if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), CACHE_KEY))) {
-            Cache cache = cacheFactory.getCache(invoker.getUrl(), invocation);
-            if (cache != null) {
-                String key = StringUtils.toArgumentString(invocation.getArguments());
-                Object value = cache.get(key);
-                if (value != null) {
-                    if (value instanceof ValueWrapper) {
-                        return AsyncRpcResult.newDefaultAsyncResult(((ValueWrapper) value).get(), invocation);
-                    } else {
-                        return AsyncRpcResult.newDefaultAsyncResult(value, invocation);
-                    }
-                }
-                Result result = invoker.invoke(invocation);
-                if (!result.hasException()) {
-                    cache.put(key, new ValueWrapper(result.getValue()));
-                }
-                return result;
-            }
+        if (cacheFactory == null || ConfigUtils.isEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), CACHE_KEY))) {
+            return invoker.invoke(invocation);
         }
-        return invoker.invoke(invocation);
+        Cache cache = cacheFactory.getCache(invoker.getUrl(), invocation);
+        if (cache == null) {
+            return invoker.invoke(invocation);
+        }
+        String key = StringUtils.toArgumentString(invocation.getArguments());
+        Object value = cache.get(key);
+        return (value != null) ? onCacheValuePresent(invocation, value) : onCacheValueNotPresent(invoker, invocation, cache, key);
+    }
+    
+    private Result onCacheValuePresent(Invocation invocation, Object value) {
+        if (value instanceof ValueWrapper) {
+            return AsyncRpcResult.newDefaultAsyncResult(((ValueWrapper) value).get(), invocation);
+        }
+        return AsyncRpcResult.newDefaultAsyncResult(value, invocation);
+    }
+    
+    private Result onCacheValueNotPresent(Invoker<?> invoker, Invocation invocation, Cache cache, String key) {
+        Result result = invoker.invoke(invocation);
+        if (!result.hasException()) {
+            cache.put(key, new ValueWrapper(result.getValue()));
+        }
+        return result;
     }
 
     /**


[dubbo] 01/07: fix UnsupportedOperationException in invokeSetParameters (#10262)

Posted by al...@apache.org.
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

commit 3435872229f0d015bcd64049d2f8a26bc07fd6c3
Author: cheese8 <yi...@163.com>
AuthorDate: Mon Jul 4 09:37:06 2022 +0800

    fix UnsupportedOperationException in invokeSetParameters (#10262)
    
    * fix UnsupportedOperationException 10257
    
    * Update AbstractConfig.java
    
    * Update AbstractConfig.java
---
 .../src/main/java/org/apache/dubbo/config/AbstractConfig.java      | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java
index 5d4ee5f1b4..d37f3e919f 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java
@@ -823,8 +823,11 @@ public abstract class AbstractConfig implements Serializable {
         if (CollectionUtils.isEmptyMap(values)) {
             return;
         }
-        Map<String, String> map = invokeGetParameters(obj.getClass(), obj);
-        map = map == null ? new HashMap<>() : map;
+        Map<String, String> map = new HashMap<>();
+        Map<String, String> getParametersMap = invokeGetParameters(obj.getClass(), obj);
+        if (getParametersMap != null && !getParametersMap.isEmpty()) {
+            map.putAll(getParametersMap);
+        }
         map.putAll(values);
         invokeSetParameters(obj.getClass(), obj, map);
     }


[dubbo] 07/07: feat: remove the unnecessary class of SaveProperties and loadding Properties use try-resource (#10276)

Posted by al...@apache.org.
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

commit 8a93fceed690d59c44bb6a8562dbfc1193d9c076
Author: stone_lion <v1...@qq.com>
AuthorDate: Wed Jul 6 14:20:54 2022 +0800

    feat: remove the unnecessary class of SaveProperties and loadding Properties use try-resource (#10276)
---
 .../dubbo/registry/support/AbstractRegistry.java   | 49 +++++++---------------
 1 file changed, 14 insertions(+), 35 deletions(-)

diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
index 6250892c21..e35eb66d39 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
@@ -30,7 +30,6 @@ import org.apache.dubbo.registry.Registry;
 import org.apache.dubbo.rpc.model.ApplicationModel;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -38,6 +37,7 @@ import java.io.RandomAccessFile;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
 import java.nio.channels.OverlappingFileLockException;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -238,7 +238,7 @@ public abstract class AbstractRegistry implements Registry {
                 savePropertiesRetryTimes.set(0);
                 return;
             } else {
-                registryCacheExecutor.execute(new SaveProperties(lastCacheChanged.incrementAndGet()));
+                registryCacheExecutor.execute(() -> doSaveProperties(lastCacheChanged.incrementAndGet()));
             }
             if (!(e instanceof OverlappingFileLockException)) {
                 logger.warn("Failed to save registry cache file, will retry, cause: " + e.getMessage(), e);
@@ -253,25 +253,18 @@ public abstract class AbstractRegistry implements Registry {
     }
 
     private void loadProperties() {
-        if (file != null && file.exists()) {
-            InputStream in = null;
-            try {
-                in = new FileInputStream(file);
-                properties.load(in);
-                if (logger.isInfoEnabled()) {
-                    logger.info("Loaded registry cache file " + file);
-                }
-            } catch (Throwable e) {
-                logger.warn("Failed to load registry cache file " + file, e);
-            } finally {
-                if (in != null) {
-                    try {
-                        in.close();
-                    } catch (IOException e) {
-                        logger.warn(e.getMessage(), e);
-                    }
-                }
+        if (file == null || !file.exists()) {
+            return;
+        }
+        try (InputStream in = Files.newInputStream(file.toPath())) {
+            properties.load(in);
+            if (logger.isInfoEnabled()) {
+                logger.info("Loaded registry cache file " + file);
             }
+        } catch (IOException e) {
+            logger.warn(e.getMessage(), e);
+        } catch (Throwable e) {
+            logger.warn("Failed to load registry cache file " + file, e);
         }
     }
 
@@ -502,7 +495,7 @@ public abstract class AbstractRegistry implements Registry {
             if (syncSaveFile) {
                 doSaveProperties(version);
             } else {
-                registryCacheExecutor.execute(new SaveProperties(version));
+                registryCacheExecutor.execute(() -> doSaveProperties(version));
             }
         } catch (Throwable t) {
             logger.warn(t.getMessage(), t);
@@ -575,18 +568,4 @@ public abstract class AbstractRegistry implements Registry {
     public String toString() {
         return getUrl().toString();
     }
-
-    private class SaveProperties implements Runnable {
-        private long version;
-
-        private SaveProperties(long version) {
-            this.version = version;
-        }
-
-        @Override
-        public void run() {
-            doSaveProperties(version);
-        }
-    }
-
 }


[dubbo] 04/07: Cancel availability check for NopServiceDiscovery (#10271)

Posted by al...@apache.org.
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

commit d82310292e337e48364f96b916a1056af8d82e43
Author: huazhongming <cr...@gmail.com>
AuthorDate: Tue Jul 5 17:26:45 2022 +0800

    Cancel availability check for NopServiceDiscovery (#10271)
    
    Signed-off-by: crazyhzm <cr...@gmail.com>
---
 .../apache/dubbo/registry/client/ServiceDiscoveryRegistry.java    | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
index 3b01639dc0..30eb983edd 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
@@ -51,7 +51,7 @@ import static org.apache.dubbo.registry.client.ServiceDiscoveryFactory.getExtens
 
 /**
  * TODO, this bridge implementation is not necessary now, protocol can interact with service discovery directly.
- *
+ * <p>
  * ServiceDiscoveryRegistry is a very special Registry implementation, which is used to bridge the old interface-level service discovery model
  * with the new service discovery model introduced in 3.0 in a compatible manner.
  * <p>
@@ -92,7 +92,7 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
     protected ServiceDiscoveryRegistry(URL registryURL, ServiceDiscovery serviceDiscovery, ServiceNameMapping serviceNameMapping) {
         super(registryURL);
         this.serviceDiscovery = serviceDiscovery;
-        this.serviceNameMapping = (AbstractServiceNameMapping)serviceNameMapping;
+        this.serviceNameMapping = (AbstractServiceNameMapping) serviceNameMapping;
     }
 
     public ServiceDiscovery getServiceDiscovery() {
@@ -270,6 +270,10 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
 
     @Override
     public boolean isAvailable() {
+        if (serviceDiscovery instanceof NopServiceDiscovery) {
+            // NopServiceDiscovery is designed for compatibility, check availability is meaningless, just return true
+            return true;
+        }
         return !serviceDiscovery.isDestroy() && !serviceDiscovery.getServices().isEmpty();
     }
 


[dubbo] 05/07: refactor: Modify the parameter validation log level to info (#10275)

Posted by al...@apache.org.
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

commit 7e7fc2807cb8aa40c0b15d202428a3dbac6b708f
Author: 桔子 <ju...@qq.com>
AuthorDate: Wed Jul 6 10:15:03 2022 +0800

    refactor: Modify the parameter validation log level to info (#10275)
---
 .../org/apache/dubbo/validation/support/jvalidation/JValidator.java     | 2 +-
 .../org/apache/dubbo/validation/support/jvalidation/JValidatorNew.java  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidator.java b/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidator.java
index 285d5de4c1..d136e373fd 100644
--- a/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidator.java
+++ b/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidator.java
@@ -287,7 +287,7 @@ public class JValidator implements Validator {
             }
 
             if (!violations.isEmpty()) {
-                logger.error("Failed to validate service: " + clazz.getName() + ", method: " + methodName + ", cause: " + violations);
+                logger.info("Failed to validate service: " + clazz.getName() + ", method: " + methodName + ", cause: " + violations);
                 throw new ConstraintViolationException("Failed to validate service: " + clazz.getName() + ", method: " + methodName + ", cause: " + violations, violations);
             }
         } catch (ValidationException e) {
diff --git a/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidatorNew.java b/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidatorNew.java
index 5a941d91ee..bd2461f92e 100644
--- a/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidatorNew.java
+++ b/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidatorNew.java
@@ -287,7 +287,7 @@ public class JValidatorNew implements Validator {
             }
 
             if (!violations.isEmpty()) {
-                logger.error("Failed to validate service: " + clazz.getName() + ", method: " + methodName + ", cause: " + violations);
+                logger.info("Failed to validate service: " + clazz.getName() + ", method: " + methodName + ", cause: " + violations);
                 throw new ConstraintViolationException("Failed to validate service: " + clazz.getName() + ", method: " + methodName + ", cause: " + violations, violations);
             }
         } catch (ValidationException e) {


[dubbo] 03/07: [3.0] Fix dependencies pom hibernate version (#10270)

Posted by al...@apache.org.
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

commit 90370b4bc23666f31ac009531722641dbc013ff6
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Tue Jul 5 17:07:17 2022 +0800

    [3.0] Fix dependencies pom hibernate version (#10270)
---
 dubbo-dependencies-bom/pom.xml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml
index c35aa01fc2..c20dc68e23 100644
--- a/dubbo-dependencies-bom/pom.xml
+++ b/dubbo-dependencies-bom/pom.xml
@@ -117,6 +117,7 @@
         <validation_new_version>3.0.1</validation_new_version>
         <validation_version>1.1.0.Final</validation_version>
         <hibernate_validator_version>5.4.3.Final</hibernate_validator_version>
+        <hibernate_validator_new_version>7.0.4.Final</hibernate_validator_new_version>
         <jel_version>3.0.1-b08</jel_version>
         <jcache_version>1.0.0</jcache_version>
         <kryo_version>4.0.2</kryo_version>