Browse Source

Code and javadoc refinement

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao 6 years ago
parent
commit
87076a6977
12 changed files with 47 additions and 39 deletions
  1. +6
    -6
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricWriter.java
  2. +1
    -1
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/property/DynamicSentinelProperty.java
  3. +12
    -2
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/AbstractRule.java
  4. +5
    -1
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/RuleConstant.java
  5. +2
    -2
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleManager.java
  6. +2
    -2
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRuleManager.java
  7. +3
    -6
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRule.java
  8. +4
    -2
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleComparator.java
  9. +1
    -1
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java
  10. +8
    -13
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java
  11. +1
    -1
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/AppNameUtil.java
  12. +2
    -2
      sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleManager.java

+ 6
- 6
sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricWriter.java View File

@@ -86,7 +86,7 @@ public class MetricWriter {
if (singleFileSize <= 0 || totalFileCount <= 0) { if (singleFileSize <= 0 || totalFileCount <= 0) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
RecordLog.info("new MetricWriter, singleFileSize=" + singleFileSize + ", totalFileCount=" + totalFileCount);
RecordLog.info("[MetricWriter] Creating new MetricWriter, singleFileSize=" + singleFileSize + ", totalFileCount=" + totalFileCount);
this.baseDir = METRIC_BASE_DIR; this.baseDir = METRIC_BASE_DIR;
File dir = new File(baseDir); File dir = new File(baseDir);
if (!dir.exists()) { if (!dir.exists()) {
@@ -100,7 +100,7 @@ public class MetricWriter {
try { try {
this.timeSecondBase = df.parse("1970-01-01 00:00:00").getTime() / 1000; this.timeSecondBase = df.parse("1970-01-01 00:00:00").getTime() / 1000;
} catch (Exception e) { } catch (Exception e) {
RecordLog.info("new MetricWriter error: ", e);
RecordLog.warn("[MetricWriter] Create new MetricWriter error", e);
} }
} }


@@ -286,9 +286,9 @@ public class MetricWriter {
String fileName = list.get(i); String fileName = list.get(i);
String indexFile = formIndexFileName(fileName); String indexFile = formIndexFileName(fileName);
new File(fileName).delete(); new File(fileName).delete();
RecordLog.info("remove metric file: " + fileName);
RecordLog.info("[MetricWriter] Removing metric file: " + fileName);
new File(indexFile).delete(); new File(indexFile).delete();
RecordLog.info("remove metric index file: " + indexFile);
RecordLog.info("[MetricWriter] Removing metric index file: " + indexFile);
} }
} }


@@ -307,8 +307,8 @@ public class MetricWriter {
; ;
curMetricIndexFile = new File(idxFile); curMetricIndexFile = new File(idxFile);
outIndex = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(idxFile, append))); outIndex = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(idxFile, append)));
RecordLog.info("create new metric file: " + fileName);
RecordLog.info("create new metric index file: " + idxFile);
RecordLog.info("[MetricWriter] New metric file created: " + fileName);
RecordLog.info("[MetricWriter] New metric index file created: " + idxFile);
} }


private boolean validSize() throws Exception { private boolean validSize() throws Exception {


+ 1
- 1
sentinel-core/src/main/java/com/alibaba/csp/sentinel/property/DynamicSentinelProperty.java View File

@@ -50,7 +50,7 @@ public class DynamicSentinelProperty<T> implements SentinelProperty<T> {
if (isEqual(value, newValue)) { if (isEqual(value, newValue)) {
return; return;
} }
RecordLog.info("SentinelProperty, config is real updated to: " + newValue);
RecordLog.info("[DynamicSentinelProperty] Config will be updated to: " + newValue);


value = newValue; value = newValue;
for (PropertyListener<T> listener : listeners) { for (PropertyListener<T> listener : listeners) {


+ 12
- 2
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/AbstractRule.java View File

@@ -17,13 +17,23 @@ package com.alibaba.csp.sentinel.slots.block;


/*** /***
* @author youji.zj * @author youji.zj
* @author Eric Zhao
*/ */
public abstract class AbstractRule implements Rule { public abstract class AbstractRule implements Rule {


/*** 规则的资源描述 ***/
/**
* Resource name.
*/
private String resource; private String resource;


/*** 被限制的应用,授权时候为逗号分隔的应用集合,限流时为单个应用 ***/
/**
* <p>
* Application name that will be limited by origin.
* Multiple application name can be separated with comma (',').
* </p>
* <p>The default limitApp is `default`, which means allowing all origin apps.</p>
* <p>For example: limitApp = `appA,appB` will limit requests from appA and appB.</p>
*/
private String limitApp; private String limitApp;


public String getResource() { public String getResource() {


+ 5
- 1
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/RuleConstant.java View File

@@ -19,7 +19,7 @@ package com.alibaba.csp.sentinel.slots.block;
* @author youji.zj * @author youji.zj
* @author jialiang.linjl * @author jialiang.linjl
*/ */
public class RuleConstant {
public final class RuleConstant {


public static final int FLOW_GRADE_THREAD = 0; public static final int FLOW_GRADE_THREAD = 0;
public static final int FLOW_GRADE_QPS = 1; public static final int FLOW_GRADE_QPS = 1;
@@ -38,4 +38,8 @@ public class RuleConstant {
public static final int CONTROL_BEHAVIOR_WARM_UP = 1; public static final int CONTROL_BEHAVIOR_WARM_UP = 1;
public static final int CONTROL_BEHAVIOR_RATE_LIMITER = 2; public static final int CONTROL_BEHAVIOR_RATE_LIMITER = 2;


public static final String LIMIT_APP_DEFAULT = "default";
public static final String LIMIT_APP_OTHER = "other";

private RuleConstant() {}
} }

+ 2
- 2
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleManager.java View File

@@ -21,11 +21,11 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;


import com.alibaba.csp.sentinel.log.RecordLog; import com.alibaba.csp.sentinel.log.RecordLog;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.property.DynamicSentinelProperty; import com.alibaba.csp.sentinel.property.DynamicSentinelProperty;
import com.alibaba.csp.sentinel.property.PropertyListener; import com.alibaba.csp.sentinel.property.PropertyListener;
import com.alibaba.csp.sentinel.property.SentinelProperty; import com.alibaba.csp.sentinel.property.SentinelProperty;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;


/** /**
* Manager for authority rules. * Manager for authority rules.
@@ -115,7 +115,7 @@ public final class AuthorityRuleManager {
} }


if (StringUtil.isBlank(rule.getLimitApp())) { if (StringUtil.isBlank(rule.getLimitApp())) {
rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT);
rule.setLimitApp(RuleConstant.LIMIT_APP_DEFAULT);
} }


String identity = rule.getResource(); String identity = rule.getResource();


+ 2
- 2
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRuleManager.java View File

@@ -28,7 +28,7 @@ import com.alibaba.csp.sentinel.property.PropertyListener;
import com.alibaba.csp.sentinel.property.SentinelProperty; import com.alibaba.csp.sentinel.property.SentinelProperty;
import com.alibaba.csp.sentinel.slotchain.ResourceWrapper; import com.alibaba.csp.sentinel.slotchain.ResourceWrapper;
import com.alibaba.csp.sentinel.slots.block.BlockException; import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;


/*** /***
@@ -150,7 +150,7 @@ public class DegradeRuleManager {
} }


if (StringUtil.isBlank(rule.getLimitApp())) { if (StringUtil.isBlank(rule.getLimitApp())) {
rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT);
rule.setLimitApp(RuleConstant.LIMIT_APP_DEFAULT);
} }


String identity = rule.getResource(); String identity = rule.getResource();


+ 3
- 6
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRule.java View File

@@ -40,12 +40,9 @@ import com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot;
*/ */
public class FlowRule extends AbstractRule { public class FlowRule extends AbstractRule {


public static final String LIMIT_APP_DEFAULT = "default";
public static final String LIMIT_APP_OTHER = "other";

public FlowRule(){ public FlowRule(){
super(); super();
setLimitApp(LIMIT_APP_DEFAULT);
setLimitApp(RuleConstant.LIMIT_APP_DEFAULT);
} }


/** /**
@@ -196,7 +193,7 @@ public class FlowRule extends AbstractRule {
return node; return node;
} }


} else if (LIMIT_APP_DEFAULT.equals(limitApp)) {
} else if (RuleConstant.LIMIT_APP_DEFAULT.equals(limitApp)) {
if (strategy == RuleConstant.STRATEGY_DIRECT) { if (strategy == RuleConstant.STRATEGY_DIRECT) {
return node.getClusterNode(); return node.getClusterNode();
} }
@@ -216,7 +213,7 @@ public class FlowRule extends AbstractRule {
return node; return node;
} }


} else if (LIMIT_APP_OTHER.equals(limitApp) && FlowRuleManager.isOtherOrigin(origin, getResource())) {
} else if (RuleConstant.LIMIT_APP_OTHER.equals(limitApp) && FlowRuleManager.isOtherOrigin(origin, getResource())) {
if (strategy == RuleConstant.STRATEGY_DIRECT) { if (strategy == RuleConstant.STRATEGY_DIRECT) {
return context.getOriginNode(); return context.getOriginNode();
} }


+ 4
- 2
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleComparator.java View File

@@ -17,6 +17,8 @@ package com.alibaba.csp.sentinel.slots.block.flow;


import java.util.Comparator; import java.util.Comparator;


import com.alibaba.csp.sentinel.slots.block.RuleConstant;

public class FlowRuleComparator implements Comparator<FlowRule> { public class FlowRuleComparator implements Comparator<FlowRule> {


@Override @Override
@@ -30,9 +32,9 @@ public class FlowRuleComparator implements Comparator<FlowRule> {
return 0; return 0;
} }


if (FlowRule.LIMIT_APP_DEFAULT.equals(o1.getLimitApp())) {
if (RuleConstant.LIMIT_APP_DEFAULT.equals(o1.getLimitApp())) {
return 1; return 1;
} else if (FlowRule.LIMIT_APP_DEFAULT.equals(o2.getLimitApp())) {
} else if (RuleConstant.LIMIT_APP_DEFAULT.equals(o2.getLimitApp())) {
return -1; return -1;
} else { } else {
return 0; return 0;


+ 1
- 1
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java View File

@@ -114,7 +114,7 @@ public class FlowRuleManager {
continue; continue;
} }
if (StringUtil.isBlank(rule.getLimitApp())) { if (StringUtil.isBlank(rule.getLimitApp())) {
rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT);
rule.setLimitApp(RuleConstant.LIMIT_APP_DEFAULT);
} }


Controller rater = new DefaultController(rule.getCount(), rule.getGrade()); Controller rater = new DefaultController(rule.getCount(), rule.getGrade());


+ 8
- 13
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java View File

@@ -77,7 +77,7 @@ public class SystemRuleManager {
private static volatile boolean maxRtIsSet = false; private static volatile boolean maxRtIsSet = false;
private static volatile boolean maxThreadIsSet = false; private static volatile boolean maxThreadIsSet = false;


static AtomicBoolean checkSystemStatus = new AtomicBoolean(false);
private static AtomicBoolean checkSystemStatus = new AtomicBoolean(false);


private static SystemStatusListener statusListener = null; private static SystemStatusListener statusListener = null;
private final static SystemPropertyListener listener = new SystemPropertyListener(); private final static SystemPropertyListener listener = new SystemPropertyListener();
@@ -185,11 +185,9 @@ public class SystemRuleManager {
checkSystemStatus.set(false); checkSystemStatus.set(false);
} }


RecordLog.info("current system system status : " + checkSystemStatus.get());
RecordLog.info("current highestSystemLoad status : " + highestSystemLoad);
RecordLog.info("current maxRt : " + maxRt);
RecordLog.info("current maxThread : " + maxThread);
RecordLog.info("current qps : " + qps);

RecordLog.info(String.format("[SystemRuleManager] Current system check status: %s, highestSystemLoad: "
+ highestSystemLoad + ", " + "maxRt: %d, maxThread: %d, maxQps: " + qps, checkSystemStatus.get(), maxRt, maxThread));
} }


protected void restoreSetting() { protected void restoreSetting() {
@@ -222,9 +220,8 @@ public class SystemRuleManager {
} }


public static void loadSystemConf(SystemRule rule) { public static void loadSystemConf(SystemRule rule) {

boolean checkStatus = false; boolean checkStatus = false;
// 首先判断是否有效
// Check if it's valid.


if (rule.getHighestSystemLoad() >= 0) { if (rule.getHighestSystemLoad() >= 0) {
highestSystemLoad = Math.min(highestSystemLoad, rule.getHighestSystemLoad()); highestSystemLoad = Math.min(highestSystemLoad, rule.getHighestSystemLoad());
@@ -260,9 +257,8 @@ public class SystemRuleManager {
* @throws BlockException when any system rule's threshold is exceeded. * @throws BlockException when any system rule's threshold is exceeded.
*/ */
public static void checkSystem(ResourceWrapper resourceWrapper) throws BlockException { public static void checkSystem(ResourceWrapper resourceWrapper) throws BlockException {

// 确定开关开了
if (checkSystemStatus.get() == false) {
// Ensure the checking switch is on.
if (!checkSystemStatus.get()) {
return; return;
} }


@@ -288,7 +284,7 @@ public class SystemRuleManager {
throw new SystemBlockException(resourceWrapper.getName(), "rt"); throw new SystemBlockException(resourceWrapper.getName(), "rt");
} }


// 完全按照RT,BBR算法来
// BBR algorithm.
if (highestSystemLoadIsSet && getCurrentSystemAvgLoad() > highestSystemLoad) { if (highestSystemLoadIsSet && getCurrentSystemAvgLoad() > highestSystemLoad) {
if (currentThread > 1 && if (currentThread > 1 &&
currentThread > Constants.ENTRY_NODE.maxSuccessQps() * Constants.ENTRY_NODE.minRt() / 1000) { currentThread > Constants.ENTRY_NODE.maxSuccessQps() * Constants.ENTRY_NODE.minRt() / 1000) {
@@ -301,5 +297,4 @@ public class SystemRuleManager {
public static double getCurrentSystemAvgLoad() { public static double getCurrentSystemAvgLoad() {
return statusListener.getSystemAverageLoad(); return statusListener.getSystemAverageLoad();
} }

} }

+ 1
- 1
sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/AppNameUtil.java View File

@@ -57,7 +57,7 @@ public final class AppNameUtil {


static { static {
resolveAppName(); resolveAppName();
RecordLog.info("app name resolved: " + appName);
RecordLog.info("App name resolved: " + appName);
} }


public static void resolveAppName() { public static void resolveAppName() {


+ 2
- 2
sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleManager.java View File

@@ -26,7 +26,7 @@ import com.alibaba.csp.sentinel.log.RecordLog;
import com.alibaba.csp.sentinel.property.DynamicSentinelProperty; import com.alibaba.csp.sentinel.property.DynamicSentinelProperty;
import com.alibaba.csp.sentinel.property.PropertyListener; import com.alibaba.csp.sentinel.property.PropertyListener;
import com.alibaba.csp.sentinel.property.SentinelProperty; import com.alibaba.csp.sentinel.property.SentinelProperty;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;


/** /**
@@ -169,7 +169,7 @@ public final class ParamFlowRuleManager {
} }


if (StringUtil.isBlank(rule.getLimitApp())) { if (StringUtil.isBlank(rule.getLimitApp())) {
rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT);
rule.setLimitApp(RuleConstant.LIMIT_APP_DEFAULT);
} }


if (rule.getParamFlowItemList() == null) { if (rule.getParamFlowItemList() == null) {


Loading…
Cancel
Save