forked from lei.chen/myxce
feat(ha-commit-engine): engine instantiation + sync-append path switch (task 5.3)
cluster_t embeds commit_engine_t; init in cluster_init_phase2 after the vtaskmgr guard (idempotence-guarded — phase2 can run twice), wiring repl_set_commit_engine + ha.repl back-pointer before any standby can register; fini after iomgr/vtask shutdown. persist_wal_sync_append passes written_lsn; engine-wired path drops -ENODEV and the committed_lsn store (engine owns advancement); LSN-0 first-entry routes to legacy per the accepted interim. p2 -ENODEV pin updated to the Req 6.3 contract. 34/34 + 6/6 green through honest delegation; census exactly at the 3 validated baselines; production binary links.
This commit is contained in:
parent
6600fd5d1f
commit
f0d6074d4e
6 changed files with 142 additions and 50 deletions
|
|
@ -1116,6 +1116,37 @@ int cluster_init_phase2(cluster_t* c)
|
|||
}
|
||||
}
|
||||
|
||||
/* ── Commit engine instantiation (ha-commit-engine task 5.3) ──────────
|
||||
* Both inputs are final exactly here: n_vcpus was resolved by the
|
||||
* vtaskmgr_init guard above (or by myapp_run before election) and
|
||||
* ha->n_peers was fixed by ha_init_raft before the election that
|
||||
* triggered this phase2. Legacy cluster_init() path (tests /
|
||||
* single-node): ha->n_peers is still 0 → standalone self-quorum
|
||||
* semantics, matching the old degraded single-node contract.
|
||||
*
|
||||
* Wire the engine BEFORE the promotion below: standbys register for
|
||||
* replication only after the post-promotion ctrlhello, so r->ce is set
|
||||
* once before any replication traffic (repl.h set-once contract).
|
||||
*
|
||||
* Guard c->commit.p: phase2 can run twice on the legacy wrapper path
|
||||
* (cluster_init() directly, then the first-boot election callback);
|
||||
* the engine must be initialized exactly once. */
|
||||
if (c->commit.p == NULL) {
|
||||
rc = commit_engine_init(&c->commit, &c->persist, c->ha.n_peers,
|
||||
c->vtaskmgr.n_vcpus);
|
||||
if (rc != 0) {
|
||||
ERROR("commit_engine_init failed: %d (n_peers=%d, n_vcpus=%d)",
|
||||
rc, c->ha.n_peers, c->vtaskmgr.n_vcpus);
|
||||
return rc;
|
||||
}
|
||||
repl_set_commit_engine(&c->persist.repl, &c->commit);
|
||||
/* Write-admission gate reads registry truth through this
|
||||
* back-pointer (ha-commit-engine task 4.2 / Req 3.1-3.3). */
|
||||
c->ha.repl = &c->persist.repl;
|
||||
INFO("commit engine wired (n_peers=%d, n_vcpus=%d)",
|
||||
c->ha.n_peers, c->vtaskmgr.n_vcpus);
|
||||
}
|
||||
|
||||
/* Role set by ha_elect_evaluate_and_signal() inside cluster_run() */
|
||||
if (ha_is_primary(&c->ha))
|
||||
ha_promote_to_primary(c);
|
||||
|
|
@ -1477,6 +1508,15 @@ void cluster_fini(cluster_t* c)
|
|||
iomgr_stop(&(c->iomgr)); /* join worker thread before freeing SSL_CTX */
|
||||
iomgr_fini(&(c->iomgr));
|
||||
|
||||
/* Commit engine teardown (ha-commit-engine task 5.3): destroy only after
|
||||
* ALL replication traffic has stopped — vtaskmgr_fini joined the
|
||||
* job-submit vtasks (commit_submit callers) and iomgr_stop/iomgr_fini
|
||||
* joined the I/O thread (commit_on_ack source). r->ce is never NULLed
|
||||
* while traffic lives (repl.h set-once contract); guard makes this safe
|
||||
* when phase2 never ran (early init failure). */
|
||||
if (c->commit.p != NULL)
|
||||
commit_engine_fini(&c->commit);
|
||||
|
||||
destroy(c->jobmgr);
|
||||
destroy(c->workermgr);
|
||||
destroy(c->qmgr);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue