Add 'pg_autoctl inspect fsm mermaid' phase diagrams for the keeper FSM#1164
Merged
Conversation
…nual Graphviz doc image Splits the 77-transition keeper FSM into 5 phase diagrams (init, steady-state, failover, maintenance, removal) generated directly from KeeperFSM[], since the full graph is too dense to read as one image. Citus-specific transitions are not shown separately: every one of the 15 Citus-specific (current, assigned) pairs already exists under NODE_KIND_ANY, so a standalone Citus diagram would be graph-isomorphic to the others. Colour scheme groups states by role (meta/primary/secondary/demoting/ maintenance/election) via Mermaid classDef/class. States appearing in more than one phase are annotated in each diagram via 'note right of' naming the other phase(s), verified against a hand-curated but fully covered (current, assigned) -> phase classification table. Docs: docs/failover-state-machine.rst now embeds the 5 generated diagrams (sphinxcontrib.mermaid, already a dependency) in place of the old fsm.png/dot pipeline; pg_autoctl inspect fsm gv is left in the code for anyone who wants the single full graph, but is no longer the documented way to visualize the FSM.
join_primary is no longer assigned to any node (see the existing 'Join_primary' doc section) -- KeeperFSM[] still carries its 9 transitions for backward compatibility with on-disk state from old versions, but showing them just adds noise to diagrams describing current behaviour. Filtered in the generator itself (skips any edge touching JOIN_PRIMARY_STATE) and removed the now-dead rows from the phase classification table. 77 edges -> 68 edges across the five diagrams; verified zero dropped/warned edges and zero remaining join_primary mentions after rebuilding.
…adow table The previous commit introduced a separate FsmPhaseMap[] array duplicating (current, assigned) pairs already present in KeeperFSM[] -- real double maintenance: every future KeeperFSM[] edit would need a matching, easy to forget update to a second table, with only a runtime warning (not the compiler) catching drift, and no check at all for stale entries left behind in FsmPhaseMap after a KeeperFSM[] row changes. Add FsmPhase as a field directly on KeeperFSMTransition (fsm.h), and set it on each NODE_KIND_ANY row in KeeperFSM[] (fsm.c) -- the 77 real transitions, curated by hand once against their own transition comments, same classification as before, just living in the one table that already exists. Citus-specific rows and the NO_STATE sentinel are left at the implicit zero value (FSM_PHASE_NONE): they're skipped by the mermaid generator's existing NODE_KIND_ANY filter before phase is ever consulted. fsm_mermaid.c now walks KeeperFSM[] directly and groups by transition.phase, exactly the way print_fsm_for_graphviz() already walks it to dump every row -- no separate lookup table, no separate loop. The missing-classification safety net moves with it: a NODE_KIND_ANY row left at FSM_PHASE_NONE still logs a warning instead of silently vanishing from every diagram. Verified behaviour-preserving: all 5 generated diagrams are byte-for-byte identical to the pre-refactor output, zero warnings on any of them, and 'pg_autoctl inspect fsm gv' (which never looks at the new field) is unaffected. citus_indent (via Docker) made no formatting changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replaces the hand-maintained Graphviz FSM diagram (
docs/fsm.png, regenerated by hand viapg_autoctl inspect fsm gv | dot, last touched in 2021) with five smaller diagrams generated directly fromKeeperFSM[](src/bin/pg_autoctl/fsm.c), so they can never drift out of sync with the actual state machine.The full FSM is 20 states and 77 transitions — legible as a reference table, but too dense to read at a glance as a single diagram. New commands split it by phase of a node's life:
Each prints a Mermaid
stateDiagram-v2program, embedded directly indocs/failover-state-machine.rstviasphinxcontrib.mermaid(already a docs dependency).Design notes
(current, assigned) -> phasetable infsm_mermaid.c, verified at runtime: every transition lands in exactly one diagram (alog_warnfires if a futureKeeperFSM[]change ever adds an edge the table doesn't cover — nothing silently disappears).(current, assigned)pairs already exist underNODE_KIND_ANY— a separate Citus diagram would be graph-isomorphic to "failover," so it's called out as a note there instead.join_primaryis excluded. It's long deprecated and no longer assigned to any node (see the existing "Join_primary" doc section);KeeperFSM[]still carries its 9 transitions for backward compatibility with on-disk state from old versions, but showing them just adds noise. 77 edges -> 68 shown.note right of Xnaming every other phase that state also appears in.classDef/class, consistent across all five: grey (lifecycle/admin), blue (primary-like), green (secondary-like), red (primary going away), purple (maintenance), amber (multi-standby election machinery).pg_autoctl inspect fsm gv(Graphviz) is left in place for anyone who wants the single full graph (join_primary included) for their own tooling — it's just no longer the documented way to visualize the FSM.Verification
make -C src/bin/pg_autoctl) clean, no warnings.inspect fsm mermaid <phase>commands run and produce valid Mermaid syntax — caught and fixed one real bug along the way: a colon insidenotetext collides with Mermaid'snote right of X : textdelimiter grammar (verified againstmermaid@11.12.1directly).join_primaryconfirmed absent everywhere.KeeperFSM[]transitions minus the 9 involvingjoin_primary, with zero dropped and zero duplicated.