1. Step 更新
- streaming_diaster_recovery_start.py
def run(self):
self.logger.log("Start create streaming disaster relationship.")
step = self.query_streaming_step()
self._first_step_for_streaming_start(step)
self.parse_cluster_status()
self._check_and_refresh_disaster_user_permission()
self._second_step_for_streaming_start(step) # 2_check_cluster_step
self.common_step_for_streaming_start()
self._third_step_for_streaming_start(step) # 3_set_wal_segments_step
self._fourth_step_for_streaming_start(step) # 4_set_wal_segments_step
self._fifth_step_for_streaming_start(step) # 5_set_wal_segments_step
self._sixth_step_for_streaming_start(step) # 6_set_guc_step
self._seventh_step_for_streaming_start(step) # 7_build_dn_instance_step
self._eighth_step_for_streaming_start(step) # 8_start_cluster_step
self._ninth_step_for_streaming_start(step)
self.logger.log("Successfully do streaming disaster recovery start.")
- 日志中的对应:
Start seventh step of streaming start.
...
Streaming action:[start] record current step:[7_build_dn_instance_step]
- 在 step 文件中记录之前执行到了哪一步,日志会记录 step 文件的名字:
[start][DEBUG]:Init step file:/database/panweidb/tmp/streaming_cabin/.streaming_start_standby.step.
- 有些步骤在完成后不会在日志中打印 record current step,意味着完成后不会在 step 文件中记录;
- 基于此,sdr start可实现失败重入。
2. 状态更新
sdr 初始状态为 normal,在第7和8步,会更新状态。

2.1 7_build_dn_instance_step
主集群
主集群在这一步不会执行任何操作,也不会更新状态。
备集群
- 一进入第七步,更新状态为 restore;
- 随后重建备集群,如果报错,更新状态为 restore_fail.
重建备集群是指:
- build main standby:检查与主集群主节点的连接 -> 备份 pg_hba.conf -> 备份 pg_ident.conf -> build -> 恢复 pg_hba.conf -> 恢复 pg_ident.conf -> 启动 main standby
- build cascade standby
2.2 8_start_cluster_step
主集群
- 一进入第八步,更新状态为 full_backup;
- 随后在 --time-out 内不断检测与 main standby 的连接(通常情况下是在等待 main standby build完并启动):
- 检测到连接成功 -> 更新状态为 archive
- 报错(包括超时)-> 更新状态为 backup_fail
备集群
在这一步会启动集群,并使用 cm_ctl query | grep cluster_state 检查集群状态:
- Normal -> 更新状态为 recovery
- 不是 Normal -> 更新状态为 recovery_fail
2.3 正常情况
- 主集群:normal -> full_backup -> archive
- 备集群:normal -> restore -> recovery
日志示例:
[36d7a0f4960711ef92aa0050568e7c85][2024-10-29 23:05:52.038238][1069440][start][DEBUG]:Start sixth step of streaming start.
[36d7a0f4960711ef92aa0050568e7c85][2024-10-29 23:05:52.929056][1069440][start][DEBUG]:Streaming action:[start] record current step:[6_set_guc_step]
[36d7a0f4960711ef92aa0050568e7c85][2024-10-29 23:05:52.929629][1069440][start][DEBUG]:Start seventh step of streaming start.
[36d7a0f4960711ef92aa0050568e7c85][2024-10-29 23:05:52.929779][1069440][start][DEBUG]:Update query [cluster] to [restore].
[36d7a0f4960711ef92aa0050568e7c85][2024-10-29 23:05:52.930169][1069440][start][DEBUG]:Got connected nodes:['xxx', 'xxx', 'xxx'] for action:update_streaming_info
[36d7a0f4960711ef92aa0050568e7c85][2024-10-29 23:05:53.417405][1069440][start][DEBUG]:Start building process.
[36d7a0f4960711ef92aa0050568e7c85][2024-10-29 23:05:53.418711][1069440][start][DEBUG]:Start build main standby dn:6001
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




