Skip to content

Latest commit

 

History

History
281 lines (205 loc) · 22.3 KB

File metadata and controls

281 lines (205 loc) · 22.3 KB

角色切换与解耦

OceanBase 集群的租户角色分为主租户(PRIMARY)和备租户(STANDBY),本文介绍如何使用 OBD 动态改变租户角色,以及如何对主备租户解耦。

概念介绍

OceanBase 集群的租户角色包括两种:主租户(PRIMARY)和备租户(STANDBY)。正常情况下创建的普通租户角色均为主租户,使用物理备库方式创建的租户角色为备租户。

OBD 支持通过命令动态改变租户角色。

  • Switchover

    Switchover 操作是在用户计划内对租户角色进行变更。执行 Switchover 操作后,主租户会与对应的备租户会交换租户角色,整个过程数据不丢失,RPO = 0,执行时间一般为秒级。

  • Failover

    Failover 操作通常是在主租户出现无法恢复的故障时所做的切换行为。执行 Failover 操作后,对应的备租户角色会变换成 PRIMARY。同时,如果对主租户故障前一直正常同步的备租户执行 Failover 操作,则执行 Failover 操作后,一般会产生百毫秒级别的数据损失,执行时间一般为秒级。

  • Decouple

    Decouple 操作是在用户计划内对租户角色进行变更,执行 Decouple 操作后,对应的备租户会和主租户解耦,备租户角色会变换为 PRIMARY。

Switchover

执行 Switchover 操作后,为保证拓扑关系不变,原主租户下的其他备租户切换到新主租户下,新主租户下的其他备租户切换到新备租户下,即仅交换 Switchover 操作的两个主备节点,其他节点的位置保持不变,如下图所示。

Switchover

前提条件

  • OceanBase 数据库需为 V4.2.0.0 及以上版本

  • 主备租户所在的集群均为在线状态

  • 主备租户的状态均为 NORMAL,且备租户的日志传输状态(sync_status)为 NORMAL

  • 备租户所有日志流的副本均在线

  • 主租户的租户角色(tenant_role)需为 PRIMARY

操作步骤

  1. 执行如下命令查看备租户的主备关系

    obd cluster tenant show clusterB -g

    输出如下:

    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                                     tenant base info                                                                                    |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    | tenant_name | tenant_type | compatibility_mode | primary_zone | max_cpu | min_cpu | memory_size | max_iops            | min_iops            | log_disk_size | iops_weight | tenant_role |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    | sys         | SYS         | MYSQL              | RANDOM       | 1.0     | 1.0     | 2.0G        | 9223372036854775807 | 9223372036854775807 | 2.0G          | 1           | PRIMARY     |
    | B_a         | USER        | MYSQL              | RANDOM       | 2.0     | 2.0     | 4.0G        | 10000               | 10000               | 5.0G          | 2           | STANDBY     |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                   standby tenant standby info                                                                   |
    +---------------------+---------------+-------------+----------------------------+----------+---------------+-------------------+------------------+--------------+
    | standby_tenant_name | tenant_status | sync_status | sync_scn_timestamp         | err_code | error_comment | switchover_status | switchover_epoch | log_mode     |
    +---------------------+---------------+-------------+----------------------------+----------+---------------+-------------------+------------------+--------------+
    | B_a                 | NORMAL        | NORMAL      | 2023-09-14 09:43:00.199589 | 0        |               | NORMAL            | 0                | NOARCHIVELOG |
    +---------------------+---------------+-------------+----------------------------+----------+---------------+-------------------+------------------+--------------+
    +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                                         standby tenant`s primary info                                                                             |
    +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | standby_tenant_name | primary_tenant_info                                                                                                                                                         |
    +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | B_a                 | IP_LIST=10.10.10.1:2881;10.10.10.2:2881;10.10.10.3:2881,USER=standbyro@A_a,PASSWORD=******,TENANT_ID=1002,CLUSTER_ID=1694680744,COMPATIBILITY_MODE=MYSQL,IS_ENCRYPTED=false |
    +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    query primary-standby relation ok
    
    primary-standby relation topology graph
    
    clusterA:A_a
    └── clusterB:B_a
  2. 为备租户执行 Switchover 命令

    obd cluster tenant switchover clusterB B_a --tenant-root-password=******
  3. 再次查看原备租户的主备关系

    obd cluster tenant show clusterB -g

    输出如下

    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                                     tenant base info                                                                                    |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    | tenant_name | tenant_type | compatibility_mode | primary_zone | max_cpu | min_cpu | memory_size | max_iops            | min_iops            | log_disk_size | iops_weight | tenant_role |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    | sys         | SYS         | MYSQL              | RANDOM       | 1.0     | 1.0     | 2.0G        | 9223372036854775807 | 9223372036854775807 | 2.0G          | 1           | PRIMARY     |
    | B_a         | USER        | MYSQL              | RANDOM       | 2.0     | 2.0     | 4.0G        | 10000               | 10000               | 5.0G          | 2           | PRIMARY     |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    query primary-standby relation ok
    
    primary-standby relation topology graph
    
    clusterB:B_a
    └── clusterA:A_a

    输出中,原备租户的 tenant_role 已更新为 PRIMARY,且主备关系拓扑图也已更新。

Failover

Failover 操作适用于当主租户不可用时,可以将备租户切换为主租户继续提供服务。Failover 操作只会对日志文件做修改,不会对数据文件做修改。

由于 OceanBase 数据库的每个租户均有多个日志流,而 Failover 操作需要在操作执行完成后达到数据一致的状态,故系统会选择所有日志流的同步位点中 SCN 最小的值作为 Failover 的执行位点。执行Failover 操作后,租户下的所有日志流都会统一回退到该位点。

注意

在一主多备场景中,将一个备租户切换为主租户后,其他的备租户无法切换到新主租户下,您需自行选择解耦或对其他备租户执行 Failover 操作生成新的主租户。

前提条件

  • OceanBase 数据库需为 V4.2.0.0 及以上版本

  • 主租户所在集群为不可用状态

  • 备租户所在的集群为在线状态,且备租户的状态(tenant_status)需为 NORMAL

  • 备租户所有日志流的副本均在线

操作步骤

  1. 执行如下命令查看备租户的主备关系

    obd cluster tenant show clusterB -g

    输出如下:

    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                                     tenant base info                                                                                    |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    | tenant_name | tenant_type | compatibility_mode | primary_zone | max_cpu | min_cpu | memory_size | max_iops            | min_iops            | log_disk_size | iops_weight | tenant_role |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    | sys         | SYS         | MYSQL              | RANDOM       | 1.0     | 1.0     | 2.0G        | 9223372036854775807 | 9223372036854775807 | 2.0G          | 1           | PRIMARY     |
    | B_a         | USER        | MYSQL              | RANDOM       | 2.0     | 2.0     | 4.0G        | 10000               | 10000               | 5.0G          | 2           | STANDBY     |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                   standby tenant standby info                                                                   |
    +---------------------+---------------+-------------+----------------------------+----------+---------------+-------------------+------------------+--------------+
    | standby_tenant_name | tenant_status | sync_status | sync_scn_timestamp         | err_code | error_comment | switchover_status | switchover_epoch | log_mode     |
    +---------------------+---------------+-------------+----------------------------+----------+---------------+-------------------+------------------+--------------+
    | B_a                 | NORMAL        | NORMAL      | 2023-09-14 10:44:04.755016 | 0        |               | NORMAL            | 0                | NOARCHIVELOG |
    +---------------------+---------------+-------------+----------------------------+----------+---------------+-------------------+------------------+--------------+
    +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                                         standby tenant`s primary info                                                                             |
    +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | standby_tenant_name | primary_tenant_info                                                                                                                                                         |
    +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | B_a                 | IP_LIST=10.10.10.1:2881;10.10.10.2:2881;10.10.10.3:2881,USER=standbyro@A_a,PASSWORD=******,TENANT_ID=1002,CLUSTER_ID=1694680744,COMPATIBILITY_MODE=MYSQL,IS_ENCRYPTED=false |
    +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    query primary-standby relation ok
    
    primary-standby relation topology graph
    
    clusterA:A_a
    └── clusterB:B_a
  2. 为备租户执行 failover 命令

    obd cluster tenant failover clusterB B_a --tenant-root-password=******
  3. 再次查看原备租户的主备关系

    obd cluster tenant show clusterB -g

    输出如下,B_a 租户的 tenant_role 更新为 PRIMARY

    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                                     tenant base info                                                                                    |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    | tenant_name | tenant_type | compatibility_mode | primary_zone | max_cpu | min_cpu | memory_size | max_iops            | min_iops            | log_disk_size | iops_weight | tenant_role |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    | sys         | SYS         | MYSQL              | RANDOM       | 1.0     | 1.0     | 2.0G        | 9223372036854775807 | 9223372036854775807 | 2.0G          | 1           | PRIMARY     |
    | B_a         | USER        | MYSQL              | RANDOM       | 2.0     | 2.0     | 4.0G        | 10000               | 10000               | 5.0G          | 2           | PRIMARY     |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    query primary-standby relation ok

主备租户解耦

您可执行 decouple 命令将备租户解耦为一个和主租户无关的普通租户,本节介绍如何执行 decouple 命令进行主备租户解耦。

前提条件

  • OceanBase 数据库需为 V4.2.0.0 及以上版本

  • 备租户所在的集群为在线状态,且备租户的状态(tenant_status)需为 NORMAL

  • 备租户所有日志流的副本均在线

操作步骤

  1. 执行如下命令查看备租户的主备关系

    obd cluster tenant show clusterC -g

    输出如下:

    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                                     tenant base info                                                                                    |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    | tenant_name | tenant_type | compatibility_mode | primary_zone | max_cpu | min_cpu | memory_size | max_iops            | min_iops            | log_disk_size | iops_weight | tenant_role |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    | sys         | SYS         | MYSQL              | RANDOM       | 1.0     | 1.0     | 2.0G        | 9223372036854775807 | 9223372036854775807 | 2.0G          | 1           | PRIMARY     |
    | C_a         | USER        | MYSQL              | RANDOM       | 2.0     | 2.0     | 4.0G        | 10000               | 10000               | 5.0G          | 2           | STANDBY     |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                   standby tenant standby info                                                                   |
    +---------------------+---------------+-------------+----------------------------+----------+---------------+-------------------+------------------+--------------+
    | standby_tenant_name | tenant_status | sync_status | sync_scn_timestamp         | err_code | error_comment | switchover_status | switchover_epoch | log_mode     |
    +---------------------+---------------+-------------+----------------------------+----------+---------------+-------------------+------------------+--------------+
    | C_a                 | NORMAL        | NORMAL      | 2023-09-14 09:39:32.423752 | 0        |               | NORMAL            | 0                | NOARCHIVELOG |
    +---------------------+---------------+-------------+----------------------------+----------+---------------+-------------------+------------------+--------------+
    +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                                         standby tenant`s primary info                                                                             |
    +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | standby_tenant_name | primary_tenant_info                                                                                                                                                         |
    +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | C_a                 | IP_LIST=10.10.10.1:3881;10.10.10.2:3881;10.10.10.3:3881,USER=standbyro@B_a,PASSWORD=******,TENANT_ID=1002,CLUSTER_ID=1694681525,COMPATIBILITY_MODE=MYSQL,IS_ENCRYPTED=false |
    +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    query primary-standby relation ok
    
    primary-standby relation topology graph
    
    clusterA:A_a
    └── clusterB:B_a
        └── clusterC:C_a
  2. 为备租户执行解耦命令

    obd cluster tenant decouple clusterC C_a --tenant-root-password=******
  3. 再次查看原备租户的主备关系

    obd cluster tenant show clusterC -g

    输出如下,C_a 租户的 tenant_role 变为 PRIMARY

    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                                     tenant base info                                                                                    |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    | tenant_name | tenant_type | compatibility_mode | primary_zone | max_cpu | min_cpu | memory_size | max_iops            | min_iops            | log_disk_size | iops_weight | tenant_role |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    | sys         | SYS         | MYSQL              | RANDOM       | 1.0     | 1.0     | 2.0G        | 9223372036854775807 | 9223372036854775807 | 2.0G          | 1           | PRIMARY     |
    | C_a         | USER        | MYSQL              | RANDOM       | 2.0     | 2.0     | 4.0G        | 10000               | 10000               | 5.0G          | 2           | PRIMARY     |
    +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
    query primary-standby relation ok