From e2a720640a2837b8648cb9df1285aabfca56377c Mon Sep 17 00:00:00 2001 From: nkorange Date: Tue, 26 Mar 2019 11:55:48 +0800 Subject: [PATCH] Fix #961 --- .../nacos/naming/controllers/ClusterController.java | 3 +-- .../main/java/com/alibaba/nacos/naming/core/Cluster.java | 7 +++++++ .../java/com/alibaba/nacos/naming/core/ServiceManager.java | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ClusterController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ClusterController.java index 9bda150d3a4..2b0df41280a 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ClusterController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ClusterController.java @@ -96,9 +96,8 @@ public String update(HttpServletRequest request) throws Exception { cluster.setHealthChecker(abstractHealthChecker); cluster.setMetadata(UtilsAndCommons.parseMetadata(metadata)); - + cluster.init(); service.getClusterMap().put(clusterName, cluster); - service.setLastModifiedMillis(System.currentTimeMillis()); service.recalculateChecksum(); service.validate(); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/Cluster.java b/naming/src/main/java/com/alibaba/nacos/naming/core/Cluster.java index af79c65d9fb..d4198b2c5dd 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/Cluster.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/Cluster.java @@ -54,6 +54,9 @@ public class Cluster extends com.alibaba.nacos.api.naming.pojo.Cluster implement @JSONField(serialize = false) private Service service; + @JSONField(serialize = false) + private volatile boolean inited = false; + private Map metadata = new ConcurrentHashMap<>(); public Cluster() { @@ -87,8 +90,12 @@ public List allIPs(boolean ephemeral) { } public void init() { + if (inited) { + return; + } checkTask = new HealthCheckTask(this); HealthCheckReactor.scheduleCheck(checkTask); + inited = true; } public void destroy() { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java index 9dea26128c4..296718476f8 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java @@ -481,6 +481,7 @@ public List updateIpAddresses(Service service, String action, boolean if (!service.getClusterMap().containsKey(instance.getClusterName())) { Cluster cluster = new Cluster(instance.getClusterName()); cluster.setService(service); + cluster.init(); service.getClusterMap().put(instance.getClusterName(), cluster); Loggers.SRV_LOG.warn("cluster: {} not found, ip: {}, will create new cluster with default configuration.", instance.getClusterName(), instance.toJSON());