forked from lei.chen/myxce
feat(ha-term-safety): on_commit_advanced barrier trigger + commit-gate ownership (task 2.4)
This commit is contained in:
parent
2c5d298cb5
commit
3470bdfb71
6 changed files with 363 additions and 9 deletions
|
|
@ -1334,10 +1334,10 @@ static void raft_cb_trace(void *ctx, const char *event, const char *detail)
|
|||
* they perform NO persistence, NO replication, and NO truncation. See CONCERNS.
|
||||
*
|
||||
* on_persist_entry → task 2.1 (durable WAL append/overwrite) — IMPLEMENTED
|
||||
* on_get_entry_term → task 2.2 (WAL entry-term lookup; persist_entry_term, 1.3)
|
||||
* on_send_append_entries→ task 2.3 (AppendEntries transmit)
|
||||
* on_truncate_from → task 2.4 (conflict truncation)
|
||||
* on_commit_advanced → task 2.5 (commit-barrier trigger)
|
||||
* on_get_entry_term → task 2.2 (WAL entry-term lookup; persist_entry_term, 1.3) — IMPLEMENTED
|
||||
* on_send_append_entries→ task 2.3 (AppendEntries transmit) — IMPLEMENTED
|
||||
* on_truncate_from → task 2.2 (conflict truncation) — IMPLEMENTED
|
||||
* on_commit_advanced → task 2.4 (commit-barrier trigger / commit source) — IMPLEMENTED
|
||||
*
|
||||
* on_get_entry_term returns 0 (== "absent") for now: with the log-replication
|
||||
* path unwired, the library's local last-log term reads as 0, so the logOk gate
|
||||
|
|
@ -1612,10 +1612,30 @@ static int ha_cb_truncate_from_stub(void *ctx, uint64_t index)
|
|||
return persist_truncate_wal_above(&ha->raft_c->persist, index - 1);
|
||||
}
|
||||
|
||||
/* on_commit_advanced (ha-term-safety task 2.4, R4.1/R4.5/R5.4): feed the raft
|
||||
* library's current-term-gated `commit_index` into the existing synchronous
|
||||
* commit barrier as the commit SOURCE. The library fired this ONLY on a strict
|
||||
* advance of its Figure-8 current-term commit index (raft.c), so the barrier
|
||||
* now advances committed_lsn only when BOTH a durable majority agrees AND the
|
||||
* library has admitted the entry — the term-blind safe-commit
|
||||
* (ha_compute_safe_committed_lsn) is no longer the steady-state commit source.
|
||||
*
|
||||
* This callback only TRIGGERS the barrier (records the ceiling + re-evaluates);
|
||||
* it performs NO durability itself. The barrier mechanism — majority self-cap at
|
||||
* the durable floor, persist-before-ACK, monotonic committed_lsn — is unchanged
|
||||
* (ha-commit-durability). The own-term writable_lsn gate is RETAINED as a
|
||||
* complementary WAIT-completion predicate (it never caps committed_lsn, so it
|
||||
* cannot deadlock against this source; see ha_arm_own_term_gate).
|
||||
*
|
||||
* Non-blocking (ha-async-io): commit_set_raft_commit_index takes only ce->lock
|
||||
* and never performs I/O — safe on the iomgr ACK path that drove
|
||||
* raft_advance_commit. */
|
||||
static void ha_cb_commit_advanced_stub(void *ctx, uint64_t commit_index)
|
||||
{
|
||||
(void)ctx; (void)commit_index;
|
||||
/* TODO task 2.5: trigger the existing synchronous commit barrier. */
|
||||
ha_state_t *ha = (ha_state_t *)ctx;
|
||||
if (!ha || !ha->raft_c)
|
||||
return; /* test mode without a cluster: no barrier to trigger */
|
||||
commit_set_raft_commit_index(&ha->raft_c->commit, commit_index);
|
||||
}
|
||||
|
||||
static const raft_callbacks_t s_real_cbs = {
|
||||
|
|
@ -1838,6 +1858,14 @@ int ha_cb_send_append_entries_for_test(ha_state_t *ha, int peer_idx,
|
|||
prev_log_term, leader_commit,
|
||||
n_entries);
|
||||
}
|
||||
|
||||
/* ha-term-safety task 2.4: drive the WIRED on_commit_advanced callback so a unit
|
||||
* test exercises the real commit-source trigger (feed the library commit_index
|
||||
* into the cluster's commit barrier). Exposed only under XCE_TESTING. */
|
||||
void ha_cb_commit_advanced_for_test(ha_state_t *ha, uint64_t commit_index)
|
||||
{
|
||||
s_real_cbs.on_commit_advanced(ha, commit_index);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ha_check_heartbeat_nocluster() / ha_watchdog_thread() / ha_start_watchdog() /
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue