Files
suaveplan/docs/old-network-planning/SERVER_FAILOVER.md
2026-05-27 23:29:53 +01:00

7.3 KiB

Server Failover and Reintegration Scenario

Overview

This document outlines a critical network scenario: server disconnection with automatic client-side hosting, followed by eventual server reintegration. This capability is a core strength of our hierarchical network architecture and should be carefully implemented and tested.

Scenario Description

  1. Initial State: Server acts as the top-level host (Level 4 or higher)
  2. Server Disconnection: Server becomes unavailable (crash, network partition, etc.)
  3. Client Reorganization: Clients detect server absence and reorganize into a self-sustaining hierarchy
  4. Autonomous Operation: Network continues functioning with client-side hosting
  5. Server Return: Server reconnects to the network
  6. Reintegration: Server smoothly reintegrates as the top-level host
  7. State Synchronization: Changes made during server absence are reconciled

Implementation Requirements

1. Disconnection Detection

The system must quickly and reliably detect server unavailability:

  • Heartbeat Monitoring: Regular ping/pong between tier levels
  • Timeout Configuration: Configurable thresholds for declaring disconnection
  • Verification Mechanism: Differentiate between temporary connectivity issues and true disconnection
  • Consensus Requirement: Multiple nodes should agree on server unavailability before triggering reorganization

2. Tier Reorganization

Once server disconnection is confirmed, the network must reorganize:

  • Emergency Voting: Trigger immediate voting for new top-tier host
  • Candidate Selection: Identify qualified clients that can serve as top-tier host
  • Hierarchy Preservation: Maintain as much of the existing hierarchy as possible
  • Minimal Disruption: Limit reorganization to essential changes

3. Client-Side Hosting

The client-based hierarchy must efficiently manage communication:

  • Tiered Structure:

    • Level 0: Regular clients (leaf nodes)
    • Level 1: Host clients managing small groups of clients
    • Level 2: Tier hosts managing groups of hosts
    • Level 3+: Higher-tier hosts (if network size requires it)
  • Resource Management:

    • Hosts must operate within device capability constraints
    • Load balancing across hosts at the same level
    • Adaptive tier depth based on network size
  • Role Adaptation:

    • Clients must implement all host functionality
    • Node behavior adapts based on assigned level
    • Level-specific configuration parameters

4. Server Reintegration

When the server returns, the system must handle its reintegration:

  • Detection: Recognize returning server
  • Role Restoration: Reestablish server as top-tier host
  • Smooth Transition: Minimize disruption during reintegration
  • Hierarchy Adjustment: Adapt tier structure as needed

5. State Synchronization

Changes made during server absence must be reconciled:

  • Change Tracking: Record state changes during server disconnection
  • Conflict Resolution: Resolve conflicting changes (server vs. client-side)
  • Delta Synchronization: Efficiently transfer only necessary changes
  • Validation: Verify state consistency after reconciliation

Component Responsibilities

TierManager

  • Detect empty top tier (server absence)
  • Orchestrate reorganization process
  • Handle smooth reintegration when server returns
  • Maintain hierarchy integrity throughout

VotingManager

  • Conduct emergency voting for new top-tier host
  • Select best-qualified clients for promotion
  • Facilitate server reintegration voting (if needed)
  • Apply appropriate voting thresholds for emergency scenarios

NetworkNode

  • Adapt behavior based on dynamic level changes
  • Implement functionality for all potential roles
  • Handle connection management during transitions
  • Maintain state during role changes

StateManager

  • Track state changes during server disconnection
  • Facilitate efficient state transfer during reintegration
  • Resolve conflicts between server and client states
  • Ensure data consistency across the network

Implementation Approach

The implementation should follow these principles:

  1. Graceful Degradation:

    • Network functionality should degrade gracefully when server is unavailable
    • Essential functions continue with client-side hosting
    • Optional features may be disabled during server absence
  2. Autonomous Operation:

    • Client network should function indefinitely without server
    • All critical voting and reorganization logic present in client code
    • No dependency on server for ongoing operation
  3. Seamless Transitions:

    • Users should experience minimal disruption during server disconnect/reconnect
    • Message delivery should continue throughout transitions
    • Session continuity should be maintained
  4. Resilience:

    • System should handle multiple disconnection/reconnection cycles
    • Recovery from partial failures during transition
    • Handling of edge cases like server disconnect during reorganization

Testing Scenarios

1. Basic Server Failover

  • Setup: Network with server and multiple clients
  • Action: Force server disconnection
  • Expected: Clients reorganize and continue functioning
  • Validation: Messages continue to flow, hierarchy reforms

2. Long-Duration Server Absence

  • Setup: Network with server and multiple clients
  • Action: Server disconnects for extended period (hours)
  • Expected: Client-side hosting remains stable
  • Validation: Network functions correctly even after long server absence

3. Server Reintegration

  • Setup: Network operating with client-side hosting after server disconnect
  • Action: Server reconnects to network
  • Expected: Server reintegrates as top-level host
  • Validation: Hierarchy adjusts, server resumes top-level control

4. State Synchronization

  • Setup: Server disconnects, clients make state changes
  • Action: Server reconnects after significant state changes
  • Expected: States are properly synchronized
  • Validation: All nodes have consistent state after reintegration

5. Repeated Disconnect/Reconnect

  • Setup: Network with server and multiple clients
  • Action: Server rapidly disconnects and reconnects multiple times
  • Expected: System remains stable despite frequent changes
  • Validation: Network topology stabilizes after disruptions

Implementation Tracking

Key success indicators for this scenario:

  1. Disconnection Detection Time: How quickly server absence is detected
  2. Reorganization Speed: Time to establish client-side hosting
  3. Message Continuity: Percentage of messages delivered during transition
  4. Reintegration Smoothness: Time to reintegrate server and stabilize
  5. State Consistency: Accuracy of state after synchronization

Integration Points

This scenario requires integration between multiple components:

  • TierManager: Handles hierarchy changes
  • VotingManager: Selects new hosts at each level
  • StateManager: Ensures data consistency
  • MessageRouter: Maintains communication throughout
  • TransportManager: Handles connection management

By thoroughly implementing and testing this server failover scenario, the library will provide robust support for applications that require continuous operation even when servers become unavailable, with minimal disruption when servers return.