feat(ha-term-safety): drive raft_log_append on primary append path (task 3.1)

This commit is contained in:
Rongsong Shen 2026-06-22 08:09:47 +00:00
parent 3dd8493fff
commit 6a519a928b
5 changed files with 299 additions and 11 deletions

View file

@ -317,6 +317,22 @@ char **controller_saved_argv(void);
*/
int ha_self_restart(cluster_t *c);
/*
* ha_primary_log_append (ha-term-safety task 3.1, R1.1/R1.2/R2.1): the single
* primary append entry point. Routes a local primary append (job-state entry or
* the own-term promotion no-op) through the raft library (raft_log_append) so
* the library stamps the live election term and assigns the LSN, firing
* on_persist_entry for the actual WAL write — making the library the sole
* LSN/term source and keeping p->current_lsn co-tracked with s->log_len. When
* the raft library is not RAFT_LEADER (the non-raft promotion road / engine-less
* tests), falls back to a legacy local persist_wal_async append (the library is
* not tracking the log, so no co-tracking hazard). `type` is a wal_entry_type;
* `payload`/`len` may be NULL/0 (e.g. WAL_NOOP). out_lsn (optional) receives the
* assigned 1-based LSN. Returns 0 on success; propagates a non-zero persist rc.
*/
int ha_primary_log_append(cluster_t *c, uint32_t type,
const void *payload, uint32_t len, uint64_t *out_lsn);
/*
* ha_schedule_demotion_convergence: schedule the one-shot delaymgr task that
* truncates above committed_lsn (Req 1.2), WARN-logs the discarded range
@ -812,6 +828,14 @@ int ha_cb_send_append_entries_for_test(ha_state_t *ha, int peer_idx,
* source. TEST-ONLY.
*/
void ha_cb_commit_advanced_for_test(ha_state_t *ha, uint64_t commit_index);
/*
* ha_arm_own_term_gate_for_test (ha-term-safety task 3.1): drive the static
* own-term gate arm (the promotion WAL_NOOP, now routed through
* ha_primary_log_append) so a unit test can assert the no-op records the live
* term via the library. TEST-ONLY.
*/
void ha_arm_own_term_gate_for_test(cluster_t *c);
#endif
/*