Skip to content
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

[fix](cloud)Compatibility with the initial default compute group usage #42504

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private String getCurrentClusterId() throws ComputeGroupException {
((CloudEnv) Env.getCurrentEnv()).checkCloudClusterPriv(cluster);
} catch (Exception e) {
LOG.warn("get compute group by session context exception");
throw new ComputeGroupException(String.format("default compute group %s check auth failed",
throw new ComputeGroupException(String.format("session context compute group %s check auth failed",
cluster),
ComputeGroupException.FailedTypeEnum.CURRENT_USER_NO_AUTH_TO_USE_DEFAULT_COMPUTE_GROUP);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public enum FailedTypeEnum {
CONNECT_CONTEXT_NOT_SET_COMPUTE_GROUP,
CURRENT_USER_NO_AUTH_TO_USE_ANY_COMPUTE_GROUP,
CURRENT_USER_NO_AUTH_TO_USE_DEFAULT_COMPUTE_GROUP,
CURRENT_USER_NO_AUTH_TO_USE_COMPUTE_GROUP,
CURRENT_COMPUTE_GROUP_NO_BE,
COMPUTE_GROUPS_NO_ALIVE_BE,
CURRENT_COMPUTE_GROUP_NOT_EXIST,
Expand All @@ -59,6 +60,8 @@ public enum FailedTypeEnum {
helpInfos.put(FailedTypeEnum.CURRENT_USER_NO_AUTH_TO_USE_ANY_COMPUTE_GROUP, " contact the system administrator "
+ "and request that they grant you the appropriate compute group permissions, "
+ "use SQL `GRANT USAGE_PRIV ON COMPUTE GROUP {compute_group_name} TO {user}`");
helpInfos.put(FailedTypeEnum.CURRENT_USER_NO_AUTH_TO_USE_COMPUTE_GROUP,
"use SQL `GRANT USAGE_PRIV ON COMPUTE GROUP {compute_group_name} TO {user}`");
helpInfos.put(FailedTypeEnum.CURRENT_USER_NO_AUTH_TO_USE_DEFAULT_COMPUTE_GROUP,
" contact the system administrator "
+ "and request that they grant you the default compute group permissions, "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@

package org.apache.doris.mysql.privilege;

import org.apache.doris.analysis.ResourceTypeEnum;
import org.apache.doris.analysis.SetUserPropertyVar;
import org.apache.doris.analysis.UserIdentity;
import org.apache.doris.catalog.Env;
import org.apache.doris.cloud.qe.ComputeGroupException;
import org.apache.doris.cluster.ClusterNamespace;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
Expand Down Expand Up @@ -257,23 +260,9 @@ public void update(List<Pair<String, String>> properties, boolean isReplay) thro

newDefaultLoadCluster = value;
} else if (keyArr[0].equalsIgnoreCase(DEFAULT_CLOUD_CLUSTER)) {
// set property "DEFAULT_CLOUD_CLUSTER" = "cluster1"
if (keyArr.length != 1) {
throw new DdlException(DEFAULT_CLOUD_CLUSTER + " format error");
}
if (value == null) {
value = "";
}
newDefaultCloudCluster = value;
newDefaultCloudCluster = checkCloudDefaultCluster(keyArr, value, DEFAULT_CLOUD_CLUSTER);
} else if (keyArr[0].equalsIgnoreCase(DEFAULT_COMPUTE_GROUP)) {
// set property "DEFAULT_CLOUD_CLUSTER" = "cluster1"
if (keyArr.length != 1) {
throw new DdlException(DEFAULT_COMPUTE_GROUP + " format error");
}
if (value == null) {
value = "";
}
newDefaultCloudCluster = value;
newDefaultCloudCluster = checkCloudDefaultCluster(keyArr, value, DEFAULT_COMPUTE_GROUP);
} else if (keyArr[0].equalsIgnoreCase(PROP_MAX_QUERY_INSTANCES)) {
// set property "max_query_instances" = "1000"
if (keyArr.length != 1) {
Expand Down Expand Up @@ -401,6 +390,25 @@ public void update(List<Pair<String, String>> properties, boolean isReplay) thro
defaultCloudCluster = newDefaultCloudCluster;
}

private String checkCloudDefaultCluster(String[] keyArr, String value, String defaultComputeGroup)
throws ComputeGroupException, DdlException {
// check cluster auth
if (!Env.getCurrentEnv().getAuth().checkCloudPriv(UserIdentity.fromString(qualifiedUser),
value, PrivPredicate.USAGE, ResourceTypeEnum.CLUSTER)) {
throw new ComputeGroupException(String.format("set default compute group failed, "
+ "user {} must first have auth to use this compute group ", value),
Copy link
Contributor

@gavinchou gavinchou Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"user {} must first have auth to use this compute group "
-> "user {} has no permission to use compute group {}, please grant use privilege first with grant USE_PRIV to ${user}

(fulfill the last part of msg )

ComputeGroupException.FailedTypeEnum.CURRENT_USER_NO_AUTH_TO_USE_COMPUTE_GROUP);
}
// set property "DEFAULT_CLOUD_CLUSTER" = "cluster1"
if (keyArr.length != 1) {
throw new DdlException(defaultComputeGroup + " format error");
}
if (value == null) {
value = "";
}
return value;
}

private long getLongProperty(String key, String value, String[] keyArr, String propName) throws DdlException {
// eg: set property "load_mem_limit" = "2147483648";
if (keyArr.length != 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1272,11 +1272,6 @@ public String getCloudCluster(boolean updateErr) throws ComputeGroupException {
if (!Strings.isNullOrEmpty(defaultCluster)) {
cluster = defaultCluster;
choseWay = "default compute group";
if (!Env.getCurrentEnv().getAuth().checkCloudPriv(getCurrentUserIdentity(),
cluster, PrivPredicate.USAGE, ResourceTypeEnum.CLUSTER)) {
throw new ComputeGroupException(String.format("default compute group %s check auth failed", cluster),
ComputeGroupException.FailedTypeEnum.CURRENT_USER_NO_AUTH_TO_USE_DEFAULT_COMPUTE_GROUP);
}
} else {
CloudClusterResult cloudClusterTypeAndName = getCloudClusterByPolicy();
if (cloudClusterTypeAndName != null && !Strings.isNullOrEmpty(cloudClusterTypeAndName.clusterName)) {
Expand Down
Loading