forked from lei.chen/myxce
fix(election-iomgr-refactor): Raft election, config decode, and RDHUP chain
- ha.c: self-vote in ha_start_election_async (Raft invariant) - ha.c: heartbeat_timeout_ms for hb_timeout_thread (not election_timeout_ms) - ha.c: clear voted_for before RDHUP jitter (stale vote from dead primary) - ha.c: same-term voted_for check in RDHUP jitter - config_repl.c/h: use xce_decode for upgradeConfig (capnp extraction before capn_free) - cluster.c: fix upgradeConfig handler direction (standbys apply, primaries skip) - cluster.c: remove raw_pkt_copy hack; use req directly - join.c: push config to newly-joined standbys - typemap.h/request.h/request.c: raw_sha256/raw_bytes fields for decoded upgradeConfig - test_ha_failover.c: update heartbeat timeout test to use g_fast_cfg
This commit is contained in:
parent
1ded1022fb
commit
dbb750ebd3
8 changed files with 198 additions and 102 deletions
|
|
@ -159,36 +159,9 @@ static int myreq_handler(vtask_t* task)
|
|||
xce_request_t request;
|
||||
xce_reply_t reply;
|
||||
|
||||
/* Capture raw packet bytes for OPCode_upgradeConfig before xce_decode()
|
||||
* frees the capnp segment. xce_upgrade_config_req_extract_raw() needs
|
||||
* the raw buffer to extract sha256+bytes via a fresh capn_init_mem context.
|
||||
* Read opcode BEFORE capn_free to avoid accessing freed memory. */
|
||||
uint8_t *raw_pkt_copy = NULL;
|
||||
size_t raw_pkt_sz = 0;
|
||||
{
|
||||
io_packet_t *pkt = data->u.iodata.pkt;
|
||||
if (pkt && pkt->data && pkt->sz > 0) {
|
||||
struct capn peek_c;
|
||||
struct Request peek_rq;
|
||||
Request_ptr peek_rp;
|
||||
capn_init_mem(&peek_c, (const uint8_t *)pkt->data, (size_t)pkt->sz, 0);
|
||||
peek_rp.p = capn_getp(capn_root(&peek_c), 0, 1);
|
||||
read_Request(&peek_rq, peek_rp);
|
||||
/* Read opcode (scalar) before capn_free — pointer fields in peek_rq
|
||||
* become invalid after free, but opcode is a uint32_t field. */
|
||||
int peek_opcode = (int)peek_rq.opcode;
|
||||
capn_free(&peek_c);
|
||||
|
||||
if (peek_opcode == OPCode_upgradeConfig) {
|
||||
raw_pkt_copy = (uint8_t *)malloc((size_t)pkt->sz);
|
||||
if (raw_pkt_copy) {
|
||||
memcpy(raw_pkt_copy, pkt->data, (size_t)pkt->sz);
|
||||
raw_pkt_sz = (size_t)pkt->sz;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* xce_decode() extracts sha256+bytes for OPCode_upgradeConfig into
|
||||
* request.body.upgradeconfigrequestmsg->raw_sha256/raw_bytes before
|
||||
* capn_free(), so no pre-decode raw-packet copy is needed. */
|
||||
rc = xce_decode(data->u.iodata.pkt, &request);
|
||||
|
||||
TRACE("%s cpu#%d opcode %s", __func__, task->vcpu,
|
||||
|
|
@ -202,8 +175,7 @@ static int myreq_handler(vtask_t* task)
|
|||
reply.status = rc;
|
||||
reply.data_which = RequestReply_data_nodata;
|
||||
xce_reply(ep, c->myhost, &reply);
|
||||
free_Request(&request);
|
||||
free(raw_pkt_copy);
|
||||
xce_free_request(&request);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
@ -330,7 +302,7 @@ static int myreq_handler(vtask_t* task)
|
|||
rc = -EAGAIN;
|
||||
break;
|
||||
}
|
||||
rc = handle_upgrade_config(c, ep, &request, raw_pkt_copy, raw_pkt_sz);
|
||||
rc = handle_upgrade_config(c, ep, &request);
|
||||
break;
|
||||
#else
|
||||
{
|
||||
|
|
@ -353,8 +325,7 @@ static int myreq_handler(vtask_t* task)
|
|||
break;
|
||||
}
|
||||
|
||||
free_Request(&request);
|
||||
free(raw_pkt_copy); /* NULL-safe: free(NULL) is a no-op */
|
||||
xce_free_request(&request);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue