You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by xi...@apache.org on 2022/06/29 08:30:15 UTC

[incubator-shenyu] branch master updated: [ISSUE #3614] admin delay update handle in selector (#3615)

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

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new a27bb8f5f [ISSUE #3614] admin delay update handle in selector (#3615)
a27bb8f5f is described below

commit a27bb8f5ff2e17d9f8eef83030ad0429520cc364
Author: dragon-zhang <ha...@webuy.ai>
AuthorDate: Wed Jun 29 16:30:05 2022 +0800

    [ISSUE #3614] admin delay update handle in selector (#3615)
    
    * [ISSUE #3614] admin delay update handle in selector
    
    * fix code style
    
    * if pass, add to normal service list directly
    
    * fix comment
    
    * fix bug
    
    * fix style
---
 .../admin/service/impl/UpstreamCheckService.java   | 25 ++++++++++++++++++++++
 .../AbstractShenyuClientRegisterServiceImpl.java   |  2 +-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java
index 768c5868e..3420c0e02 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java
@@ -202,6 +202,31 @@ public class UpstreamCheckService {
         executor.execute(() -> updateHandler(selectorId, upstreams, upstreams));
         return true;
     }
+    
+    /**
+     * If the health check passes, the service will be added to
+     * the normal service list; if the health check fails, the service
+     * will not be discarded directly and add to the zombie nodes.
+     *
+     * <p>Note: This is to be compatible with older versions of clients
+     * that do not register with the gateway by listening to
+     * {@link org.springframework.context.event.ContextRefreshedEvent},
+     * which will cause some problems,
+     * check https://github.com/apache/incubator-shenyu/issues/3484 for more details.
+     *
+     * @param selectorId     the selector id
+     * @param commonUpstream the common upstream
+     * @return whether this module handles
+     */
+    public boolean checkAndSubmit(final String selectorId, final CommonUpstream commonUpstream) {
+        final boolean pass = UpstreamCheckUtils.checkUrl(commonUpstream.getUpstreamUrl());
+        if (pass) {
+            return submit(selectorId, commonUpstream);
+        }
+        ZOMBIE_SET.add(ZombieUpstream.transform(commonUpstream, zombieCheckTimes, selectorId));
+        LOG.error("add zombie node, url={}", commonUpstream.getUpstreamUrl());
+        return true;
+    }
 
     /**
      * Replace.
diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java
index 1f873ac1f..8100b0348 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java
@@ -203,7 +203,7 @@ public abstract class AbstractShenyuClientRegisterServiceImpl extends FallbackSh
      */
     protected boolean doSubmit(final String selectorId, final List<? extends CommonUpstream> upstreamList) {
         List<CommonUpstream> commonUpstreamList = CommonUpstreamUtils.convertCommonUpstreamList(upstreamList);
-        return commonUpstreamList.stream().map(upstream -> upstreamCheckService.submit(selectorId, upstream))
+        return commonUpstreamList.stream().map(upstream -> upstreamCheckService.checkAndSubmit(selectorId, upstream))
                 .collect(Collectors.toList()).stream().findAny().orElse(false);
     }