In the compute-storage decoupled mode, users can organize one or more BE nodes into a compute cluster. This document introduces how to use the compute clusters. The main operations include:

  • Show all compute clusters
  • Grant compute clusters to users
  • Bind a compute cluster to user (default_cloud_cluster) for user-level isolation

Managing Compute Cluster - 图1info

cluster in this document refers to compute clusters.

Show all compute clusters

Use the show clusters command to check all compute clusters under the current instance.

  1. > mysql show clusters;
  2. +-------------------------------+------------+------------+
  3. | cluster | is_current | users |
  4. +-------------------------------+------------+------------+
  5. | regression_test_cluster_name0 | FALSE | root, jack |
  6. | regression_test_cluster_name5 | FALSE | |
  7. +-------------------------------+------------+------------+
  8. 2 rows in set (0.01 sec)
  9. mysql SET PROPERTY 'default_cloud_cluster' = 'regression_test_cluster_name5';
  10. Query OK, 0 rows affected (0.01 sec)

Grant compute cluster access privilege

Use the MySQL Client to create a new user.

Syntax

  1. GRANT USAGE_PRIV ON CLUSTER {cluster_name} TO {user}

Example

  1. // Use the root account to create a new Jack user in the MySQL Client.
  2. mysql CREATE USER jack IDENTIFIED BY '123456' DEFAULT ROLE "admin";
  3. Query OK, 0 rows affected (0.01 sec)
  4. mysql GRANT USAGE_PRIV ON CLUSTER regression_test_cluster_name0 TO jack;
  5. Query OK, 0 rows affected (0.01 sec)
  6. // Log in to the MySQL Client via Jack.
  7. mysql use d1@regression_test_cluster_name0;
  8. Database changed
  9. mysql show grants for jack\G
  10. *************************** 1. row ***************************
  11. UserIdentity: 'jack'@'%'
  12. Password: Yes
  13. GlobalPrivs: Admin_priv (false)
  14. CatalogPrivs: NULL
  15. DatabasePrivs: internal.information_schema: Select_priv (false)
  16. TablePrivs: NULL
  17. ResourcePrivs: NULL
  18. CloudCluster: regression_test_cluster_name0: Usage_priv (false)
  19. CloudStage: NULL
  20. 1 row in set (0.00 sec)
  21. mysql select * from t1;
  22. +------+------+-------+
  23. | id | name | score |
  24. +------+------+-------+
  25. | 1 | aaa | 20 |
  26. | 2 | bbb | 320 |
  27. | 3 | ccc | 30 |
  28. | 4 | ddd | 120 |
  29. | 5 | eee | 30 |
  30. | 6 | fff | 30 |
  31. | 7 | ggg | 90 |
  32. | 8 | hhh | 30 |
  33. +------+------+-------+
  34. 8 rows in set (12.70 sec)
  35. mysql insert into t1 (id, name, score) values (8, "hhh", 30);
  36. Query OK, 1 row affected (7.22 sec)
  37. {'label':'insert_6f40c1713baf4d61_9c33c0962c68ab07', 'status':'VISIBLE', 'txnId':'5462662627547136'}

If you attempt to grant a Jack user the access privilege to a non-existent compute cluster, the system will not report an error. However, an error will be raised when the user attempts to execute the use @cluster command.

  1. mysql GRANT USAGE_PRIV ON CLUSTER not_exist_cluster TO jack;
  2. Query OK, 0 rows affected (0.05 sec)
  3. mysql show grants for jack\G
  4. *************************** 1. row ***************************
  5. UserIdentity: 'jack'@'%'
  6. Password: Yes
  7. GlobalPrivs: Admin_priv (false)
  8. CatalogPrivs: NULL
  9. DatabasePrivs: internal.information_schema: Select_priv (false)
  10. TablePrivs: NULL
  11. ResourcePrivs: NULL
  12. CloudCluster: not_exist_cluster: Usage_priv (false)
  13. CloudStage: NULL
  14. 1 row in set (0.00 sec)
  15. Switch to the Jack account and execute use @not_exist_cluster, an error will be thrown.
  16. mysql use information_schema@not_exist_cluster;
  17. No connection. Trying to reconnect...
  18. Connection id: 1
  19. Current database: *** NONE ***
  20. ERROR 5091 (42000): Cluster not_exist_cluster not exist

Revoke compute cluster access privilege

Syntax

  1. REVOKE USAGE_PRIV ON CLUSTER {cluster_name} FROM {user}

Example

  1. // Use the root account to create a new Jack user in the MySQL Client.
  2. mysql REVOKE USAGE_PRIV ON CLUSTER regression_test_cluster_name0 FROM jack;
  3. Query OK, 0 rows affected (0.01 sec)
  4. mysql show grants for jack\G
  5. *************************** 1. row ***************************
  6. UserIdentity: 'jack'@'%'
  7. Password: Yes
  8. GlobalPrivs: Admin_priv (false)
  9. CatalogPrivs: NULL
  10. DatabasePrivs: internal.information_schema: Select_priv (false)
  11. TablePrivs: NULL
  12. ResourcePrivs: NULL
  13. CloudCluster: NULL
  14. CloudStage: NULL
  15. 1 row in set (0.01 sec)

Set default compute cluster

Users can set a compute cluster as the default compute cluster.

Syntax

Set the default compute cluster for the current user:

  1. SET PROPERTY 'default_cloud_cluster' = '{clusterName}';

Set the default compute cluster for other users (requiring Admin privileges):

  1. SET PROPERTY FOR {user} 'default_cloud_cluster' = '{clusterName}';

Check the default compute cluster of the current user. The value of default_cloud_cluster in the returned result will be the default compute cluster.

  1. SHOW PROPERTY;

Check the default compute clusters of other users (requiring Admin privileges). The value of default_cloud_clusterin the returned result will be the default compute cluster.

  1. SHOW PROPERTY FOR {user};

Check all available compute clusters under the current instance:

  1. SHOW CLUSTERS;

Managing Compute Cluster - 图2info

  • If the current user has Admin privileges, (e.g. CREATE USER jack IDENTIFIED BY '123456' DEFAULT ROLE "admin"), then:
    • They can set the default compute cluster for themselves and other users;
    • They can view the PROPERTY for themselves and other users.
  • If the current user does not have Admin privileges, (e.g. CREATE USER jack1 IDENTIFIED BY '123456'), then:
    • They can set the default compute cluster for themselves;
    • They can view their own PROPERTY;
    • They cannot view all compute clusters, as this operation requires the GRANT ADMIN privilege.
  • If a default compute cluster is not set for the current user, the system will trigger an error when the user executes data read/write operations. To solve this, the user can execute the use @cluster command to specify the compute cluster for the current context, or use the SET PROPERTY statement to set the default compute cluster.
  • If the current user has set a default compute cluster, but that cluster is later deleted, an error will also be triggered when executing data read/write operations. The user can execute the use @cluster command to re-specify the compute cluster for the current context, or use the SET PROPERTY statement to update the default compute cluster setting.

Example

  1. // Set the default compute cluster for the current user
  2. mysql SET PROPERTY 'default_cloud_cluster' = 'regression_test_cluster_name0';
  3. Query OK, 0 rows affected (0.02 sec)
  4. // Show the default compute cluster of the current user
  5. mysql show PROPERTY;
  6. +------------------------+-------------------------------+
  7. | Key | Value |
  8. +------------------------+-------------------------------+
  9. | cpu_resource_limit | -1 |
  10. | default_cloud_cluster | regression_test_cluster_name0 |
  11. | exec_mem_limit | -1 |
  12. | load_mem_limit | -1 |
  13. | max_query_instances | -1 |
  14. | max_user_connections | 100 |
  15. | quota.high | 800 |
  16. | quota.low | 100 |
  17. | quota.normal | 400 |
  18. | resource.cpu_share | 1000 |
  19. | resource.hdd_read_iops | 80 |
  20. | resource.hdd_read_mbps | 30 |
  21. | resource.io_share | 1000 |
  22. | resource.ssd_read_iops | 1000 |
  23. | resource.ssd_read_mbps | 30 |
  24. | resource_tags | |
  25. | sql_block_rules | |
  26. +------------------------+-------------------------------+
  27. 17 rows in set (0.00 sec)
  28. // Use the root account to create a new Jack user in the MySQL Client
  29. mysql CREATE USER jack IDENTIFIED BY '123456' DEFAULT ROLE "admin";
  30. Query OK, 0 rows affected (0.01 sec)
  31. // Set the default compute cluster for a Jack user
  32. mysql SET PROPERTY FOR jack 'default_cloud_cluster' = 'regression_test_cluster_name1';
  33. Query OK, 0 rows affected (0.00 sec)
  34. // Show the default compute clusters of other users
  35. mysql show PROPERTY for jack;
  36. +------------------------+-------------------------------+
  37. | Key | Value |
  38. +------------------------+-------------------------------+
  39. | cpu_resource_limit | -1 |
  40. | default_cloud_cluster | regression_test_cluster_name1 |
  41. | exec_mem_limit | -1 |
  42. | load_mem_limit | -1 |
  43. | max_query_instances | -1 |
  44. | max_user_connections | 100 |
  45. | quota.high | 800 |
  46. | quota.low | 100 |
  47. | quota.normal | 400 |
  48. | resource.cpu_share | 1000 |
  49. | resource.hdd_read_iops | 80 |
  50. | resource.hdd_read_mbps | 30 |
  51. | resource.io_share | 1000 |
  52. | resource.ssd_read_iops | 1000 |
  53. | resource.ssd_read_mbps | 30 |
  54. | resource_tags | |
  55. | sql_block_rules | |
  56. +------------------------+-------------------------------+
  57. 17 rows in set (0.00 sec)

If the compute cluster that is about to be set as default does not exist, as the default, the system will return an error and prompt the user to use the SHOW CLUSTERS command to view all the valid compute clusters in the current warehouse.

The SHOW CLUSTERS command will return a result set, where:

  • The Cluster column shows the name of the compute clusters.
  • The is_current column indicates whether the current user is using that compute cluster.
  • The Users column shows which users have set that compute cluster as their default.
  1. mysql SET PROPERTY 'default_cloud_cluster' = 'not_exist_cluster';
  2. ERROR 5091 (42000): errCode = 2, detailMessage = Cluster not_exist_cluster not exist, use SQL 'SHOW CLUSTERS' to get a valid cluster
  3. mysql show clusters;
  4. +-------------------------------+------------+------------+
  5. | cluster | is_current | users |
  6. +-------------------------------+------------+------------+
  7. | regression_test_cluster_name0 | FALSE | root, jack |
  8. | regression_test_cluster_name5 | FALSE | |
  9. +-------------------------------+------------+------------+
  10. 2 rows in set (0.01 sec)
  11. mysql SET PROPERTY 'default_cloud_cluster' = 'regression_test_cluster_name5';
  12. Query OK, 0 rows affected (0.01 sec)

Default compute cluster selection mechanism

When the user has not explicitly set a default compute cluster, the system will automatically select a compute cluster which satifies the following conditions:

  • The compute cluster has an active backend.
  • The user has permission to use this compute cluster.

Once a default compute cluster is established for a specific session, it will remain the default throughout that session, unless the user explicitly changes the default setting.

In different sessions, the system may automatically change the user’s default compute cluster if any of the following occur:

  • The user loses permission to use the compute cluster that was previously selected as the default.
  • Clusters have been added or removed.
  • The previously selected default compute cluster no longer has an active backend.

Scenarios 1 and 2 will definitively trigger the system to automatically select a new default compute cluster, while scenario 3 may potentially lead to a change.

Switch compute cluster

In a compute-storage decoupled architecture, the user can specify the database and compute cluster to be used.

Syntax

  1. USE { [catalog_name.]database_name[@cluster_name] | @cluster_name }

If the name of the database or compute cluster contains a reserved keyword, the respective name needs to be enclosed within backticks ``` to denote it as a quoted identifier.

Example

Use database test_database:

  1. USE test_database
  2. USE `test_database`

Use compute cluster test_cluster:

  1. USE @test_cluster
  2. USE @`test_cluster`

Use database test_database and compute cluster test_cluster:

  1. USE test_database@test_cluster
  2. USE `test_database`@`test_cluster`