Browse Source

Log warn when amount of context exceeds the max capacity for the first time

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao 6 years ago
parent
commit
9c2683e6ba
2 changed files with 34 additions and 2 deletions
  1. +10
    -0
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/CtSph.java
  2. +24
    -2
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/context/ContextUtil.java

+ 10
- 0
sentinel-core/src/main/java/com/alibaba/csp/sentinel/CtSph.java View File

@@ -203,6 +203,16 @@ public class CtSph implements Sph {
return chain;
}

/**
* Get current size of created slot chains.
*
* @return size of created slot chains
* @since 0.2.0
*/
public static int entrySize() {
return chainMap.size();
}

/**
* Reset the slot chain map. Only for internal test.
*


+ 24
- 2
sentinel-core/src/main/java/com/alibaba/csp/sentinel/context/ContextUtil.java View File

@@ -123,7 +123,7 @@ public class ContextUtil {
DefaultNode node = localCacheNameMap.get(name);
if (node == null) {
if (localCacheNameMap.size() > Constants.MAX_CONTEXT_NAME_SIZE) {
contextHolder.set(NULL_CONTEXT);
setNullContext();
return NULL_CONTEXT;
} else {
try {
@@ -131,7 +131,7 @@ public class ContextUtil {
node = contextNameNodeMap.get(name);
if (node == null) {
if (contextNameNodeMap.size() > Constants.MAX_CONTEXT_NAME_SIZE) {
contextHolder.set(NULL_CONTEXT);
setNullContext();
return NULL_CONTEXT;
} else {
node = new EntranceNode(new StringResourceWrapper(name, EntryType.IN), null);
@@ -158,6 +158,18 @@ public class ContextUtil {
return context;
}

private static boolean shouldWarn = true;

private static void setNullContext() {
contextHolder.set(NULL_CONTEXT);
// Don't need to be thread-safe.
if (shouldWarn) {
RecordLog.warn("[SentinelStatusChecker] WARN: Amount of context exceeds the threshold "
+ Constants.MAX_CONTEXT_NAME_SIZE + ". Entries in new contexts will NOT take effect!");
shouldWarn = false;
}
}

/**
* <p>
* Enter the invocation context. The context is ThreadLocal, meaning that
@@ -192,6 +204,16 @@ public class ContextUtil {
}
}

/**
* Get current size of context entrance node map.
*
* @return current size of context entrance node map
* @since 0.2.0
*/
public static int contextSize() {
return contextNameNodeMap.size();
}

/**
* Check if provided context is a default auto-created context.
*


Loading…
Cancel
Save