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;
/**
* 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 + '\'' +

View File

@ -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);
}

View File

@ -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<Instance> instances, boolean ephemeral) {

View File

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