feat(ha): add phase2_done, repl_ack_count, n_peers, client_ssl_ctx fields and CTRL_PRIMARY_COMMITTING enum
Task 2.1 of election-iomgr-refactor spec. Adds the new ha_state_t fields required for the COMMITTING phase FSM, the CTRL_PRIMARY_COMMITTING role enum value, and the committing_timeout_ms config field with its default constant. ha_init() explicitly zero-initialises all new fields. Unit test verifies zero-init and enum distinctness. Requirements: 5.2, 8.1 (election-iomgr-refactor spec)
This commit is contained in:
parent
c3caab49a6
commit
e42564b3bd
3 changed files with 79 additions and 14 deletions
|
|
@ -53,10 +53,11 @@ void ha_seed_jitter(uint64_t *seed, int my_priority);
|
|||
|
||||
/* ── Role enum ─────────────────────────────────────────────── */
|
||||
typedef enum {
|
||||
CTRL_PRIMARY = 0,
|
||||
CTRL_STANDBY = 1,
|
||||
CTRL_INIT = 2, /* Startup: listener open, awaiting heartbeat or election timeout */
|
||||
CTRL_ELECTING = 3 /* Running quorum election via OP_requestVote */
|
||||
CTRL_PRIMARY = 0,
|
||||
CTRL_STANDBY = 1,
|
||||
CTRL_INIT = 2, /* Startup: listener open, awaiting heartbeat or election timeout */
|
||||
CTRL_ELECTING = 3, /* Running quorum election via OP_requestVote */
|
||||
CTRL_PRIMARY_COMMITTING = 4 /* Primary waiting for quorum ACK on config commit */
|
||||
} ctrl_role_t;
|
||||
|
||||
/* ── Election types ────────────────────────────────────────── */
|
||||
|
|
@ -97,22 +98,24 @@ typedef struct {
|
|||
/* ── HA configuration ──────────────────────────────────────── */
|
||||
|
||||
/* Default values used by cluster_init(). Tuned for a LAN with ≤5ms RTT. */
|
||||
#define HA_DEFAULT_HEARTBEAT_INTERVAL_MS 3000
|
||||
#define HA_DEFAULT_HEARTBEAT_TIMEOUT_MS 10000
|
||||
#define HA_DEFAULT_ELECTION_TIMEOUT_MS 2000
|
||||
#define HA_DEFAULT_PROBE_CONNECT_TIMEOUT_MS 500
|
||||
#define HA_DEFAULT_MAX_PROMOTION_RETRIES 5
|
||||
#define HA_DEFAULT_HEARTBEAT_INTERVAL_MS 3000
|
||||
#define HA_DEFAULT_HEARTBEAT_TIMEOUT_MS 10000
|
||||
#define HA_DEFAULT_ELECTION_TIMEOUT_MS 2000
|
||||
#define HA_DEFAULT_PROBE_CONNECT_TIMEOUT_MS 500
|
||||
#define HA_DEFAULT_MAX_PROMOTION_RETRIES 5
|
||||
#define HA_DEFAULT_ELECTION_JITTER_MAX_MS 200
|
||||
#define HA_DEFAULT_ELECTION_PRIORITY_STEP_MS 500
|
||||
#define HA_DEFAULT_COMMITTING_TIMEOUT_MS 10000
|
||||
|
||||
typedef struct {
|
||||
uint32_t heartbeat_interval_ms; /* Primary heartbeat send interval (min 2000 ms) */
|
||||
uint32_t heartbeat_timeout_ms; /* Standby timeout before promoting (>= interval) */
|
||||
uint32_t election_timeout_ms; /* Election probe shared deadline (min 500 ms) */
|
||||
uint32_t probe_connect_timeout_ms; /* Per-probe TCP connect timeout */
|
||||
uint32_t max_promotion_retries; /* Max consecutive failed promotion attempts */
|
||||
uint32_t heartbeat_interval_ms; /* Primary heartbeat send interval (min 2000 ms) */
|
||||
uint32_t heartbeat_timeout_ms; /* Standby timeout before promoting (>= interval) */
|
||||
uint32_t election_timeout_ms; /* Election probe shared deadline (min 500 ms) */
|
||||
uint32_t probe_connect_timeout_ms; /* Per-probe TCP connect timeout */
|
||||
uint32_t max_promotion_retries; /* Max consecutive failed promotion attempts */
|
||||
uint32_t election_jitter_max_ms; /* random jitter added to election timeout (default 200) */
|
||||
uint32_t election_priority_step_ms; /* extra ms per priority level (default 500) */
|
||||
uint32_t committing_timeout_ms; /* Quorum-ACK deadline for CTRL_PRIMARY_COMMITTING (default 10000) */
|
||||
} ha_config_t;
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -157,6 +160,11 @@ typedef struct {
|
|||
sem_t heartbeat_seen; /* Req 1: posted by heartbeat handler during CTRL_INIT */
|
||||
uint64_t last_known_committed_config_tag; /* Req 8: from primary heartbeats */
|
||||
_Atomic uint64_t committed_config_tag; /* Req 8.1: set on quorum ACK */
|
||||
/* ── New fields added by election-iomgr-refactor spec (Task 2.1) ── */
|
||||
void *client_ssl_ctx; /* SSL_CTX* (TLS_client_method); created in myapp_run */
|
||||
int phase2_done; /* 1 after cluster_init_phase2 runs */
|
||||
_Atomic int repl_ack_count; /* count of standbys that ACKed in COMMITTING state */
|
||||
int n_peers; /* total candidate count (excluding self) */
|
||||
} ha_state_t;
|
||||
|
||||
/* ── Public API ────────────────────────────────────────────── */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue