Files
orbit/docs/reports/phase-6-mysql-replication.md

38 lines
2.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# P6:MySQL GTID 复制与手工提升演练
验证日期:2026-09-20。新增 `scripts/test-mysql-replication.sh`,在两个一次性 MySQL 8.4 容器中使用原生 GTID 复制,先由源库承载真实 Orbit HTTP 受理,再停止源库、提升副本并用原幂等键重放请求。演练不连接已有数据库,也不修改生产数据。
## 实际环境与命令
使用 Docker `golang:1.27.1` 交叉构建 macOS arm64 的当前 `orbit`、`orbit-migrate` 和 `orbit-admin`,随后在宿主机执行:
```sh
ORBIT_BIN=/tmp/orbit-go127-darwin/orbit \
ORBIT_MIGRATE_BIN=/tmp/orbit-go127-darwin/orbit-migrate \
ORBIT_ADMIN_BIN=/tmp/orbit-go127-darwin/orbit-admin \
ORBIT_TEST_MYSQL_IMAGE=mysql:8.4 \
sh scripts/test-mysql-replication.sh
```
脚本使用普通 Docker bridge 映射宿主机端口,避免 Docker Desktop 的 host network 只对容器可见;副本通过源容器 IP 和内部 3306 端口连接。两个数据库均启用 `gtid_mode=ON`、`enforce_gtid_consistency=ON`、行格式 binlog 和独立 `server_id`。源库和副本均随机生成密码,副本提升前保持 `read_only`/`super_read_only`。
## 实际结果
```json
{"replication_io_sql":"Yes:Yes","replicated_task_rows":1,"source_stopped":true,"manual_promotion_verified":true,"idempotent_replay_same_task":true,"automatic_failover":false}
```
真实步骤包括:
1. 迁移源库并签发通用应用凭据;
2. 对源库执行带 GTID 的逻辑基线导入副本;
3. 建立复制并核对 `Replica_IO_Running=Yes`、`Replica_SQL_Running=Yes`;
4. 通过源库上的 Orbit HTTP 提交任务,确认副本收到任务记录;
5. 停止源库,停止复制并提升副本为可写;
6. 用原凭据和原幂等键启动 Orbit,重放后返回同一个任务身份;
7. 用 `orbit-admin verify` 核对提升后的迁移版本、固定索引和零外键。
## 边界
这次演练证明 MySQL 原生 GTID 复制、手工提升、Orbit 重新连接和幂等重放可以在隔离拓扑中工作;它不提供自动故障探测、虚拟 IP、代理路由或零停机切换。没有测量复制延迟上限、网络分区、双主写入、磁盘损坏、跨故障域、备份介质、RPO/RTO 或生产容量。上线前仍需在批准的 MySQL 主从/集群拓扑中确定切换执行人、读写路由、复制确认、恢复点和恢复时间,并完成业务副作用核对。