[#3388]Reset nacos roles, permissions during reloading role info from database (#3442)

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

* Add volatile to guarantee visibility in threads
This commit is contained in:
yanjunnf 2020-07-27 10:13:56 +08:00 committed by GitHub
parent d19b441540
commit 377f778711
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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() {
@ -95,9 +95,9 @@ public class NacosRoleServiceImpl {
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);
}