gavinchou commented on code in PR #30340:
URL: https://github.com/apache/doris/pull/30340#discussion_r1466371096


##########
fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java:
##########
@@ -1034,14 +1037,63 @@ public String getCurrentCloudCluster() {
         return cluster;
     }
 
-    // Set cloud cluster by `use @clusterName`
     public void setCloudCluster(String cluster) {
         this.cloudCluster = cluster;
     }
 
-    // The returned cluster is set by `use @clusterName`
+    // 1 Use an explicitly specified cluster
+    // 2 If no cluster is specified, the user's default cluster is used.
+    // 3 If the user does not have a default cluster, select a cluster with 
permissions for the user.
     public String getCloudCluster() {
-        return cloudCluster;
+        String cluster = null;
+        if (!Strings.isNullOrEmpty(this.cloudCluster)) {
+            cluster = this.cloudCluster;
+        }
+
+        String defaultCluster = getDefaultCloudCluster();
+        if (!Strings.isNullOrEmpty(defaultCluster)) {
+            cluster = defaultCluster;
+        }
+
+        String authorizedCluster = getAuthorizedCloudCluster();
+        if (!Strings.isNullOrEmpty(authorizedCluster)) {
+            cluster = authorizedCluster;
+        }
+
+        if (Strings.isNullOrEmpty(cluster)) {
+            LOG.warn("cant get a valid cluster for user {} to use", 
getCurrentUserIdentity());
+            getState().setError(ErrorCode.ERR_NO_CLUSTER_ERROR,
+                    "Cant get a Valid cluster for you to use, plz connect 
admin");
+        } else {
+            this.cloudCluster = cluster;
+            LOG.info("finally set context cluster name {}", cloudCluster);
+        }
+
+        return cluster;
+    }
+
+    public String getDefaultCloudCluster() {

Review Comment:
   Add comment



##########
fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java:
##########
@@ -1034,14 +1037,63 @@ public String getCurrentCloudCluster() {
         return cluster;
     }
 
-    // Set cloud cluster by `use @clusterName`
     public void setCloudCluster(String cluster) {
         this.cloudCluster = cluster;
     }
 
-    // The returned cluster is set by `use @clusterName`
+    // 1 Use an explicitly specified cluster
+    // 2 If no cluster is specified, the user's default cluster is used.
+    // 3 If the user does not have a default cluster, select a cluster with 
permissions for the user.
     public String getCloudCluster() {
-        return cloudCluster;
+        String cluster = null;
+        if (!Strings.isNullOrEmpty(this.cloudCluster)) {
+            cluster = this.cloudCluster;
+        }
+
+        String defaultCluster = getDefaultCloudCluster();
+        if (!Strings.isNullOrEmpty(defaultCluster)) {
+            cluster = defaultCluster;
+        }
+
+        String authorizedCluster = getAuthorizedCloudCluster();
+        if (!Strings.isNullOrEmpty(authorizedCluster)) {
+            cluster = authorizedCluster;
+        }
+
+        if (Strings.isNullOrEmpty(cluster)) {
+            LOG.warn("cant get a valid cluster for user {} to use", 
getCurrentUserIdentity());
+            getState().setError(ErrorCode.ERR_NO_CLUSTER_ERROR,
+                    "Cant get a Valid cluster for you to use, plz connect 
admin");
+        } else {
+            this.cloudCluster = cluster;
+            LOG.info("finally set context cluster name {}", cloudCluster);
+        }
+
+        return cluster;
+    }
+
+    public String getDefaultCloudCluster() {
+        return null;
+    }
+
+    public String getAuthorizedCloudCluster() {
+        List<String> cloudClusterNames = 
Env.getCurrentSystemInfo().getCloudClusterNames();
+        // get all available cluster of the user
+        for (String cloudClusterName : cloudClusterNames) {
+            // find a cluster has more than one alive be
+            List<Backend> bes = 
Env.getCurrentSystemInfo().getBackendsByClusterName(cloudClusterName);
+            AtomicBoolean hasAliveBe = new AtomicBoolean(false);

Review Comment:
   why atomic?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to