Skip to content

Refactor Node::run() with strategy pattern (Learner/Voter bootstrap) #217

@JoshuaChi

Description

@JoshuaChi

Changes

Refactored Node::run() to eliminate scattered control flow and improve code clarity:

Before: Multiple is_learner() checks scattered throughout, mixed Learner/Voter logic
After: Strategy pattern with clear separation:

  • run_as_learner() - Learner-specific bootstrap
  • run_as_voter() - Voter-specific bootstrap
  • warmup_with_shutdown() - Extracted common shutdown handling
  • start_raft_loop() - Shutdown-aware main loop entry

Benefits

  • Single point of role branching (one is_learner() check)
  • Eliminates code duplication in shutdown handling
  • Clear, linear bootstrap flow for each node type
  • Fixes potential race: shutdown check before raft.run()
  • Better reflects Raft protocol semantics (Learners don't need cluster quorum)

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:docsDocumentation, guides, API references, examples.type:refactorCode restructuring without changing external behavior

    Type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions