问题现象
OCP 主备架构下,黑屏执行 OceanBase 数据库备集群有损 Failover,obconfig_url 方式部署的 OBproxy 无法访问新主集群且重启无效。
问题原因
黑屏环境下 OceanBase 数据库主备集群 Failover 报错,集群变更信息不会同步至 OCP,引发主备切换后新主集群 obconfig_url 仍指向故障原主集群 Rslist 节点,连接异常。
影响租户
影响 OceanBase 数据库中的 SYS 租户和 Oracle 租户以及 MySQL 租户。
适用版本
OceanBase 数据库 V3.x 版本、OCP V4.x 版本。
解决方法
模拟 OCP 白屏 Failover 步骤,正确修正 OCP_meta 元数据。
备注
OCP 主集群存活时,登录主集群 ocp_meta 执行;OCP 主集群宕机时,备 OCP 切换为主集群后登录至新主 ocp_meta 执行。
ocp_meta 库 lock ob clusters (主、备集群)。
查询集群同步信息表 mc_ob_cluster。
select ocp_cluster_id,ob_cluster_id,type,lock_count,rootserver_json from mc_ob_cluster where ob_cluster_id in($standby_cluster_id,$primary_cluster_id);更新集群同步信息表 mc_ob_cluster 信息。
update mc_ob_cluster set locker_id = ?, lock_count = 1 where ob_cluster_id = ? and ob_cluster_name = ? and locker_id is null and lock_count = 0, args: [$ocp_cluster_id, $standby_cluster_id, $cluster_name] update mc_ob_cluster set locker_id = ?, lock_count = 1 where ob_cluster_id = ? and ob_cluster_name = ? and locker_id is null and lock_count = 0, args: [$ocp_cluster_id, $primary_cluster_id, $cluster_name]
备集群 sys 租户 Failover to Primary。
-- 设置 SQL 最大执行时间,单位是微秒。 set ob_query_timeout = 1000000000; -- 设置调度转储的间隔时间,默认为 20s,建议修改为 3s。 ALTER SYSTEM SET _ob_minor_merge_schedule_interval = '3s'; -- 设置控制 OceanBase 数据库 L0 转储的工作线程数为 16。 ALTER SYSTEM SET _mini_merge_concurrency = 16; -- 执行有损 Failover 命令,主库宕机,备库切换成主库。 ALTER SYSTEM ACTIVATE PHYSICAL STANDBY CLUSTER;确认 FAILOVER 结束。
select timestamp,facility,message from v$ob_cluster_event_history where facility like '%failover%' order by timestamp;输出结果如下:
+----------------------------+---------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | timestamp | facility | message | +----------------------------+---------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | 2024-08-08 19:29:09.645256 | failover to primary | flag:"start", ddl_stmt_str:"ALTER SYSTEM ACTIVATE PHYSICAL STANDBY CLUSTER", trace_id:xxxxx-xxxxx-xxxxx-xxxxx | | 2024-08-08 19:31:29.580348 | failover to primary | flag:"finish", failover#:1723116567631872, cost:139935091, ddl_stmt_str:"ALTER SYSTEM ACTIVATE PHYSICAL STANDBY CLUSTER", trace_id:xxxxx-xxxxx-xxxxx-xxxxx | +----------------------------+---------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+备集群 sys 租户 Failover to Primary
-- 设置调度转储的间隔时间为 20s。 ALTER SYSTEM SET _ob_minor_merge_schedule_interval = '20s'; -- 设置控制 OceanBase 数据库 L0 转储的工作线程数为 5. ALTER SYSTEM SET _mini_merge_concurrency = 5;ocp_meta 库 set abandoned status、update mc ob cluster。
update ob_cluster set status = 'ABANDONED' where ob_cluster_name = '$cluster_name' and ob_cluster_id = $primary_cluster_id; (原主集群) delete from mc_ob_cluster where ob_cluster_name = '$cluster_name' and ob_cluster_id = $primary_cluster_id; update mc_ob_cluster set type = 'PRIMARY' where ob_cluster_name = '$cluster_name' and ob_cluster_id = $standby_cluster_id; (新主集群)新主集群 sys 租户 Remove standby cluster。
-- 删除一个已经存在的备库。 ALTER SYSTEM REMOVE CLUSTER $cluster_name cluster_id = $primary_cluster_id; (原主集群)ocp_meta 库 unlock ob clusters。
-- 更新集群同步信息表 mc_ob_cluster 信息。 update mc_ob_cluster set locker_id = null, lock_count = 0 where ob_cluster_id = $standby_cluster_id and ob_cluster_name = '$cluster_name' and locker_id = $ocp_cluster_id and lock_count = 1; (新主集群)查询集群同步信息表 mc_ob_cluster。
select ocp_cluster_id, ob_cluster_id, ob_cluster_name, ocp_ob_cluster_id, type, architecture, rootserver_json, ob_version, locker_id, lock_count from mc_ob_cluster where ob_cluster_name = '$cluster_name' and ob_cluster_id = $standby_cluster_id;重启备集群 OBProxy 验证连接。