Skip to content

Commit 4440993

Browse files
wenyanshi-123shiwenyan
andauthored
Avoid CN OOM by Pulling User/Roles to DN When Cache Misses. (apache#16888)
* Fix OOM problem for PIPE. * Fix IT. * Fix potential NPE. --------- Co-authored-by: shiwenyan <[email protected]>
1 parent 48bd352 commit 4440993

File tree

1 file changed

+25
-34
lines changed

1 file changed

+25
-34
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/ClusterAuthorityFetcher.java

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -167,37 +167,37 @@ public TSStatus checkUserSysPrivilegesGrantOpt(String username, PrivilegeType pe
167167
@Override
168168
public List<Integer> checkUserPathPrivileges(
169169
String username, List<? extends PartialPath> allPath, PrivilegeType permission) {
170-
checkCacheAvailable();
171170
List<Integer> posList = new ArrayList<>();
172-
User user = iAuthorCache.getUserCache(username);
173-
if (user != null) {
174-
if (user.isOpenIdUser()) {
175-
return posList;
176-
}
177-
int pos = 0;
178-
for (PartialPath path : allPath) {
179-
if (!user.checkPathPrivilege(path, permission)) {
180-
boolean checkFromRole = false;
181-
for (String rolename : user.getRoleSet()) {
182-
Role cachedRole = iAuthorCache.getRoleCache(rolename);
183-
if (cachedRole == null) {
184-
return checkPathFromConfigNode(username, allPath, permission);
185-
}
186-
if (cachedRole.checkPathPrivilege(path, permission)) {
187-
checkFromRole = true;
188-
break;
189-
}
171+
if (username.equals(AuthorityChecker.INTERNAL_AUDIT_USER)) {
172+
return posList;
173+
}
174+
checkCacheAvailable();
175+
User user = getUser(username);
176+
if (user.isOpenIdUser()) {
177+
return posList;
178+
}
179+
int pos = 0;
180+
for (PartialPath path : allPath) {
181+
if (!user.checkPathPrivilege(path, permission)) {
182+
boolean checkFromRole = false;
183+
for (String rolename : user.getRoleSet()) {
184+
Role cachedRole = iAuthorCache.getRoleCache(rolename);
185+
if (cachedRole == null) {
186+
checkRoleFromConfigNode(username, rolename);
187+
cachedRole = iAuthorCache.getRoleCache(rolename);
190188
}
191-
if (!checkFromRole) {
192-
posList.add(pos);
189+
if (cachedRole != null && cachedRole.checkPathPrivilege(path, permission)) {
190+
checkFromRole = true;
191+
break;
193192
}
194193
}
195-
pos++;
194+
if (!checkFromRole) {
195+
posList.add(pos);
196+
}
196197
}
197-
return posList;
198-
} else {
199-
return checkPathFromConfigNode(username, allPath, permission);
198+
pos++;
200199
}
200+
return posList;
201201
}
202202

203203
@Override
@@ -642,15 +642,6 @@ private TPermissionInfoResp checkPrivilegeFromConfigNode(TCheckUserPrivilegesReq
642642
return permissionInfoResp;
643643
}
644644

645-
private List<Integer> checkPathFromConfigNode(
646-
String username, List<? extends PartialPath> allPath, PrivilegeType permission) {
647-
TCheckUserPrivilegesReq req =
648-
new TCheckUserPrivilegesReq(
649-
username, PrivilegeModelType.TREE.ordinal(), permission.ordinal(), false);
650-
req.setPaths(AuthUtils.serializePartialPathList(allPath));
651-
return checkPrivilegeFromConfigNode(req).getFailPos();
652-
}
653-
654645
private boolean checkRoleFromConfigNode(String username, String rolename) {
655646
TAuthorizerReq req = new TAuthorizerReq();
656647
// just reuse authorizer request. only need username and rolename field.

0 commit comments

Comments
 (0)