feat: implement push_config_to_standbys() — parallel fan-out via xce_replconfigpush_req_raw() using capn_new_list8 for raw bytes
This commit is contained in:
parent
609314efa4
commit
2e2aaea78c
3 changed files with 190 additions and 26 deletions
|
|
@ -142,6 +142,88 @@ int xce_reply(endpoint_t* ep, xce_peerinfo_t* from, xce_reply_t* reply)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* xce_replconfigpush_req_raw: send OP_replConfigPush with raw byte arrays.
|
||||
*
|
||||
* Bypasses encode_ReplConfigPushRequest_ptr (which maps sha256/bytes through
|
||||
* xce_data_t — a cluster-data discriminated union that cannot carry raw bytes).
|
||||
* Instead, constructs the struct Request / struct ReplConfigPushRequest directly
|
||||
* using the capnp wire-format API (capn_new_list8 + capn_setv8), then calls
|
||||
* write_Request to serialise.
|
||||
*/
|
||||
int xce_replconfigpush_req_raw(endpoint_t *ep, xce_peerinfo_t *from,
|
||||
uint64_t version_tag,
|
||||
const uint8_t *sha256, size_t sha256_len,
|
||||
const uint8_t *config_bytes, size_t config_len)
|
||||
{
|
||||
struct capn c;
|
||||
struct capn_segment *cs;
|
||||
struct Request rq;
|
||||
struct ReplConfigPushRequest push_req;
|
||||
ReplConfigPushRequest_ptr push_ptr;
|
||||
Request_ptr rp;
|
||||
io_packet_t *pkt;
|
||||
int rc;
|
||||
|
||||
if (ep == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
capn_init_malloc(&c);
|
||||
cs = capn_root(&c).seg;
|
||||
|
||||
memset(&rq, 0, sizeof(rq));
|
||||
memset(&push_req, 0, sizeof(push_req));
|
||||
|
||||
push_req.versionTag = version_tag;
|
||||
|
||||
/* sha256: write as a List(UInt8) — capn_list8 and capn_data share {capn_ptr p} */
|
||||
if (sha256 && sha256_len > 0) {
|
||||
capn_list8 sha_list = capn_new_list8(cs, (int)sha256_len);
|
||||
capn_setv8(sha_list, 0, sha256, (int)sha256_len);
|
||||
push_req.sha256.p = sha_list.p;
|
||||
}
|
||||
|
||||
/* config bytes */
|
||||
if (config_bytes && config_len > 0) {
|
||||
capn_list8 bytes_list = capn_new_list8(cs, (int)config_len);
|
||||
capn_setv8(bytes_list, 0, config_bytes, (int)config_len);
|
||||
push_req.bytes.p = bytes_list.p;
|
||||
}
|
||||
|
||||
push_ptr = new_ReplConfigPushRequest(cs);
|
||||
write_ReplConfigPushRequest(&push_req, push_ptr);
|
||||
|
||||
rq.opcode = OPCode_replConfigPush;
|
||||
rq.seq = endpoint_getseq(ep);
|
||||
rq.body_which = Request_body_replconfigpushrequestmsg;
|
||||
rq.body.replconfigpushrequestmsg = push_ptr;
|
||||
encode_PeerInfo_ptr(cs, &rq.from, from);
|
||||
|
||||
rp = new_Request(cs);
|
||||
write_Request(&rq, rp);
|
||||
capn_setp(capn_root(&c), 0, rp.p);
|
||||
|
||||
pkt = (io_packet_t *)calloc(1, sizeof(*pkt));
|
||||
if (!pkt) {
|
||||
capn_free(&c);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
pkt->sz = capn_size(&c);
|
||||
rc = alloc_packet(pkt);
|
||||
if (rc < 0) {
|
||||
free(pkt);
|
||||
capn_free(&c);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
capn_write_mem(&c, (uint8_t *)pkt->data, pkt->sz, 0);
|
||||
capn_free(&c);
|
||||
|
||||
endpoint_enq(ep, &(pkt->link));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int xce_nop_req(endpoint_t* ep)
|
||||
{
|
||||
xce_request_t request
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue