From 25f79e0587e30b783f92b5254ddbc8c4d6234772 Mon Sep 17 00:00:00 2001 From: zhuyou1234 Date: Sat, 2 Apr 2022 23:03:17 +0800 Subject: [PATCH] =?UTF-8?q?AuthorityRuleManager=E5=B9=B6=E5=8F=91=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E4=B8=8B=E5=8A=A8=E6=80=81=E6=9B=B4=E6=96=B0=E9=BB=91?= =?UTF-8?q?=E7=99=BD=E5=90=8D=E5=8D=95=EF=BC=8C=E5=8F=AF=E8=83=BD=E4=BC=9A?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E9=BB=91=E7=99=BD=E5=90=8D=E5=8D=95=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改黑白名单配置,先clear在去putAll。假设在此期间进行黑白名单验证,由于authorityRules已经被clear了,导致之前的黑白名单失效 --- .../block/authority/AuthorityRuleManager.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleManager.java index 22b698dd46..8ce0adf447 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleManager.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleManager.java @@ -39,7 +39,7 @@ */ public final class AuthorityRuleManager { - private static Map> authorityRules = new ConcurrentHashMap<>(); + private static volatile Map> authorityRules = new ConcurrentHashMap<>(); private static final RulePropertyListener LISTENER = new RulePropertyListener(); private static SentinelProperty> currentProperty = new DynamicSentinelProperty<>(); @@ -93,12 +93,8 @@ private static class RulePropertyListener implements PropertyListener conf) { - Map> rules = loadAuthorityConf(conf); - - authorityRules.clear(); - if (rules != null) { - authorityRules.putAll(rules); - } + authorityRules = loadAuthorityConf(conf); + RecordLog.info("[AuthorityRuleManager] Authority rules received: {}", authorityRules); } @@ -137,12 +133,8 @@ private Map> loadAuthorityConf(List li @Override public void configLoad(List value) { - Map> rules = loadAuthorityConf(value); + authorityRules = loadAuthorityConf(value); - authorityRules.clear(); - if (rules != null) { - authorityRules.putAll(rules); - } RecordLog.info("[AuthorityRuleManager] Load authority rules: {}", authorityRules); } }