From 0f3c9f3c87d43fbb9048e3e59b66c6fefaf28fa7 Mon Sep 17 00:00:00 2001 From: universefeeler Date: Tue, 17 Sep 2019 19:52:12 +0800 Subject: [PATCH] improve(triggerFlag): adjust triggerFlag calculation chance --- .../com/alibaba/nacos/api/naming/pojo/Service.java | 14 -------------- .../naming/controllers/CatalogController.java | 2 +- .../com/alibaba/nacos/naming/core/Service.java | 12 ++++-------- .../naming/healthcheck/ClientBeatProcessor.java | 1 - 4 files changed, 5 insertions(+), 24 deletions(-) diff --git a/api/src/main/java/com/alibaba/nacos/api/naming/pojo/Service.java b/api/src/main/java/com/alibaba/nacos/api/naming/pojo/Service.java index cb7a9afb5..7e8fe2d34 100644 --- a/api/src/main/java/com/alibaba/nacos/api/naming/pojo/Service.java +++ b/api/src/main/java/com/alibaba/nacos/api/naming/pojo/Service.java @@ -34,11 +34,6 @@ public class Service { */ private String name; - /** - * service protect threshold trigger flag - */ - private boolean triggerFlag = false; - /** * protect threshold */ @@ -107,19 +102,10 @@ public class Service { this.metadata.put(key, value); } - public boolean isTriggerFlag() { - return triggerFlag; - } - - public void setTriggerFlag(boolean triggerFlag) { - this.triggerFlag = triggerFlag; - } - @Override public String toString() { return "Service{" + "name='" + name + '\'' + - "triggerFlag='" + triggerFlag + '\'' + ", protectThreshold=" + protectThreshold + ", appName='" + appName + '\'' + ", groupName='" + groupName + '\'' + diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/CatalogController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/CatalogController.java index d051939ca..2b552b2eb 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/CatalogController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/CatalogController.java @@ -285,7 +285,7 @@ public class CatalogController { serviceView.setClusterCount(service.getClusterMap().size()); serviceView.setIpCount(service.allIPs().size()); serviceView.setHealthyInstanceCount(service.healthyInstanceCount()); - serviceView.setTriggerFlag(service.isTriggerFlag()?"True":"False"); + serviceView.setTriggerFlag(service.triggerFlag()?"true":"false"); serviceJsonArray.add(serviceView); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java b/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java index f19772533..2423bf7c9 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java @@ -172,8 +172,6 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement updateIPs(value.getInstanceList(), KeyBuilder.matchEphemeralInstanceListKey(key)); - updateTriggerFlag(); - recalculateChecksum(); } @@ -193,18 +191,16 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement return healthyCount; } - public void updateTriggerFlag() { + public boolean triggerFlag() { if(0 == healthyInstanceCount()) { - setTriggerFlag(true); - return; + return true; } Float compareValue = 0.0F; if(Float.floatToIntBits(compareValue) == getProtectThreshold()) { - setTriggerFlag(false); - return; + return false; } boolean triggerFlag = (healthyInstanceCount() * 1.0 / allIPs().size()) <= getProtectThreshold(); - setTriggerFlag(triggerFlag); + return triggerFlag; } public void updateIPs(Collection instances, boolean ephemeral) { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatProcessor.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatProcessor.java index 4dc4a5672..00b6bacb3 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatProcessor.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatProcessor.java @@ -88,6 +88,5 @@ public class ClientBeatProcessor implements Runnable { } } } - service.updateTriggerFlag(); } }