feat(ha-config-bootstrap): implement committed_config_tag and config quorum commit (task 8.1)

This commit is contained in:
Rongsong Shen 2026-05-28 14:52:29 +00:00
parent 684d3b6608
commit c0cfc1cf83
3 changed files with 20 additions and 3 deletions

View file

@ -27,7 +27,9 @@
#include "byteorder.h"
#include "clusterconfig.h"
#include "cluster.h"
#include "controller.capnp.h" /* OPCode_upgradeConfigAck */
#include "ha.h"
#include "repl.h" /* repl_wait_majority_ack, repl_on_config_ack */
#include "request.h"
#include "utils.h"
#include "wobj.h"
@ -1119,10 +1121,24 @@ int push_config_to_standbys(cluster_t *c, const uint8_t *bytes, size_t blen,
int acked = wait_all_with_timeout(threads, ctxs, n,
CONF_PUSH_TIMEOUT_MS, &push_done);
INFO("Config pushed to %d/%d standbys", acked, n);
free(ctxs);
free(threads);
/* Req 8.1–8.3: wait for majority-quorum OP_upgradeConfigAck.
* On quorum: advance committed_config_tag atomically (Req 8.5). */
int rc = repl_wait_majority_ack(&c->persist.repl, CONF_PUSH_TIMEOUT_MS,
(uint8_t)OPCode_upgradeConfigAck);
if (rc == 0) {
atomic_store_explicit(&c->ha.committed_config_tag, new_tag,
memory_order_release);
INFO("Config committed on majority (tag=%016" PRIx64
", pushed=%d/%d standbys)", new_tag, acked, n);
} else {
WARN("Config push: timeout waiting for majority ACK"
" (tag=%016" PRIx64 ", pushed=%d/%d standbys)",
new_tag, acked, n);
}
return acked;
}

View file

@ -156,6 +156,7 @@ typedef struct {
_Atomic uint64_t last_known_committed_lsn; /* Req 5: from primary heartbeats */
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 */
} ha_state_t;
/* ── Public API ────────────────────────────────────────────── */