跳转至

逻辑集群

逻辑集群说明

简介

逻辑集群是划分物理节点的一种模式。通过逻辑集群管理,实现了在一个大的物理集群中,将集群划分成多个存储上隔离的小集群,这些小集群被称作逻辑集群。

通过逻辑集群的划分,可以达到逻辑集群间的计算和存储资源的隔离;同时通过逻辑集群和用户的绑定,实现不同用户数据的互相隔离;另外通过支持跨逻辑集群的数据访问,保证在授权情况下的业务用户可以访问多个逻辑集群上的数据。

逻辑集群方式部署,可以进一步扩大整个集群的部署规模;同时通过配置不同的用户归属于不同的逻辑集群,可以实现同一物理集群,服务于多个租户。

逻辑集群划分

上图是对物理集群进行逻辑集群划分的示意图:

  • 物理集群包含 Node1 ~ Node6 六个物理主机,上面运行seaboxsql executor实例,作为存储和计算节点
  • 通过逻辑集群划分,六个物理主机划分到两个相对独立的逻辑集群中,逻辑集群1 包含Node1、Node2、Node5,逻辑集群2 包含Node3、Node4、Node6
  • 随着业务扩大,新增Node7 ~ Node9三台物理主机,可以通过集群扩容工具把Node7 ~ Node9扩容到 逻辑集群1 中,进一步提升其存储能力和计算能力

跨逻辑集群数据访问

在逻辑集群模式下,用户会被配置为属于某个逻辑集群。用户创建的数据会存储在其所属的逻辑集群内。一个用户默认情况下不能访问其他逻辑集群的数据, 但是经过授权,用户可以跨逻辑集群进行数据访问。

跨逻辑集群数据访问

上图是跨逻辑集群进行数据访问的示意图:

  • 逻辑集群logic_cluster_1上有一个数据表table_a
  • 逻辑集群logic_cluster_2上有一个数据表table_b
  • 用户lc1_user属于逻辑集群logic_cluster_1
  • lc1_user默认可以访问table_a;通过授权,lc1_user也能访问table_b
  • 同一个查询语句中,可以同时访问不同逻辑集群内的表:select * from table_a a, table_b b where a.i = b.x
  • 默认情况下,会使用用户lc1_user所属的逻辑集群的计算资源执行上面的语句,即会把table_b的数据,重分布到logic_cluster_1上,通过logic_cluster_1的计算资源进行查询计算
  • 可以通过execute_nodegroup参数,设置查询计算使用的逻辑集群。如set execute_nodegroup = logic_cluster_2,会设置上面的查询语句在logic_cluster_2上执行,即会把table_a的数据,重分布到logic_cluster_2的计算节点上

逻辑集群与节点组

逻辑集群是在节点组(Node Group)的基础上实现的对物理集群的划分。节点组是一组计算节点的组合,可以在节点组上创建表对象。可以把逻辑集群看成是一种特殊的节点组,逻辑集群的相关管理语句使用了节点组关键字(Node Group)

逻辑集群与节点组的区别:

  • 逻辑集群之间不能有重叠的Executor实例
  • Node Group支持数据隔离,逻辑集群在此基础上,支持权限隔离
  • 逻辑集群支持单独启动/停止
  • 逻辑集群支持在seabox管理工具中查看状态
  • 逻辑集群支持扩容、缩容

逻辑集群的使用方法

通过Node Group或逻辑集群对物理集群进行划分

  1. 创建节点组或逻辑集群

  2. 语句

    • CREATE NODE GROUP
  3. 功能描述
    • 创建一个新的集群节点组
  4. 注意事项
    • 只有系统管理员可以创建node group。
  5. 语法格式

    CREATE NODE GROUP group_name
          WITH NODE ( nodename [, ... ] )
          [LCGROUP]
    | CREATE NODE GROUP group_name
          WITH CONTENT ( contentid [, ... ] )
          [LCGROUP]
    
    • 注: WITH CONTENT格式的命令为开发调试内部使用,不体现在最终用户手册中
    • 参数说明
    • group_name
      • 节点组名称。
      • 取值范围:字符串,要符合标识符的命名规范。且最大长度不超过63个字符。
    • nodename
      • 节点名称。
      • 取值范围:字符串。sc_node_configuration系统表中executor对应的hostname。给定nodename上所有的executor实例都会添加到集群节点组
    • contentid
      • executor对应的contentid。
      • 取值范围:整数。sc_node_configuration系统表中executor对应的content字段。
    • LCGROUP
      • 创建一个逻辑集群类型的节点组
  6. 删除节点组或逻辑集群

  7. 语句

    • DROP NODE GROUP
  8. 功能描述
    • 删除节点组。
  9. 注意事项
    • 只有系统管理员可以删除node group。
  10. 语法格式

    DROP NODE GROUP group_name
    
  11. 参数说明

    • group_name
      • 要删除的节点组名。
      • 取值范围:已存在的节点组。
  12. 修改节点组或逻辑集群

  13. 语句

    • ALTER NODE GROUP
  14. 功能描述
    • 修改一个node group的信息。
  15. 注意事项
    • 只有系统管理员可以修改node group信息。
  16. 语法格式

    ALTER NODE GROUP group_name
      | ADD NODE ( nodename [, ... ] )
      | ADD CONTENT ( contentid [, ... ] )
      | DELETE NODE ( nodename [, ... ] )
      | DELETE CONTENT ( contentid [, ... ] )
      | SET LCGROUP RENAME TO new_group_name
      | RENAME TO new_group_name
      | SET NOT LCGROUP
      | OWNER TO new_owner
      | STATUS TO new_status
    
    • 注: ADD、DELETE和STATUS TO子命令为管理工具内部使用,不体现在最终用户手册中
    • 参数说明
    • group_name
      • 需要修改的node group名称。
      • 取值范围:已存在的节点组。
    • RENAME TO new_group_name
      • 将group_name指定的node group的名字修改为new_group_name。
    • SET LCGROUP RENAME TO new_group_name
      • 把用于扩缩容的临时节点组转换成逻辑集群
    • SET NOT LCGROUP
      • 将当前唯一的逻辑集群回退为物理集群。
    • ADD NODE ( nodename [, … ] ) | ADD CONTENT ( contentid [, … ] )
      • 以主机或实例为单位,向group_name指定的NodeGroup中增加指定的节点。
      • 该语句仅仅修改系统表,不会进行实际的节点添加和数据重分布,用户不应该直接调用该SQL语句。
    • DELETE NODE ( nodename [, … ] ) | DELETE CONTENT ( contentid [, … ] )
      • 以主机或实例为单位,从group_name指定的NodeGroup中,将指定的节点移除
      • 该语句仅仅修改系统表,不会进行实际的节点移除和数据重分布,用户不应该直接调用该SQL语句。
    • OWNER TO new_owner
      • 修改逻辑集群节点组的所有者
    • STATUS TO new_status
      • 修改逻辑集群节点组的状态,合法的状态值为 start, stop, starting, stopping
  17. 查看已有的逻辑集群

逻辑集群的信息,保存在 sc_node_group 这个系统表中,在 coordinator 上查询这个系统表,可以查看系统当前的逻辑集群/节点组的信息。如下的示例,演示创建和查询逻辑集群/节点组的过程:

test=# create node group lc1 with node(node1) lcgroup;
test=# create node group lc2 with node(node2, node3) lcgroup;

创建后的逻辑集群lc1包含node1主机上所有Executor实例,lc2包含node2、node3这两个主机上所有Executor实例。

查询sc_node_configuration系统表,查看整个集群拓扑,确定Executor实例与主机的对应关系

test=# select dbid, content, port, hostname, datadir from sc_node_configuration order by content;
 dbid | content | port  | hostname |                          datadir                           
------+---------+-------+----------+------------------------------------------------------------
    2 |      -2 | 11301 | coor1    | /mpp/seabox-data-directory-new/coordinatordd/1
    1 |      -1 | 11300 | coor2    | /mpp/seabox-data-directory-new/coordinatordd/0
    3 |       0 | 11381 | node1    | /mpp/seabox-data-directory-new/executordd/primary/0
    6 |       0 | 11400 | node1    | /mpp/seabox-data-directory-new/executordd/mirror/0
    7 |       1 | 11401 | node2    | /mpp/seabox-data-directory-new/executordd/mirror/1
    4 |       1 | 11382 | node3    | /mpp/seabox-data-directory-new/executordd/primary/1
    8 |       2 | 11402 | node3    | /mpp/seabox-data-directory-new/executordd/mirror/2
    5 |       2 | 11383 | node2    | /mpp/seabox-data-directory-new/executordd/primary/2
(8 rows)

查询sc_node_group系统表,查看逻辑集群/节点组的信息

test=# select oid, group_name, group_kind, group_acl, contents from sc_node_group;
  oid  | group_name | group_kind | group_acl | contents 
-------+------------+------------+-----------+----------
 16386 | grp1       | l          |           | 0
 16390 | grp2       | l          |           | 1 2
(3 rows)

说明: * sc_node_group系统表的contents列,保存的是 逻辑集群/节点组 包含的Executor实例,与 sc_node_configuration 系统表的 content 列对应 * group_kind列说明节点组的类型,为 'l' 表示是逻辑集群,如果为 'n' 表示是普通节点组(Node Group)

逻辑集群的权限管理

  1. 创建角色/用户时指定所属的逻辑集群节点组

  2. 语句

    • CREATE ROLE role_name NODE GROUP group_name
  3. 功能描述
    • 创建角色,指定其属于某个节点组。
  4. 注意事项
    • 这里列出的语法为在CREATE ROLE原有的语法基础上添加与节点组和逻辑集群相关的语法。CREATE ROLE原有语法和功能这里没有列出
  5. 语法格式

    CREATE ROLE role_name [ WITH ] NODE GROUP group_name
    
  6. 参数说明

    • group_name
      • 角色所属的node group名称。
      • 取值范围:已存在的节点组。
  7. 修改角色/用户时指定所属的逻辑集群节点组

  8. 语句

    • ALTER ROLE role_name [NODE GROUP group_name]
  9. 功能描述
    • 修改角色,指定其属于某个节点组
  10. 注意事项
    • 这里列出的语法为在ALTER ROLE原有的语法基础上添加与节点组和逻辑集群相关的语法。ALTER ROLE原有语法和功能这里没有列出
  11. 语法格式

    ALTER ROLE role_name [ WITH ] NODE GROUP group_name
    
  12. 参数说明

    • group_name
      • 修改角色使其属于的node group名称。
      • 取值范围:已存在的节点组。
  13. 赋予角色/用户对逻辑集群节点组的权限

  14. 语句

    • GRANT privileges ON NODE GROUP group_name TO role_name
  15. 功能描述
    • 把节点组的权限授予指定角色
  16. 注意事项
    • 这里列出的语法为在GRANT原有的语法基础上添加与节点组和逻辑集群相关的语法。GRANT原有语法和功能这里没有列出
  17. 语法格式

    GRANT { CREATE | USAGE | EXECUTE | ALL [ PRIVILEGES ] }
    ON NODE GROUP group_name [, ...]
    TO role_name;
    
  18. 参数说明

    • group_name
      • 授权的node group名称。
      • 取值范围:已存在的节点组。
    • role_name
      • 授予的角色名称
  19. 逻辑集群节点组的权限说明

    • 逻辑集群作为权限的客体有CREATE、USAGE和EXECUTE三种权限。CREATE权限可以在逻辑集群上创建对象,USAGE权限可以查询逻辑集群上的表对象,EXECUTE权限可以使用逻辑集群的计算资源执行查询语句。
  20. 回收角色/用户对逻辑集群节点组的权限

  21. 语句

    • REVOKE privileges ON NODE GROUP group_name FROM role_name
  22. 功能描述
    • 撤销指定角色在节点组上的权限
  23. 注意事项
    • 这里列出的语法为在REVOKE原有的语法基础上添加与节点组和逻辑集群相关的语法。REVOKE原有语法和功能这里没有列出
  24. 语法格式

    REVOKE { CREATE | USAGE | EXECUTE | ALL [ PRIVILEGES ] }
    ON NODE GROUP group_name [, ...]
    FROM role_name;
    
  25. 参数说明

    • group_name
      • 撤销权限的node group名称。
      • 取值范围:已存在的节点组。
    • role_name
      • 撤销权限的角色名称

在逻辑集群上建表和查询

  1. 在指定的逻辑集群/节点组上创建表

  2. 语句

    • CREATE TABLE tablename TO GROUP group_name
  3. 功能描述
    • 创建表,指定其属于某个节点组。
  4. 注意事项
    • 这里列出的语法为在CREATE TABLE原有的语法基础上添加的与节点组合逻辑集群相关的语法。CREATE TABLE原有的语法和功能这里没有列出
  5. 语法格式

    CREATE TABLE [...] tablename [...] TO GROUP group_name
    
  6. 参数说明

    • group_name
      • 表所属的node group名称。
      • 取值范围:已存在的节点组。
  7. 通过GUC参数设置存储或计算所属的默认的节点组/逻辑集群

  8. storage_nodegroup

    • 设置创建表所属的默认的节点组/逻辑集群
  9. execute_nodegroup

    • 设置用户期望承担查询运算的节点组/逻辑集群
  10. 逻辑集群模式下创建表时计算表所属的逻辑集群

  11. 如果建表语句中包含 TO GROUP 字句,则在TO GROUP字句指定的逻辑集群下建表

  12. 否则,如果设置了storage_nodegroup,则在该GUC参数指定的逻辑集群下建表
  13. 否则在用户所属的逻辑集群中建表
  14. 如果以上条件都不满足,则报错退出

  15. 查看表对象所属的逻辑集群

ssql中,可以使用 d 命令查看表所属的逻辑集群/节点组

test=# create table ta(a int, b int) distributed by(a) to group lc1;
test=# \d ta
                 Table "public.ta"
 Column |  Type   | Collation | Nullable | Default 
--------+---------+-----------+----------+---------
 a      | integer |           |          | 
 b      | integer |           |          | 
Distributed by: (a), Node Group: lc1
  1. 跨逻辑集群/节点组查询示例

  2. 连接操作(JOIN)

-- ta 表属于逻辑集群 lc1, tb 表属于逻辑集群 lc2
-- tb 表的数据重分布到 ta 所在的逻辑集群
select * from ta,tb where ta.a = tb.a;

-- 设置 execute_nodegroup 为 lc2 后,ta 表的数据重分布到 tb 所在的逻辑集群
set execute_nodegroup = lc2;
select * from ta,tb where ta.a = tb.a;
  • 集合操作
-- ta 表属于逻辑集群 lc1, tb 表属于逻辑集群 lc2
-- tb 表的数据重分布到 ta 所在的节点组
select * from ta union all select * from tb;

-- 设置 execute_nodegroup 为 lc2 后,ta 表的数据重分布到 tb 所在的节点组
set execute_nodegroup = lc2;
select * from ta union all select * from tb;

通过seabox工具集对逻辑集群进行管理

初始化自动创建逻辑集群

集群初始化时,在 seabox-site.yml 配置文件中配置逻辑集群的相关信息,就可以在集群初始化完成后,自动创建逻辑集群

seabox-site.yml 配置逻辑集群示例:

  lcgroup:
    - name : lc1
      nodes : [node1, node2, node3, node4]
    - name : lc2
      nodes : [node5, node6]

每个逻辑集群可以以 executor 节点主机名为单位添加,每个逻辑集群可以包含多个主机

集群初始化后,执行 seabox status -a 可以看到逻辑集群的配置结果:

lcgroup:
+------+----------+--------+
| name | contents | status |
+------+----------+--------+
| lc1  | 0,1,2,3  | start  |
| lc2  | 4,5      | start  |
+------+----------+--------+

executor 的状态中,会显示每个 executor 所属的逻辑集群,没有配置逻辑集群的 executor,也可以部署成功,只是不属于任何一个逻辑集群

executor:
+------+---------+---------+------+----------------+------+--------+-------+---------+------+
| dbid | content | lcgroup | role | preferred_role | mode | status | host  | address | port |
+------+---------+---------+------+----------------+------+--------+-------+---------+------+
|    4 | 0       | lc1     | p    | p              | s    | normal | node1 | node1   | 3800 |
|    5 | 1       | lc1     | p    | p              | s    | normal | node2 | node2   | 3800 |
|    6 | 2       | lc1     | p    | p              | s    | normal | node3 | node3   | 3800 |
|    7 | 3       | lc1     | p    | p              | s    | normal | node4 | node4   | 3800 |
|    8 | 4       | lc2     | p    | p              | s    | close  | node5 | node5   | 3800 |
|    9 | 5       | lc2     | p    | p              | s    | close  | node6 | node6   | 3800 |
|   10 | 6       |         | p    | p              | s    | normal | node7 | node7   | 3800 |
|   11 | 7       |         | p    | p              | s    | normal | node8 | node8   | 3800 |
|   12 | 0       | lc1     | m    | m              | s    | normal | node2 | node2   | 4000 |
|   13 | 1       | lc1     | m    | m              | s    | normal | node1 | node1   | 4000 |
|   14 | 2       | lc1     | m    | m              | s    | normal | node4 | node4   | 4000 |
|   15 | 3       | lc1     | m    | m              | s    | normal | node3 | node3   | 4000 |
|   16 | 4       | lc2     | m    | m              | s    | close  | node6 | node6   | 4000 |
|   17 | 5       | lc2     | m    | m              | s    | close  | node5 | node5   | 4000 |
|   18 | 6       |         | m    | m              | s    | normal | node8 | node8   | 4000 |
|   19 | 7       |         | m    | m              | s    | normal | node7 | node7   | 4000 |
+------+---------+---------+------+----------------+------+--------+-------+---------+------+

执行 seabox status -a -g [group name] 显示名为 [group name] 的逻辑集群的配置结果,以及属于其逻辑集群的 executor 的状态信息,例如 seabox status -a -g lc1 的执行结果:

lcgroup:
+------+----------+--------+
| name | contents | status |
+------+----------+--------+
| lc1  | 0,1,2,3  | start  |
+------+----------+--------+

executor 的状态中,只会显示属于逻辑集群 lc1 的 executor 的状态信息:

executor:
+------+---------+---------+------+----------------+------+--------+-------+---------+------+
| dbid | content | lcgroup | role | preferred_role | mode | status | host  | address | port |
+------+---------+---------+------+----------------+------+--------+-------+---------+------+
|    4 | 0       | lc1     | p    | p              | s    | normal | node1 | node1   | 3800 |
|    5 | 1       | lc1     | p    | p              | s    | normal | node2 | node2   | 3800 |
|    6 | 2       | lc1     | p    | p              | s    | normal | node3 | node3   | 3800 |
|    7 | 3       | lc1     | p    | p              | s    | normal | node4 | node4   | 3800 |
|   12 | 0       | lc1     | m    | m              | s    | normal | node2 | node2   | 4000 |
|   13 | 1       | lc1     | m    | m              | s    | normal | node1 | node1   | 4000 |
|   14 | 2       | lc1     | m    | m              | s    | normal | node4 | node4   | 4000 |
|   15 | 3       | lc1     | m    | m              | s    | normal | node3 | node3   | 4000 |
+------+---------+---------+------+----------------+------+--------+-------+---------+------+

单独启停某个逻辑集群

每个逻辑集群包含多个 executor,在逻辑上是一个完整的数据库集群,可以针对每个逻辑集群执行启动停止操作。

启动状态的逻辑集群的状态为 start,当逻辑集群停止后,会设置逻辑集群的状态为 stop,针对此逻辑集群的操作将会报错

  • 停止逻辑集群 lc1:
seabox stop -g lc2

逻辑集群停止后,执行 seabox status -a -k,可以看到 lc2 的状态切换为 stop

lcgroup:
+------+----------+--------+
| name | contents | status |
+------+----------+--------+
| lc1  | 0,1,2,3  | start  |
| lc2  | 4,5      | stop   |
+------+----------+--------+

属于 lc2 的 executor 状态也会变为 close

executor:
+------+---------+---------+------+----------------+------+--------+-------+---------+------+
| dbid | content | lcgroup | role | preferred_role | mode | status | host  | address | port |
+------+---------+---------+------+----------------+------+--------+-------+---------+------+
|    4 | 0       | lc1     | p    | p              | s    | normal | node1 | node1   | 3800 |
|    5 | 1       | lc1     | p    | p              | s    | normal | node2 | node2   | 3800 |
|    6 | 2       | lc1     | p    | p              | s    | normal | node3 | node3   | 3800 |
|    7 | 3       | lc1     | p    | p              | s    | normal | node4 | node4   | 3800 |
|    8 | 4       | lc2     | p    | p              | s    | close  | node5 | node5   | 3800 |
|    9 | 5       | lc2     | p    | p              | s    | close  | node6 | node6   | 3800 |
|   10 | 6       |         | p    | p              | s    | normal | node7 | node7   | 3800 |
|   11 | 7       |         | p    | p              | s    | normal | node8 | node8   | 3800 |
|   12 | 0       | lc1     | m    | m              | s    | normal | node2 | node2   | 4000 |
|   13 | 1       | lc1     | m    | m              | s    | normal | node1 | node1   | 4000 |
|   14 | 2       | lc1     | m    | m              | s    | normal | node4 | node4   | 4000 |
|   15 | 3       | lc1     | m    | m              | s    | normal | node3 | node3   | 4000 |
|   16 | 4       | lc2     | m    | m              | s    | close  | node6 | node6   | 4000 |
|   17 | 5       | lc2     | m    | m              | s    | close  | node5 | node5   | 4000 |
|   18 | 6       |         | m    | m              | s    | normal | node8 | node8   | 4000 |
|   19 | 7       |         | m    | m              | s    | normal | node7 | node7   | 4000 |
+------+---------+---------+------+----------------+------+--------+-------+---------+------+
  • 启动逻辑集群 lc2:
seabox start -g lc2

启动逻辑集群 lc2 后,执行 seabox status -a,逻辑集群和 executor 状态显示正常

lcgroup:
+------+----------+--------+
| name | contents | status |
+------+----------+--------+
| lc1  | 0,1,2,3  | start  |
| lc2  | 4,5      | start  |
+------+----------+--------+
executor:
+------+---------+---------+------+----------------+------+--------+-------+---------+------+
| dbid | content | lcgroup | role | preferred_role | mode | status | host  | address | port |
+------+---------+---------+------+----------------+------+--------+-------+---------+------+
|    4 | 0       | lc1     | p    | p              | s    | normal | node1 | node1   | 3800 |
|    5 | 1       | lc1     | p    | p              | s    | normal | node2 | node2   | 3800 |
|    6 | 2       | lc1     | p    | p              | s    | normal | node3 | node3   | 3800 |
|    7 | 3       | lc1     | p    | p              | s    | normal | node4 | node4   | 3800 |
|    8 | 4       | lc2     | p    | p              | s    | normal | node5 | node5   | 3800 |
|    9 | 5       | lc2     | p    | p              | s    | normal | node6 | node6   | 3800 |
|   10 | 6       |         | p    | p              | s    | normal | node7 | node7   | 3800 |
|   11 | 7       |         | p    | p              | s    | normal | node8 | node8   | 3800 |
|   12 | 0       | lc1     | m    | m              | s    | normal | node2 | node2   | 4000 |
|   13 | 1       | lc1     | m    | m              | s    | normal | node1 | node1   | 4000 |
|   14 | 2       | lc1     | m    | m              | s    | normal | node4 | node4   | 4000 |
|   15 | 3       | lc1     | m    | m              | s    | normal | node3 | node3   | 4000 |
|   16 | 4       | lc2     | m    | m              | s    | normal | node6 | node6   | 4000 |
|   17 | 5       | lc2     | m    | m              | s    | normal | node5 | node5   | 4000 |
|   18 | 6       |         | m    | m              | s    | normal | node8 | node8   | 4000 |
|   19 | 7       |         | m    | m              | s    | normal | node7 | node7   | 4000 |
+------+---------+---------+------+----------------+------+--------+-------+---------+------+

监控逻辑集群状态

集群监控服务会监控逻辑集群的状态,当逻辑集群包含的 executor 状态跟逻辑集群不符合时,集群监控服务会以逻辑集群状态为准,强制启动或停止此逻辑集群的 executor

对于逻辑集群的状态监控,有两个参数:

参数名称 功能
monitor_lcgroup_start_stop_monit 集群监控服务是否监控逻辑集群状态,可选值:0:不监控逻辑集群状态;1:监控逻辑集群状态。默认值:1
monitor_lcgroup_starting_stoping_time 集群监控服务,逻辑集群状态超时时间,单位:s。超过此时间 executor 的状态与逻辑集群状态不符,则 monitor 则会根据逻辑集群状态,强制启动或停止 executor。最小值:30,默认值:120

上述的两个参数,可以通过 seabox config 来进行查看和配置

例如: 用户执行了 seabox stop -g lc1 操作,经过了 120s,lc1 包含的 executor 依然不是 close 状态,则集群监控服务会强制停止非 close 状态的 executor

逻辑集群扩缩容

逻辑集群扩容

逻辑集群扩容是针对某一个特定逻辑集群的扩容,在扩容时,须指定逻辑集群的名称。如有以下集群拓扑:

lcgroup:
+------+--------+
| name | host   |
+------+--------+
| lc1  | test-1 |
| lc2  | test-1 |
+------+--------+

executor:
+------+---------+---------+------+----------+------+--------+------------+--------+--------+---------+-------+----------+---------------------------------------------+
| dbid | content | lcgroup | role | pre_role | mode | source | pre_source | status | host   | address |  port | pre_host | datadir                                     |
+------+---------+---------+------+----------+------+--------+------------+--------+--------+---------+-------+----------+---------------------------------------------+
|    3 | 0       | lc1     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31250 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/0  |
|    4 | 1       | lc1     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31251 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/1  |
|    5 | 2       | lc1     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31252 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/2  |
|    6 | 3       | lc2     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31253 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/3  |
|    7 | 4       | lc2     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31254 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/4  |
|    8 | 5       | lc2     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31255 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/5  |
|    9 | 0       | lc1     | a    | a        | s    | 3      | 3          | normal | test-1 | test-1  | 31270 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/0 |
|   10 | 1       | lc1     | a    | a        | s    | 4      | 4          | normal | test-1 | test-1  | 31271 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/1 |
|   11 | 2       | lc1     | a    | a        | s    | 5      | 5          | normal | test-1 | test-1  | 31272 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/2 |
|   12 | 3       | lc2     | a    | a        | s    | 6      | 6          | normal | test-1 | test-1  | 31273 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/3 |
|   13 | 4       | lc2     | a    | a        | s    | 7      | 7          | normal | test-1 | test-1  | 31274 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/4 |
|   14 | 5       | lc2     | a    | a        | s    | 8      | 8          | normal | test-1 | test-1  | 31275 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/5 |
+------+---------+---------+------+----------+------+--------+------------+--------+--------+---------+-------+----------+---------------------------------------------+

现在对逻辑集群lc1进行扩容,可按如下步骤进行扩容:

  1. 编写扩容配置文件

扩容配置文件同MPP集群相同。编写扩容配置文件expand_file, 内容如下:

test-1|test-1|31176|/home/hxm/dbdata/mpp/executordd/primary/6|15|6|p
test-1|test-1|31177|/home/hxm/dbdata/mpp/executordd/mirror/6|16|6|a
  1. 修改集群拓扑

执行命令:

scexpand -i ./expand_file --logical-cluster=lc1

可见,与普通mpp相比,多了指定逻辑集群名称的参数–logical-cluster。 这一步完成后,可见集群拓扑已经修改

  1. 重分布集群数据

执行:

scexpand  --logical-cluster=lc1

将数据进行重新分布,也是需要添加参数–logical-cluster

  1. 清理扩容元数据

执行:

scexpand  -c --logical-cluster=lc1

最后可见逻辑集群lc1集群拓扑已经修改。数据也已重新分布:

lcgroup:
+------+--------+
| name | host   |
+------+--------+
| lc1  | test-1 |
| lc2  | test-1 |
+------+--------+
executor:
+------+---------+---------+------+----------+------+--------+------------+--------+--------+---------+-------+----------+---------------------------------------------+
| dbid | content | lcgroup | role | pre_role | mode | source | pre_source | status | host   | address |  port | pre_host | datadir                                     |
+------+---------+---------+------+----------+------+--------+------------+--------+--------+---------+-------+----------+---------------------------------------------+
|    3 | 0       | lc1     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31250 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/0  |
|    4 | 1       | lc1     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31251 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/1  |
|    5 | 2       | lc1     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31252 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/2  |
|    6 | 3       | lc2     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31253 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/3  |
|    7 | 4       | lc2     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31254 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/4  |
|    8 | 5       | lc2     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31255 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/5  |
|    9 | 0       | lc1     | a    | a        | s    | 3      | 3          | normal | test-1 | test-1  | 31270 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/0 |
|   10 | 1       | lc1     | a    | a        | s    | 4      | 4          | normal | test-1 | test-1  | 31271 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/1 |
|   11 | 2       | lc1     | a    | a        | s    | 5      | 5          | normal | test-1 | test-1  | 31272 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/2 |
|   12 | 3       | lc2     | a    | a        | s    | 6      | 6          | normal | test-1 | test-1  | 31273 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/3 |
|   13 | 4       | lc2     | a    | a        | s    | 7      | 7          | normal | test-1 | test-1  | 31274 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/4 |
|   14 | 5       | lc2     | a    | a        | s    | 8      | 8          | normal | test-1 | test-1  | 31275 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/5 |
|   15 | 6       | lc1     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31176 | test-1   | /home/hxm/dbdata/mpp/executordd/primary/6   |
|   16 | 6       | lc1     | a    | a        | s    | 15     | 15         | normal | test-1 | test-1  | 31177 | test-1   | /home/hxm/dbdata/mpp/executordd/mirror/6    |
+------+---------+---------+------+----------+------+--------+------------+--------+--------+---------+-------+----------+---------------------------------------------+

逻辑集群缩容

与扩容相比,缩容也需要指定逻辑集群的名称。如上,以上述扩容结果为初始状态,可按照如下步骤进行缩容

  1. 缩容集群拓扑

执行:

scexpand  --shrink-contents="0,1" --logical-cluster=lc1

缩容时,需要用户输入要缩掉的executor对应的content值。可以缩掉多个,也可以是一个。可以不连续,只要是逻辑集群中的executor即可。 执行成功后,则将逻辑集群lc1中的content对应0和1的executor缩掉了,拓扑变为:

lcgroup:
+------+--------+
| name | host   |
+------+--------+
| lc1  | test-1 |
| lc2  | test-1 |
+------+--------+
executor:
+------+---------+---------+------+----------+------+--------+------------+--------+--------+---------+-------+----------+---------------------------------------------+
| dbid | content | lcgroup | role | pre_role | mode | source | pre_source | status | host   | address |  port | pre_host | datadir                                     |
+------+---------+---------+------+----------+------+--------+------------+--------+--------+---------+-------+----------+---------------------------------------------+
|    5 | 2       | lc1     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31252 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/2  |
|    6 | 3       | lc2     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31253 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/3  |
|    7 | 4       | lc2     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31254 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/4  |
|    8 | 5       | lc2     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31255 | test-1   | /home/hxm/dbdata/mpp2/executordd/primary/5  |
|   11 | 2       | lc1     | a    | a        | s    | 5      | 5          | normal | test-1 | test-1  | 31272 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/2 |
|   12 | 3       | lc2     | a    | a        | s    | 6      | 6          | normal | test-1 | test-1  | 31273 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/3 |
|   13 | 4       | lc2     | a    | a        | s    | 7      | 7          | normal | test-1 | test-1  | 31274 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/4 |
|   14 | 5       | lc2     | a    | a        | s    | 8      | 8          | normal | test-1 | test-1  | 31275 | test-1   | /home/hxm/dbdata/mpp2/executordd/mirror/0/5 |
|   15 | 6       | lc1     | p    | p        | s    | 0      | 0          | normal | test-1 | test-1  | 31176 | test-1   | /home/hxm/dbdata/mpp/executordd/primary/6   |
|   16 | 6       | lc1     | a    | a        | s    | 15     | 15         | normal | test-1 | test-1  | 31177 | test-1   | /home/hxm/dbdata/mpp/executordd/mirror/6    |
+------+---------+---------+------+----------+------+--------+------------+--------+--------+---------+-------+----------+---------------------------------------------+
  1. 删除扩缩容元数据

scexpand -c –logical-cluster=lc1

至此,缩容执行完毕

扩展新的逻辑集群

以上是对已有逻辑集群进行扩容,缩容。还可以通过扩容,创建出一个新的逻辑集群来。 如,原始集群拓扑:

lcgroup:
+------+--------+
| name | host   |
+------+--------+
| lc1  | e1, e2 |
+------+--------+
safe group:
+--------+--------+
| name   | host   |
+--------+--------+
| group0 | e1, e2 |
+--------+--------+
executor:
+------+---------+---------+------+----------+------+--------+------------+--------+------+---------+-------+----------+------------------------------------------+
| dbid | content | lcgroup | role | pre_role | mode | source | pre_source | status | host | address |  port | pre_host | datadir                                  |
+------+---------+---------+------+----------+------+--------+------------+--------+------+---------+-------+----------+------------------------------------------+
|    4 | 0       | lc1     | p    | p        | s    | 0      | 0          | normal | e1   | e1      | 31150 | e1       | /home/seabox/data/executordd/primary/0   |
|    5 | 1       | lc1     | p    | p        | s    | 0      | 0          | normal | e1   | e1      | 31151 | e1       | /home/seabox/data/executordd/primary/1   |
|    6 | 2       | lc1     | p    | p        | s    | 0      | 0          | normal | e2   | e2      | 31150 | e2       | /home/seabox/data/executordd/primary/2   |
|    7 | 3       | lc1     | p    | p        | s    | 0      | 0          | normal | e2   | e2      | 31151 | e2       | /home/seabox/data/executordd/primary/3   |
|    8 | 0       | lc1     | a    | a        | s    | 4      | 4          | normal | e2   | e2      | 31170 | e2       | /home/seabox/data/executordd/mirror1/0/0 |
|    9 | 1       | lc1     | a    | a        | s    | 5      | 5          | normal | e2   | e2      | 31171 | e2       | /home/seabox/data/executordd/mirror1/0/1 |
|   10 | 2       | lc1     | a    | a        | s    | 6      | 6          | normal | e1   | e1      | 31170 | e1       | /home/seabox/data/executordd/mirror1/0/2 |
|   11 | 3       | lc1     | a    | a        | s    | 7      | 7          | normal | e1   | e1      | 31171 | e1       | /home/seabox/data/executordd/mirror1/0/3 |
+------+---------+---------+------+----------+------+--------+------------+--------+------+---------+-------+----------+------------------------------------------+

通过执行scexpand,增加新的逻辑集群: scexpand -i ./scexpand_inputfile_20221111_080728 –logical-cluster=lc2 执行完成后,集群拓扑变为:

lcgroup:
+------+--------+
| name | host   |
+------+--------+
| lc1  | e1, e2 |
| lc2  | e3, e4 |
+------+--------+
safe group:
+--------+--------+
| name   | host   |
+--------+--------+
| group0 | e1, e2 |
+--------+--------+
executor:
+------+---------+---------+------+----------+------+--------+------------+--------+------+---------+-------+----------+------------------------------------------+
| dbid | content | lcgroup | role | pre_role | mode | source | pre_source | status | host | address |  port | pre_host | datadir                                  |
+------+---------+---------+------+----------+------+--------+------------+--------+------+---------+-------+----------+------------------------------------------+
|    4 | 0       | lc1     | p    | p        | s    | 0      | 0          | normal | e1   | e1      | 31150 | e1       | /home/seabox/data/executordd/primary/0   |
|    5 | 1       | lc1     | p    | p        | s    | 0      | 0          | normal | e1   | e1      | 31151 | e1       | /home/seabox/data/executordd/primary/1   |
|    6 | 2       | lc1     | p    | p        | s    | 0      | 0          | normal | e2   | e2      | 31150 | e2       | /home/seabox/data/executordd/primary/2   |
|    7 | 3       | lc1     | p    | p        | s    | 0      | 0          | normal | e2   | e2      | 31151 | e2       | /home/seabox/data/executordd/primary/3   |
|    8 | 0       | lc1     | a    | a        | s    | 4      | 4          | normal | e2   | e2      | 31170 | e2       | /home/seabox/data/executordd/mirror1/0/0 |
|    9 | 1       | lc1     | a    | a        | s    | 5      | 5          | normal | e2   | e2      | 31171 | e2       | /home/seabox/data/executordd/mirror1/0/1 |
|   10 | 2       | lc1     | a    | a        | s    | 6      | 6          | normal | e1   | e1      | 31170 | e1       | /home/seabox/data/executordd/mirror1/0/2 |
|   11 | 3       | lc1     | a    | a        | s    | 7      | 7          | normal | e1   | e1      | 31171 | e1       | /home/seabox/data/executordd/mirror1/0/3 |
|   12 | 4       | lc2     | p    | p        | s    | 0      | 0          | normal | e3   | e3      | 31150 | e3       | /home/seabox/data/executordd/primary/4   |
|   13 | 5       | lc2     | p    | p        | s    | 0      | 0          | normal | e3   | e3      | 31151 | e3       | /home/seabox/data/executordd/primary/5   |
|   14 | 6       | lc2     | p    | p        | s    | 0      | 0          | normal | e4   | e4      | 31150 | e4       | /home/seabox/data/executordd/primary/6   |
|   15 | 7       | lc2     | p    | p        | s    | 0      | 0          | normal | e4   | e4      | 31151 | e4       | /home/seabox/data/executordd/primary/7   |
|   16 | 6       | lc2     | a    | a        | s    | 14     | 14         | normal | e3   | e3      | 31170 | e3       | /home/seabox/data/executordd/mirror1/0/6 |
|   17 | 7       | lc2     | a    | a        | s    | 15     | 15         | normal | e3   | e3      | 31171 | e3       | /home/seabox/data/executordd/mirror1/0/7 |
|   18 | 4       | lc2     | a    | a        | s    | 12     | 12         | normal | e4   | e4      | 31170 | e4       | /home/seabox/data/executordd/mirror1/0/4 |
|   19 | 5       | lc2     | a    | a        | s    | 13     | 13         | normal | e4   | e4      | 31171 | e4       | /home/seabox/data/executordd/mirror1/0/5 |
+------+---------+---------+------+----------+------+--------+------------+--------+------+---------+-------+----------+------------------------------------------+
可见,集群已经完成在e3,e4节点上创建新的逻辑集群lc2的任务。 执行scexpand -i ./scexpand_inputfile –logical-cluster=logical_name 时,扩容程序会判断是否存在指定的逻辑集群。如果存在,则扩展已有逻辑集群,如前所述。如果不存在,则创建新的用户指定的逻辑集群。创建新的逻辑集群时,完成后,scexpand会提示“expansion with new logical cluster complete”, 提示用户所有任务已经完成了,无需进行scexpand以及scexpand -c等后续重分布任务了