feat(libxce-failover): controller populates primary host/port on E_XCE_REDIRECT replies (task 5.3)

This commit is contained in:
Rongsong Shen 2026-06-17 04:16:26 +00:00
parent fdb8938059
commit 5d1d1e3f12
5 changed files with 124 additions and 1 deletions

View file

@ -16,6 +16,21 @@ static int validate_host(cluster_t* c, const char* host, const char* key)
return 1;
}
/*
* fill_redirect_reply: populate an E_XCE_REDIRECT reply with the primary's
* host and port from ha state so the libxce client can use it as a one-hop
* hint (libxce-failover Req 8.1). The redirect_host pointer aliases the
* ha_state_t.primary_host buffer (capnp serialises it when non-NULL — see
* request.c); the caller must keep *ha live until xce_reply() runs, which it
* does (ha is embedded in cluster_t). Pure aside from the field writes — no
* locking, no allocation.
*/
void fill_redirect_reply(xce_reply_t* reply, const ha_state_t* ha)
{
reply->redirect_host = (char*)ha->primary_host;
reply->redirect_port = (uint16_t)ha->primary_port;
}
static int handle_client_join(cluster_t* c, endpoint_t* ep,
xce_request_t* request)
{
@ -264,6 +279,7 @@ static int handle_join_(cluster_t* c, endpoint_t* ep, xce_request_t* request)
rc = -E_XCE_REDIRECT;
reply.status = rc;
reply.data_which = RequestReply_data_nodata;
fill_redirect_reply(&reply, &c->ha);
xce_reply(ep, c->myhost, &reply);
return rc;
}