Improve AuthorityRuleManager: replace the rule map instead of clear-then-insert when updating rules (#2655)
This commit is contained in:
parent
fcc539d660
commit
679625e299
|
|
@ -39,7 +39,7 @@ import com.alibaba.csp.sentinel.property.SentinelProperty;
|
||||||
*/
|
*/
|
||||||
public final class AuthorityRuleManager {
|
public final class AuthorityRuleManager {
|
||||||
|
|
||||||
private static Map<String, Set<AuthorityRule>> authorityRules = new ConcurrentHashMap<>();
|
private static volatile Map<String, Set<AuthorityRule>> authorityRules = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private static final RulePropertyListener LISTENER = new RulePropertyListener();
|
private static final RulePropertyListener LISTENER = new RulePropertyListener();
|
||||||
private static SentinelProperty<List<AuthorityRule>> currentProperty = new DynamicSentinelProperty<>();
|
private static SentinelProperty<List<AuthorityRule>> currentProperty = new DynamicSentinelProperty<>();
|
||||||
|
|
@ -92,13 +92,16 @@ public final class AuthorityRuleManager {
|
||||||
private static class RulePropertyListener implements PropertyListener<List<AuthorityRule>> {
|
private static class RulePropertyListener implements PropertyListener<List<AuthorityRule>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configUpdate(List<AuthorityRule> conf) {
|
public synchronized void configLoad(List<AuthorityRule> value) {
|
||||||
Map<String, Set<AuthorityRule>> rules = loadAuthorityConf(conf);
|
authorityRules = loadAuthorityConf(value);
|
||||||
|
|
||||||
authorityRules.clear();
|
RecordLog.info("[AuthorityRuleManager] Authority rules loaded: {}", authorityRules);
|
||||||
if (rules != null) {
|
|
||||||
authorityRules.putAll(rules);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void configUpdate(List<AuthorityRule> conf) {
|
||||||
|
authorityRules = loadAuthorityConf(conf);
|
||||||
|
|
||||||
RecordLog.info("[AuthorityRuleManager] Authority rules received: {}", authorityRules);
|
RecordLog.info("[AuthorityRuleManager] Authority rules received: {}", authorityRules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,16 +138,6 @@ public final class AuthorityRuleManager {
|
||||||
return newRuleMap;
|
return newRuleMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void configLoad(List<AuthorityRule> value) {
|
|
||||||
Map<String, Set<AuthorityRule>> rules = loadAuthorityConf(value);
|
|
||||||
|
|
||||||
authorityRules.clear();
|
|
||||||
if (rules != null) {
|
|
||||||
authorityRules.putAll(rules);
|
|
||||||
}
|
|
||||||
RecordLog.info("[AuthorityRuleManager] Load authority rules: {}", authorityRules);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Map<String, Set<AuthorityRule>> getAuthorityRules() {
|
static Map<String, Set<AuthorityRule>> getAuthorityRules() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue