forked from lei.chen/myxce
feat(ha-heartbeat-liveness): add validate_heartbeat_config startup check (task 1.2)
Enforce heartbeat_timeout_ms >= 2 * heartbeat_interval_ms at startup. validate_heartbeat_config() in startup_validation.c returns -EINVAL with error message on violation; wired in cluster_init_phase1 before ha_init(). 4 unit tests added to test_ha_startup.c.
This commit is contained in:
parent
bcb45e59d2
commit
9f9a6b3c0f
4 changed files with 129 additions and 4 deletions
|
|
@ -28,6 +28,11 @@
|
|||
#include "xstring.h"
|
||||
#include "helper.h"
|
||||
|
||||
/* startup_validation.c — forward declaration */
|
||||
int validate_heartbeat_config(uint32_t heartbeat_timeout_ms,
|
||||
uint32_t heartbeat_interval_ms,
|
||||
char *err_buf, size_t err_len);
|
||||
|
||||
static xce_peerinfo_t from_controller
|
||||
= { .name = "controller", .key = "keepSecret" };
|
||||
|
||||
|
|
@ -217,6 +222,9 @@ static int myreq_handler(vtask_t* task)
|
|||
reply.status = 0;
|
||||
reply.data_which = RequestReply_data_nodata;
|
||||
xce_reply(ep, c->myhost, &reply);
|
||||
/* Reset heartbeat watchdog when nop arrives on the primary channel */
|
||||
if (ep->fd == c->ha.primary_ctrl_fd)
|
||||
ha_on_heartbeat_received(&c->ha);
|
||||
break;
|
||||
case OPCode_join:
|
||||
rc = handle_join(c, ep, &request);
|
||||
|
|
@ -798,6 +806,18 @@ int cluster_init_phase1(cluster_t* c)
|
|||
pcfg->candidates_count, my_priority, c->myconf->name);
|
||||
}
|
||||
|
||||
/* Req 2.4: reject misconfigured heartbeat timing before ha_init() */
|
||||
{
|
||||
char hb_err[256];
|
||||
if (validate_heartbeat_config(ha_cfg.heartbeat_timeout_ms,
|
||||
ha_cfg.heartbeat_interval_ms,
|
||||
hb_err, sizeof(hb_err)) != 0) {
|
||||
ERROR("startup validation failed: %s", hb_err);
|
||||
fprintf(stderr, "xce_controller: %s\n", hb_err);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
rc = ha_init(&c->ha, &ha_cfg, my_priority);
|
||||
if (rc != 0) {
|
||||
ERROR("ha_init failed: %d", rc);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue