diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java index 9ed4d998f..e4c027254 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java @@ -40,7 +40,10 @@ import javax.annotation.PostConstruct; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.concurrent.*; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.LinkedBlockingQueue; /** * A consistency protocol algorithm called Distro @@ -59,18 +62,6 @@ import java.util.concurrent.*; @org.springframework.stereotype.Service("distroConsistencyService") public class DistroConsistencyServiceImpl implements EphemeralConsistencyService { - private ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() { - @Override - public Thread newThread(Runnable r) { - Thread t = new Thread(r); - - t.setDaemon(true); - t.setName("com.alibaba.nacos.naming.distro.notifier"); - - return t; - } - }); - @Autowired private DistroMapper distroMapper; @@ -80,9 +71,6 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService @Autowired private TaskDispatcher taskDispatcher; - @Autowired - private DataSyncer dataSyncer; - @Autowired private Serializer serializer; @@ -97,7 +85,7 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService private boolean initialized = false; - public volatile Notifier notifier = new Notifier(); + private volatile Notifier notifier = new Notifier(); private LoadDataTask loadDataTask = new LoadDataTask(); @@ -107,19 +95,8 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService @PostConstruct public void init() { - GlobalExecutor.submit(new Runnable() { - @Override - public void run() { - try { - load(); - } catch (Exception e) { - Loggers.DISTRO.error("load data failed.", e); - } - } - }); - - executor.submit(notifier); GlobalExecutor.submit(loadDataTask); + GlobalExecutor.submitDistroNotifyTask(notifier); } private class LoadDataTask implements Runnable { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatCheckTask.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatCheckTask.java index ba9c965ad..ea7537e75 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatCheckTask.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatCheckTask.java @@ -19,6 +19,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.nacos.naming.boot.RunningConfig; import com.alibaba.nacos.naming.boot.SpringContext; +import com.alibaba.nacos.naming.consistency.KeyBuilder; import com.alibaba.nacos.naming.core.DistroMapper; import com.alibaba.nacos.naming.core.Instance; import com.alibaba.nacos.naming.core.Service; @@ -65,7 +66,7 @@ public class ClientBeatCheckTask implements Runnable { } public String taskKey() { - return service.getName(); + return KeyBuilder.buildServiceMetaKey(service.getNamespaceId(), service.getName()); } @Override diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/GlobalExecutor.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/GlobalExecutor.java index 390a0359d..a87112906 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/GlobalExecutor.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/GlobalExecutor.java @@ -125,6 +125,18 @@ public class GlobalExecutor { } ); + private static ScheduledExecutorService distroNotifyExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + + t.setDaemon(true); + t.setName("com.alibaba.nacos.naming.distro.notifier"); + + return t; + } + }); + public static void submitDataSync(Runnable runnable, long delay) { dataSyncExecutor.schedule(runnable, delay, TimeUnit.MILLISECONDS); } @@ -178,6 +190,10 @@ public class GlobalExecutor { executorService.schedule(runnable, delay, TimeUnit.MILLISECONDS); } + public static void submitDistroNotifyTask(Runnable runnable) { + distroNotifyExecutor.submit(runnable); + } + public static void submitServiceUpdate(Runnable runnable) { serviceUpdateExecutor.execute(runnable); } diff --git a/test/logs/access_log.2020-03-09.log b/test/logs/access_log.2020-03-09.log new file mode 100644 index 000000000..5037a1a9b --- /dev/null +++ b/test/logs/access_log.2020-03-09.log @@ -0,0 +1,17 @@ +192.168.16.101 - - [09/Mar/2020:12:02:15 +0800] "GET /nacos/v1/cs/health HTTP/1.1" 200 2 147 +127.0.0.1 - - [09/Mar/2020:12:02:15 +0800] "PUT /nacos/v1/ns/operator/switches?entry=overriddenServerStatus&value=UP HTTP/1.1" 200 2 195 +127.0.0.1 - - [09/Mar/2020:12:02:15 +0800] "PUT /nacos/v1/ns/operator/switches?entry=overriddenServerStatus&value=UP HTTP/1.1" 200 2 197 +127.0.0.1 - - [09/Mar/2020:12:02:15 +0800] "PUT /nacos/v1/ns/operator/switches?entry=overriddenServerStatus&value=UP HTTP/1.1" 200 2 198 +127.0.0.1 - - [09/Mar/2020:12:02:15 +0800] "PUT /nacos/v1/ns/operator/switches?entry=autoChangeHealthCheckEnabled&value=false HTTP/1.1" 200 2 6 +127.0.0.1 - - [09/Mar/2020:12:02:15 +0800] "PUT /nacos/v1/ns/operator/switches?entry=autoChangeHealthCheckEnabled&value=false HTTP/1.1" 200 2 8 +127.0.0.1 - - [09/Mar/2020:12:02:15 +0800] "PUT /nacos/v1/ns/operator/switches?entry=autoChangeHealthCheckEnabled&value=false HTTP/1.1" 200 2 10 +127.0.0.1 - - [09/Mar/2020:12:02:16 +0800] "GET /nacos/v1/ns/operator/metrics?app=unknown&encoding=UTF-8&namespaceId=public HTTP/1.1" 200 187 62 +127.0.0.1 - - [09/Mar/2020:12:02:16 +0800] "GET /nacos/v1/ns/operator/metrics?app=unknown&encoding=UTF-8&namespaceId=public HTTP/1.1" 200 185 62 +127.0.0.1 - - [09/Mar/2020:12:02:16 +0800] "GET /nacos/v1/ns/operator/metrics?app=unknown&encoding=UTF-8&namespaceId=public HTTP/1.1" 200 185 62 +127.0.0.1 - - [09/Mar/2020:12:02:16 +0800] "GET /nacos/v1/ns/service/list?app=unknown&pageSize=10&groupName=DEFAULT_GROUP&encoding=UTF-8&namespaceId=public&pageNo=1 HTTP/1.1" 200 32 7 +127.0.0.1 - - [09/Mar/2020:12:02:16 +0800] "GET /nacos/v1/ns/service/list?app=unknown&pageSize=10&groupName=DEFAULT_GROUP&encoding=UTF-8&namespaceId=public&pageNo=1 HTTP/1.1" 200 32 7 +127.0.0.1 - - [09/Mar/2020:12:02:16 +0800] "POST /nacos/v1/ns/instance?app=unknown&metadata=%7B%7D&ip=127.0.0.1&weight=1.0&ephemeral=true&serviceName=DEFAULT_GROUP%40%40jinhanb9I1B.B3ETP.net&encoding=UTF-8&groupName=DEFAULT_GROUP&namespaceId=public&port=8080&enable=true&healthy=true&clusterName=c1 HTTP/1.1" 200 2 42 +127.0.0.1 - - [09/Mar/2020:12:02:16 +0800] "POST /nacos/v1/ns/instance?app=unknown&metadata=%7B%7D&ip=127.0.0.1&weight=1.0&ephemeral=true&serviceName=DEFAULT_GROUP%40%40jinhan3RA7V.5g5rC.net&encoding=UTF-8&groupName=DEFAULT_GROUP&namespaceId=public&port=8080&enable=true&healthy=true&clusterName=c1 HTTP/1.1" 200 2 46 +127.0.0.1 - - [09/Mar/2020:12:02:16 +0800] "GET /nacos/v1/ns/instance/list?app=unknown&healthyOnly=false&namespaceId=public&clientIP=127.0.0.1&serviceName=DEFAULT_GROUP%40%40jinhan3RA7V.5g5rC.net&udpPort=65151&encoding=UTF-8 HTTP/1.1" 200 270 13 +127.0.0.1 - - [09/Mar/2020:12:02:16 +0800] "GET /nacos/v1/ns/instance/list?app=unknown&healthyOnly=false&namespaceId=public&clientIP=127.0.0.1&serviceName=DEFAULT_GROUP%40%40jinhanb9I1B.B3ETP.net&udpPort=65150&encoding=UTF-8 HTTP/1.1" 200 544 17 +127.0.0.1 - - [09/Mar/2020:12:02:16 +0800] "DELETE /nacos/v1/ns/instance?app=unknown&namespaceId=public&port=8080&clusterName=c1&ip=127.0.0.1&ephemeral=true&serviceName=DEFAULT_GROUP%40%40jinhan3RA7V.5g5rC.net&encoding=UTF-8 HTTP/1.1" 200 2 5