Commit 48c02be
authored
keeper: send node_active reports to monitor during graceful shutdown (#1146)
* keeper: send node_active reports to monitor during graceful shutdown
On SIGTERM, the node-active service's main loop exits immediately, before
calling keeper_update_pg_state() or service_keeper_node_active(). This
leaves the monitor unaware that node1 is going offline until its next
health-check poll, causing the flaky behaviour seen in ensure::test_004_demoted
where node2 never reached wait_primary within the test timeout.
Add keeper_node_active_shutdown_loop(): after the main loop breaks on
asked_to_stop, report the current Postgres state to the monitor every 1s
for up to 30 seconds (or until Postgres stops or an escalated signal
arrives). This runs concurrently with the postgres-controller service
calling 'pg_ctl stop -m fast': fast mode sends SIGTERM to the postmaster,
which stops accepting new connections immediately, while the checkpoint
completes asynchronously. By the time the first shutdown report fires,
Postgres is already refusing connections; the monitor can start failover
right away rather than waiting for a health-check timeout.
SIGINT (asked_to_stop_fast) and SIGQUIT (asked_to_quit) skip the shutdown
loop and exit immediately, as before.
* fix ensure::test_003: re-enable auto-start after stop postgres
test_003_init_secondary stops postgres on node2 then waits for it to
recover as secondary. The original Python test (node2.stop_postgres())
sends SIGTERM directly to postgres without touching pg_autoctl's service
controller, so the keeper auto-restarts postgres.
The pgaftest port used 'stop postgres node2' which calls
'pg_autoctl manual service pgctl off' — this both stops postgres AND
disables auto-restart. As a result node2's postgres stayed stopped for
the rest of the spec.
In test_004_demoted, NodeIsHealthy(node2) checks pgIsRunning, which was
false because node2's postgres was never restarted. The failover
transition at group_state_machine.c:550 requires NodeIsHealthy(activeNode)
to be true, so the failover never triggered and the test timed out at 180s.
Fix: add 'start postgres node2' immediately after 'stop postgres node2'
to call 'pg_autoctl manual service pgctl on', re-enabling the keeper's
auto-restart. The keeper restarts postgres and node2 converges back to
secondary before test_004 runs.1 parent 53a1a9d commit 48c02be
2 files changed
Lines changed: 71 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
247 | 302 | | |
248 | 303 | | |
249 | 304 | | |
| |||
659 | 714 | | |
660 | 715 | | |
661 | 716 | | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
662 | 727 | | |
663 | 728 | | |
664 | 729 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
44 | 49 | | |
| 50 | + | |
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
| |||
0 commit comments