Skip to content

Commit

Permalink
[alibaba#3388]Reset nacos roles, permissions during reloading role in…
Browse files Browse the repository at this point in the history
…fo from database (alibaba#3442)

* Reset nacos roles, permissions during reloading role info from database

* Add volatile to guarantee visibility in threads
  • Loading branch information
yanjunnf authored and lancediarmuid committed Jul 27, 2020
1 parent 95c091f commit d310fda
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public class NacosRoleServiceImpl {
@Autowired
private PermissionPersistService permissionPersistService;

private final Set<String> roleSet = new ConcurrentHashSet<>();
private volatile Set<String> roleSet = new ConcurrentHashSet<>();

private final Map<String, List<RoleInfo>> roleInfoMap = new ConcurrentHashMap<>();
private volatile Map<String, List<RoleInfo>> roleInfoMap = new ConcurrentHashMap<>();

private final Map<String, List<PermissionInfo>> permissionInfoMap = new ConcurrentHashMap<>();
private volatile Map<String, List<PermissionInfo>> permissionInfoMap = new ConcurrentHashMap<>();

@Scheduled(initialDelay = 5000, fixedDelay = 15000)
private void reload() {
Expand All @@ -95,9 +95,9 @@ private void reload() {
tmpPermissionInfoMap.put(role, permissionInfoPage.getPageItems());
}

roleSet.addAll(tmpRoleSet);
roleInfoMap.putAll(tmpRoleInfoMap);
permissionInfoMap.putAll(tmpPermissionInfoMap);
roleSet = tmpRoleSet;
roleInfoMap = tmpRoleInfoMap;
permissionInfoMap = tmpPermissionInfoMap;
} catch (Exception e) {
Loggers.AUTH.warn("[LOAD-ROLES] load failed", e);
}
Expand Down

0 comments on commit d310fda

Please sign in to comment.