forked from lei.chen/myxce
feat: wire persist_init/recover/start/stop into cluster lifecycle (P0-F)
- Add `persist_t persist` field to cluster_t (cluster_def.h includes persist.h) - Add `workdir` and `name` fields to myconf_t; main.c passes them through - cluster_init: call persist_set_workdir, persist_init, persist_recover after apiserver_init - cluster_start: call persist_start (launches fsync thread + registers WAL hooks) - cluster_fini: call persist_stop + persist_fini before delaymgr/vtaskmgr teardown - persist_init: store cluster back-pointer (replaces (void)c stub) - persist_start: register persist_job/queue/worker_hook_fun via xce_add_hook when cluster != NULL - Add test_cluster_persist.c: compile-time struct check + config defaults + workdir path derivation - Register test in controller_test.c and meson.build All controller tests pass (1/1 OK, 50s).
This commit is contained in:
parent
3030012f51
commit
b52fbef36d
9 changed files with 159 additions and 2 deletions
|
|
@ -610,6 +610,28 @@ int cluster_init(cluster_t* c)
|
|||
|
||||
apiserver_init(c);
|
||||
|
||||
/* Persistence: derive paths, init, and recover from WAL/snapshot */
|
||||
{
|
||||
const char* workdir = c->myconf->workdir ? c->myconf->workdir
|
||||
: DEFAULT_WORKDIR;
|
||||
const char* name = c->myconf->name ? c->myconf->name
|
||||
: "controller";
|
||||
persist_config_t pcfg = persist_config_defaults();
|
||||
|
||||
persist_set_workdir(&c->persist, workdir, name);
|
||||
rc = persist_init(&c->persist, &pcfg, c);
|
||||
if (rc != 0) {
|
||||
ERROR("persist_init failed: %d", rc);
|
||||
return rc;
|
||||
}
|
||||
rc = persist_recover(&c->persist);
|
||||
if (rc != 0) {
|
||||
ERROR("persist_recover failed: %d", rc);
|
||||
persist_fini(&c->persist);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_CLUSTER, HOOK_AFTER_EVENT,
|
||||
HOOK_DETAIL_CLUSTER_INIT, c);
|
||||
|
||||
|
|
@ -758,6 +780,13 @@ int cluster_start(cluster_t* c)
|
|||
vtaskmgr_start(&(c->vtaskmgr));
|
||||
delaymgr_start(&(c->delaymgr));
|
||||
|
||||
/* Start persistence fsync thread and register WAL hooks */
|
||||
rc = persist_start(&c->persist);
|
||||
if (rc != 0) {
|
||||
ERROR("persist_start failed: %d", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
delay_task(&(c->delaymgr), c->myconf->cluster_config->heartbeat_interval,
|
||||
-1, (delay_task_entry_fn_t)check_workers_timeout, (void*)c);
|
||||
|
||||
|
|
@ -790,6 +819,10 @@ int cluster_run(cluster_t* c)
|
|||
|
||||
void cluster_fini(cluster_t* c)
|
||||
{
|
||||
/* Stop persistence before tearing down the rest */
|
||||
persist_stop(&c->persist);
|
||||
persist_fini(&c->persist);
|
||||
|
||||
delaymgr_fini(&(c->delaymgr));
|
||||
vtaskmgr_fini(&(c->vtaskmgr));
|
||||
endpoint_fini(&(c->ep));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue