diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/CtSph.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/CtSph.java index 27e7c805..e8750710 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/CtSph.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/CtSph.java @@ -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. * diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/context/ContextUtil.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/context/ContextUtil.java index 3389750b..3da93330 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/context/ContextUtil.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/context/ContextUtil.java @@ -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; + } + } + /** *

* 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. *