feat(raft-apply-decoupling): resolve pending continuations on demotion/truncation (task 1.4)

commit_resolve_pending_above(ce, lsn_floor, rc) fails every registered
continuation for lsn > lsn_floor, reusing commit_resolve()'s existing
exactly-once/idempotent guarantee (no parallel bookkeeping path).

Truncation: a new on_truncate/truncate_cb_ctx callback on persist_t
(same inversion-of-control shape as the existing on_durable_advance
hook) fires from persist_truncate_wal_above after releasing p->lock,
only when entries were actually removed. This one wrapper covers all
three real truncation call sites: raft_cb_become_leader's
post-election truncate, the library's on_truncate_from
conflict-reconcile, and ha_demotion_convergence_fn's post-demotion
truncate.

Demotion: raft_cb_become_follower calls
commit_resolve_pending_above(&c->commit, 0, -XCE_ERR_STANDBY) --
lsn_floor=0 fails everything, since a demoted node can never
authoritatively confirm anything still pending (CP posture).

Without this, a demoted or truncated node would leave any pending
async command permanently unresolved -- the requester would simply
never get a reply, worse than today's bounded-timeout behavior.

Also closes bug-1407 (pre-existing test_config_repl flake, unrelated
to this feature) -- confirmed fixed as a side effect of prior tasks
in this series, 70/70 passing across 3 independent runs.
This commit is contained in:
Rongsong Shen 2026-07-03 11:58:10 +00:00
parent 530a02bda3
commit 9b4b805a27
9 changed files with 748 additions and 301 deletions

View file

@ -1378,6 +1378,21 @@ static void raft_cb_become_follower(void *ctx, uint64_t term, int leader_idx)
(hook_fn_t)persist_worker_hook_fun);
ha->hooks_registered = 0;
}
/* raft-apply-decoupling task 1.4 (Req 1.3, 1.4, 9.3, 9.4): a demoted
* PRIMARY can never advance committed_lsn again for anything it had
* pending -- resolve every currently registered commit continuation
* as FAILED now, synchronously with the rest of this "stop being
* primary" sequence, rather than leaving a requester parked until
* the commit engine's own timeout-sweep thread (task 1.3) eventually
* times it out. lsn_floor=0 resolves ALL pending continuations (lsn
* 0 is never a real registration -- the free-slot sentinel). Uses
* the same -XCE_ERR_STANDBY vocabulary the HA dispatch gate already
* uses to reject writes to a non-primary. Reachable only when this
* node was already PRIMARY, which means cluster_init_phase2 (and
* therefore commit_engine_init) already ran, so c->commit is always
* initialized here. */
commit_resolve_pending_above(&c->commit, 0, -XCE_ERR_STANDBY);
}
atomic_store_explicit(&ha->role, (int32_t)CTRL_STANDBY,