forked from lei.chen/myxce
feat(ha-config-bootstrap): wire repl_wait_majority_ack into persist_wal_sync_append (task 7.6)
This commit is contained in:
parent
85c8565957
commit
684d3b6608
2 changed files with 21 additions and 8 deletions
|
|
@ -1005,21 +1005,34 @@ int persist_wal_sync_append(persist_t* p, uint32_t type,
|
|||
return rc;
|
||||
}
|
||||
|
||||
/* For sync replication (WAL_JOB_SUBMIT): wait for at least one standby ACK.
|
||||
/* Majority-commit replication (Req 5.1–5.3).
|
||||
* After local fsync via persist_wal_async, wait for majority quorum ACK.
|
||||
* On quorum: advance committed_lsn. On no standbys or timeout: degraded.
|
||||
* We use current_lsn - 1 because persist_wal_async already incremented it. */
|
||||
uint64_t written_lsn;
|
||||
pthread_mutex_lock(&p->lock);
|
||||
written_lsn = p->current_lsn - 1;
|
||||
pthread_mutex_unlock(&p->lock);
|
||||
|
||||
int sync_err = repl_wait_ack(&p->repl, written_lsn,
|
||||
p->config.sync_timeout_ms);
|
||||
if (sync_err < 0)
|
||||
CTRL_METRIC_INC(ctrl_repl_degraded_count);
|
||||
/* No standbys registered → degraded mode immediately (no quorum to wait for) */
|
||||
mylock_lock(&p->repl.lock);
|
||||
int has_standbys = (p->repl.nstandbys > 0);
|
||||
mylock_unlock(&p->repl.lock);
|
||||
|
||||
int sync_err;
|
||||
if (!has_standbys) {
|
||||
sync_err = -ENODEV;
|
||||
} else {
|
||||
sync_err = repl_wait_majority_ack(&p->repl, p->config.sync_timeout_ms,
|
||||
(uint8_t)OPCode_walAck);
|
||||
if (sync_err == 0)
|
||||
atomic_store_explicit(&p->committed_lsn, written_lsn, memory_order_release);
|
||||
else
|
||||
CTRL_METRIC_INC(ctrl_repl_degraded_count);
|
||||
}
|
||||
if (sync_rc_out)
|
||||
*sync_rc_out = sync_err;
|
||||
/* -ETIMEDOUT = degraded mode (local-only durability); -ENODEV = no standbys.
|
||||
* Both are acceptable — primary continues operating. */
|
||||
/* sync_err < 0 = degraded mode (local-only durability); continue operating. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue