From ad7ea12563be70ee79f97430575ad8b079cd0ccb Mon Sep 17 00:00:00 2001 From: Rongsong Shen Date: Fri, 29 May 2026 13:42:15 +0000 Subject: [PATCH] fix(ha-bootstrap): pre-load config before election so node enters with correct config_tag --- src/controller/myapp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/controller/myapp.c b/src/controller/myapp.c index 837082b5..20370cbf 100644 --- a/src/controller/myapp.c +++ b/src/controller/myapp.c @@ -75,6 +75,21 @@ int myapp_run(myconf_t* myconf) iomgr_start(&(c.iomgr)); vtaskmgr_start(&(c.vtaskmgr)); + /* Pre-load config from disk if a local config file exists, so that this + * node's config_tag is known before election. This allows the freshness gate + * in am_i_primary_quorum() (Req 2.4) to work correctly: a node with a valid + * local config will win over nodes that have no config (tag=0). + * If no config file exists yet, config_version_tag stays 0 and the node will + * defer the config fetch to after election via bootstrap_config_if_needed. */ + { + int pre_rc = load_primary_config(&c); + if (pre_rc == 0) { + INFO("Pre-election config loaded: tag=%016llx", + (unsigned long long)c.myconf->config_version_tag); + } + /* Ignore errors — node may have no config yet (first boot or standby) */ + } + /* Req 3.1–3.4: probe peers for config tags before election so that a node * joining an existing cluster knows to defer its config fetch to post-election * rather than participating as a first-boot candidate with no config. */