Skip to content

Commit 15c752b

Browse files
authored
[feature](selectdb-cloud) Report an error directly when the cluster is empty (apache#1578)
* Report an error directly when the cluster is empty * fix regression case
1 parent 527361b commit 15c752b

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ public String getCloudCluster() {
689689
return cloudCluster;
690690
}
691691

692-
public void setCloudCluster() {
692+
public void setCloudCluster() throws UserException {
693693
List<String> cloudClusterNames = Env.getCurrentSystemInfo().getCloudClusterNames();
694694
// try set default cluster
695695
String defaultCloudCluster = Env.getCurrentEnv().getAuth().getDefaultCloudCluster(getQualifiedUser());
@@ -705,7 +705,7 @@ public void setCloudCluster() {
705705
LOG.warn("default cluster {} current invalid, please change it", defaultCloudCluster);
706706
getState().setError(ErrorCode.ERR_NO_CLUSTER_ERROR,
707707
"default cluster " + defaultCloudCluster + "current invalid, please change it");
708-
return;
708+
throw new UserException("default cluster " + defaultCloudCluster + "current invalid, please change it");
709709
}
710710
}
711711

@@ -723,7 +723,7 @@ public void setCloudCluster() {
723723
LOG.warn("cant get a valid cluster for user {} to use", getCurrentUserIdentity());
724724
getState().setError(ErrorCode.ERR_NO_CLUSTER_ERROR,
725725
"Cant get a Valid cluster for you to use, plz connect admin");
726-
return;
726+
throw new UserException("Cant get a Valid cluster for you to use, plz connect admin");
727727
}
728728
LOG.info("finally set context cluster name {}", cloudCluster);
729729
}

‎fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,11 @@ private void auditAfterExec(String origStmt, StatementBase parsedStmt, Data.PQue
302302
private void handleQuery() {
303303
MetricRepo.COUNTER_REQUEST_ALL.increase(1L);
304304
if (Config.isCloudMode() && Strings.isNullOrEmpty(ctx.cloudCluster)) {
305-
ctx.setCloudCluster();
305+
try {
306+
ctx.setCloudCluster();
307+
} catch (UserException e) {
308+
return;
309+
}
306310
LOG.debug("handle Query set ctx cloud cluster, get cluster: {}", ctx.getCloudCluster());
307311
}
308312
if (Config.isCloudMode() && ctx.cloudCluster != null) {

‎regression-test/suites/cloud/copy_into/test_stage_ddl.groovy‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ suite("test_stage_ddl") {
115115
sql """
116116
GRANT LOAD_PRIV ON *.*.* TO '${user}'@'%';
117117
"""
118+
List<List<Object>> clusterRes = sql "show clusters"
119+
assertTrue(clusterRes.size() >= 1);
120+
String clusterName = clusterRes[0][0]
121+
122+
sql """
123+
GRANT USAGE_PRIV ON CLUSTER ${clusterName} TO ${user}
124+
"""
125+
118126
// copy into
119127
def result = connect(user=user, password='12345', url=context.config.jdbcUrl) {
120128
def result1 = sql """COPY INTO regression_test.test FROM @~('${remote}') properties('copy.async'='false')"""

0 commit comments

Comments
 (0)