-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BugFix] Fix MySQL 8.0.x compatibility problem #56872
base: main
Are you sure you want to change the base?
Conversation
_applicable_roles_index++; | ||
return Status::OK(); | ||
} | ||
} // namespace starrocks No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most risky bug in this code is:
Potential out-of-bounds access due to _column_num being uninitialized, leading to unpredictable slot_id validation.
You can modify the code like this:
// Within SchemaApplicableRolesScanner constructor or initialization part:
_column_num = sizeof(_s_columns) / sizeof(SchemaScanner::ColumnDesc); // Initialize _column_num
// Ensure to include this initialization logic to avoid potential issues.
SchemaScanner::SchemaScanner(_s_columns, _column_num);
} finally { | ||
roleReadUnlock(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most risky bug in this code is:
Improper handling of lock acquisition and release order might lead to deadlocks. Specifically, mixing userReadLock/Unlock with roleReadLock/Unlock without a consistent order can cause deadlock issues if another method acquires them in a conflicting order.
You can modify the code like this:
public List<RolePrivilegeCollectionV2> getApplicableRoles(UserIdentity user) throws PrivilegeException {
List<RolePrivilegeCollectionV2> applicableRoles = new ArrayList<>();
// Ensure a consistent locking order by acquiring role lock before user lock
roleReadLock();
try {
userReadLock();
try {
Set<Long> roleIds = getRoleIdsByUser(user);
for (Long roleId : roleIds) {
RolePrivilegeCollectionV2 rolePrivilegeCollection = roleIdToPrivilegeCollection.get(roleId);
if (rolePrivilegeCollection != null) {
applicableRoles.add(rolePrivilegeCollection);
}
}
} finally {
userReadUnlock();
}
} finally {
roleReadUnlock();
}
return applicableRoles;
}
This modification ensures that locks are always acquired and released in a consistent order, mitigating the risk of deadlocks.
response.setRoles(roleList); | ||
return response; | ||
} | ||
|
||
public static TGetTemporaryTablesInfoResponse generateTemporaryTablesInfoResponse(TGetTemporaryTablesInfoRequest request) | ||
throws TException { | ||
TemporaryTableMgr temporaryTableMgr = GlobalStateMgr.getCurrentState().getTemporaryTableMgr(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most risky bug in this code is: If getAuthDbRequestResult(request.getAuth_info())
returns a null
value for authorizedDbs
, calling isEmpty()
on it will result in a NullPointerException
.
You can modify the code like this:
public static TGetApplicableRolesResponse generateApplicableRolesResp(TGetApplicableRolesRequest request) throws TException {
TGetApplicableRolesResponse response = new TGetApplicableRolesResponse();
List<TApplicableRolesInfo> roleList = new ArrayList<>();
AuthDbRequestResult result = getAuthDbRequestResult(request.getAuth_info());
if (result == null || result.authorizedDbs == null || result.authorizedDbs.isEmpty()) {
response.setRoles(roleList);
return response;
}
UserIdentity currentUser = result.currentUser;
if (currentUser == null) {
response.setRoles(roleList);
return response;
}
AuthorizationMgr authMgr = GlobalStateMgr.getCurrentState().getAuthorizationMgr();
try {
for (RolePrivilegeCollectionV2 role : authMgr.getApplicableRoles(currentUser)) {
String roleName = role.getName();
String roleHost = "%";
String isGrantable = authMgr.isRoleGrantable(currentUser, roleName) ? "YES" : "NO";
String isDefault = authMgr.isRoleDefault(currentUser, roleName) ? "YES" : "NO";
String isMandatory = authMgr.isRoleMandatory(currentUser, roleName) ? "YES" : "NO";
TApplicableRolesInfo roleInfo = new TApplicableRolesInfo();
roleInfo.setUser(currentUser.getUser());
roleInfo.setHost(currentUser.getHost());
roleInfo.setGrantee(currentUser.getUser());
roleInfo.setGrantee_host(currentUser.getHost());
roleInfo.setRole_name(roleName);
roleInfo.setRole_host(roleHost);
roleInfo.setIs_grantable(isGrantable);
roleInfo.setIs_default(isDefault);
roleInfo.setIs_mandatory(isMandatory);
roleList.add(roleInfo);
}
} catch (PrivilegeException e) {
throw new RuntimeException(e);
}
response.setRoles(roleList);
return response;
}
fc36f03
to
4395186
Compare
gensrc/thrift/Descriptors.thrift
Outdated
@@ -182,6 +182,7 @@ enum TSchemaTableType { | |||
SCH_CLUSTER_SNAPSHOTS, | |||
SCH_CLUSTER_SNAPSHOT_JOBS, | |||
|
|||
SCH_APPLICABLE_ROLES, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New items should be added to the last.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I've already revised it.
Signed-off-by: Zac-saodiseng <[email protected]>
Signed-off-by: Zac-saodiseng <[email protected]>
Signed-off-by: Zac-saodiseng <[email protected]>
88b8302
to
6d06425
Compare
Signed-off-by: Zac-saodiseng <[email protected]>
e95f59b
to
bc0b829
Compare
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 80 / 92 (86.96%) file detail
|
[BE Incremental Coverage Report]✅ pass : 83 / 92 (90.22%) file detail
|
|
@@ -103,6 +103,7 @@ public class SystemId { | |||
public static final long FE_METRICS_ID = 42L; | |||
|
|||
public static final long TEMP_TABLES_ID = 43L; | |||
public static final long APPLICABLE_ROLES_ID = 45L; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be moved behind 44.
@SerializedName(value = "d") | ||
private boolean isDefault; | ||
@SerializedName(value = "m") | ||
private boolean isMandatory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s best not to add extra persistent fields.
Why I'm doing:
What I'm doing:
INFORMATION_SCHEMA.APPLICABLE_ROLES
table.'default_storage_engine'
and'default_table_compression'
.'EXPRESSION'
inINFORMATION_SCHEMA.STATISTICS
and'ENFORCED'
inINFORMATION_SCHEMA.TABLE_CONSTRAINTS
.Fixes #55629
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: