improve(triggerFlag): adjust triggerFlag calculation chance

This commit is contained in:
universefeeler 2019-09-17 19:52:12 +08:00
parent 54ae846cb7
commit 0f3c9f3c87
4 changed files with 5 additions and 24 deletions

View File

@ -34,11 +34,6 @@ public class Service {
*/ */
private String name; private String name;
/**
* service protect threshold trigger flag
*/
private boolean triggerFlag = false;
/** /**
* protect threshold * protect threshold
*/ */
@ -107,19 +102,10 @@ public class Service {
this.metadata.put(key, value); this.metadata.put(key, value);
} }
public boolean isTriggerFlag() {
return triggerFlag;
}
public void setTriggerFlag(boolean triggerFlag) {
this.triggerFlag = triggerFlag;
}
@Override @Override
public String toString() { public String toString() {
return "Service{" + return "Service{" +
"name='" + name + '\'' + "name='" + name + '\'' +
"triggerFlag='" + triggerFlag + '\'' +
", protectThreshold=" + protectThreshold + ", protectThreshold=" + protectThreshold +
", appName='" + appName + '\'' + ", appName='" + appName + '\'' +
", groupName='" + groupName + '\'' + ", groupName='" + groupName + '\'' +

View File

@ -285,7 +285,7 @@ public class CatalogController {
serviceView.setClusterCount(service.getClusterMap().size()); serviceView.setClusterCount(service.getClusterMap().size());
serviceView.setIpCount(service.allIPs().size()); serviceView.setIpCount(service.allIPs().size());
serviceView.setHealthyInstanceCount(service.healthyInstanceCount()); serviceView.setHealthyInstanceCount(service.healthyInstanceCount());
serviceView.setTriggerFlag(service.isTriggerFlag()?"True":"False"); serviceView.setTriggerFlag(service.triggerFlag()?"true":"false");
serviceJsonArray.add(serviceView); serviceJsonArray.add(serviceView);
} }

View File

@ -172,8 +172,6 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
updateIPs(value.getInstanceList(), KeyBuilder.matchEphemeralInstanceListKey(key)); updateIPs(value.getInstanceList(), KeyBuilder.matchEphemeralInstanceListKey(key));
updateTriggerFlag();
recalculateChecksum(); recalculateChecksum();
} }
@ -193,18 +191,16 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
return healthyCount; return healthyCount;
} }
public void updateTriggerFlag() { public boolean triggerFlag() {
if(0 == healthyInstanceCount()) { if(0 == healthyInstanceCount()) {
setTriggerFlag(true); return true;
return;
} }
Float compareValue = 0.0F; Float compareValue = 0.0F;
if(Float.floatToIntBits(compareValue) == getProtectThreshold()) { if(Float.floatToIntBits(compareValue) == getProtectThreshold()) {
setTriggerFlag(false); return false;
return;
} }
boolean triggerFlag = (healthyInstanceCount() * 1.0 / allIPs().size()) <= getProtectThreshold(); boolean triggerFlag = (healthyInstanceCount() * 1.0 / allIPs().size()) <= getProtectThreshold();
setTriggerFlag(triggerFlag); return triggerFlag;
} }
public void updateIPs(Collection<Instance> instances, boolean ephemeral) { public void updateIPs(Collection<Instance> instances, boolean ephemeral) {

View File

@ -88,6 +88,5 @@ public class ClientBeatProcessor implements Runnable {
} }
} }
} }
service.updateTriggerFlag();
} }
} }