feat(ha-config-bootstrap): implement repl_broadcast eviction and pending_ack_count (task 7.2)

This commit is contained in:
Rongsong Shen 2026-05-28 13:44:11 +00:00
parent f6030749de
commit 3969064e11
4 changed files with 100 additions and 43 deletions

View file

@ -10,6 +10,7 @@
#include "repl.h"
#include "mylock.h"
#include "utils.h"
/* ============================================================
* Lifecycle
@ -177,13 +178,17 @@ void repl_on_ack(replicator_t *r, repl_ep_t ep, uint64_t acked_lsn)
}
/* ============================================================
* Replication send — stub in P2-1; wired in P2-4
* Replication send (task 7.2)
*
* Iterates active standbys; skips empty slots and standbys in catch-up.
* Evicts standbys whose pending_ack_count exceeds MAX_PENDING_ACKS by marking
* them in_catch_up=1 (inlined to avoid re-entrant lock acquisition).
* TCP send wiring deferred to task 7.6.
* ============================================================ */
int repl_broadcast(replicator_t *r, const wal_entry_hdr_t *hdr,
const void *payload, uint32_t payload_len)
{
(void)r;
(void)payload;
(void)payload_len;
@ -191,7 +196,36 @@ int repl_broadcast(replicator_t *r, const wal_entry_hdr_t *hdr,
assert(hdr != NULL);
assert(hdr->type != WAL_CHECKPOINT);
/* Full implementation in P2-4 */
if (r == NULL)
return -EINVAL;
mylock_lock(&r->lock);
for (int i = 0; i < MAX_STANDBYS; i++) {
standby_conn_t *s = &r->standbys[i];
if (s->ep == NULL)
continue;
if (atomic_load_explicit(&s->in_catch_up, memory_order_acquire))
continue;
if (s->pending_ack_count > MAX_PENDING_ACKS) {
/* Inline repl_start_catchup to avoid re-entrant lock acquisition */
s->join_applied_lsn = atomic_load_explicit(&s->acked_lsn,
memory_order_acquire);
atomic_store_explicit(&s->in_catch_up, 1, memory_order_release);
WARN("repl_broadcast: standby %s:%u evicted (pending_ack_count=%u > %u)"
" — triggering catch-up reconnect",
s->host, s->port, s->pending_ack_count, MAX_PENDING_ACKS);
continue;
}
/* Non-evicted standby: track the pending send (TCP wiring in task 7.6) */
s->pending_ack_count++;
}
mylock_unlock(&r->lock);
return 0;
}
@ -258,6 +292,18 @@ int repl_wait_ack(replicator_t *r, uint64_t target_lsn, uint32_t timeout_ms)
return rc;
}
/* ============================================================
* Majority-quorum ACK wait — stub until task 7.3
* ============================================================ */
int repl_wait_majority_ack(replicator_t *r, uint32_t timeout_ms, uint8_t ack_op)
{
(void)r;
(void)timeout_ms;
(void)ack_op;
return -ENOSYS;
}
/* ============================================================
* WAL trim guard
* ============================================================ */