feat: implement create_lost_and_found() — synthetic queue+host via makeQueue/makeWorker (gated for unit tests)

This commit is contained in:
Rongsong Shen 2026-05-14 03:13:14 +00:00
parent e4c1bfb17f
commit 91e66b8b07

View file

@ -20,8 +20,10 @@
#include "byteorder.h" #include "byteorder.h"
#include "clusterconfig.h" #include "clusterconfig.h"
#include "cluster.h"
#include "ha.h" #include "ha.h"
#include "utils.h" #include "utils.h"
#include "wobj.h"
#include "xce/cluster_def.h" #include "xce/cluster_def.h"
/* ── config load helpers (shared with myconf.c logic) ─────── */ /* ── config load helpers (shared with myconf.c logic) ─────── */
@ -536,21 +538,46 @@ int load_primary_config_for_test(cluster_t *c)
void create_lost_and_found(cluster_t *c) void create_lost_and_found(cluster_t *c)
{ {
/* if (!c->qmgr || !c->workermgr)
* Ensure the synthetic "lost_and_found" queue exists before return;
* persist_recover() runs. Jobs whose queue was removed by a config
* upgrade are re-queued here so they survive the WAL replay. #ifndef XCE_TESTING
* /* key_find, create_queue, and makeWorker require librtti + queue.c which
* Phase 2 concern: the full kvmgr queue-insertion API requires a * are not linked into the unit test binary. The !qmgr guard above means
* complete config context that is not yet available at the point this * this block is unreachable in tests regardless. */
* function is called (pre-recovery). Leave as a documented no-op stub;
* the core config-replication feature is fully functional without it. /* Synthetic queue — receives jobs whose queue was removed by a config
* Track lost-and-found job count via c->lost_and_found_job_count. * upgrade. Created before persist_recover() so WAL replay can route
*/ * unknown queue IDs here instead of failing. */
(void)c; {
WARN("create_lost_and_found: synthetic queue insertion deferred to Phase 2" void *existing = NULL;
" -- lost-and-found jobs will not be preserved across config upgrades" if (key_find(c->qmgr, (void *)"lost_and_found", &existing) <= 0) {
" until that phase is complete"); xce_queue_t lf = {0};
lf.queue = "lost_and_found";
queue_t *q = create_queue(c, &lf);
if (q)
INFO("Created synthetic 'lost_and_found' queue");
else
ERROR("Failed to create synthetic 'lost_and_found' queue");
}
}
/* Synthetic host — receives jobs whose host was removed by a config
* upgrade. Uses makeWorker directly; no hostconfig entry is required
* for this sentinel host. */
{
void *existing = NULL;
if (key_find(c->workermgr, (void *)"lost_and_found", &existing) <= 0) {
xce_worker_t lf_host = {0};
lf_host.name = "lost_and_found";
worker_t *w = makeWorker(c->workermgr, &lf_host);
if (w)
INFO("Created synthetic 'lost_and_found' host");
else
ERROR("Failed to create synthetic 'lost_and_found' host");
}
}
#endif /* XCE_TESTING */
} }
/* ── handle_config_request ──────────────────────── */ /* ── handle_config_request ──────────────────────── */