feat(ha-config-bootstrap): implement OP_ctrlHello state sync handler (task 9.3)

This commit is contained in:
Rongsong Shen 2026-05-29 05:22:17 +00:00
parent 0ec0ffa7e3
commit 94bf5d94b8
9 changed files with 396 additions and 3 deletions

View file

@ -216,7 +216,7 @@ Dependency order: startup validation (D) unblocks vtaskmgr before election (A);
- _Requirements: 6.1_
- _Boundary: Persistent Control Channel (ha.c)_
- [ ] 9.3 Implement extended OP_ctrlHello handler and state sync sequence
- [x] 9.3 Implement extended OP_ctrlHello handler and state sync sequence
- Extend `CtrlHelloRequest` with `applied_lsn` and `config_tag`; extend `CtrlHelloReply` with `committed_lsn`, `needs_snapshot`, `config_tag`
- Primary side `handle_ctrlhello()`: `repl_add_standby()` → `repl_start_catchup()`; reply; if `needs_snapshot` → `persist_checkpoint()` + send `OP_snapshotTransfer`; stream `OP_walCatchupEntry` from `[standby.applied_lsn+1 → committed_lsn]`; on `OP_walAck` reaching `committed_lsn` → `repl_complete_catchup()`; if config_tag mismatch → call `push_config_to_standbys()`
- Standby side: store `last_known_committed_lsn`; call `persist_truncate_wal_above(primary_committed_lsn)`; set `in_catch_up=1`; apply `OP_snapshotTransfer` if present; apply each `OP_walCatchupEntry` via `apply_wal_entry()`; send `OP_walAck` after each; on catch-up end: `in_catch_up=0`