fix(ha-term): move ha-term.bin to {workdir}/{name}/data/ alongside WAL/snapshot

This commit is contained in:
Rongsong Shen 2026-05-31 11:04:35 +00:00
parent 04b31afb06
commit 0f766776ba
2 changed files with 13 additions and 6 deletions

View file

@ -476,7 +476,12 @@ static int raft_cb_persist(void *ctx, uint64_t term, int voted_for)
{
ha_state_t *ha = (ha_state_t *)ctx;
cluster_t *c = ha->raft_c;
const char *workdir = (c && c->myconf) ? c->myconf->workdir : NULL;
/* Store ha-term.bin under {workdir}/{myname}/data/ alongside WAL/snapshot. */
char data_dir[1024] = {0};
if (c && c->myconf && c->myconf->workdir && c->myconf->name)
snprintf(data_dir, sizeof(data_dir), "%s/%s/data",
c->myconf->workdir, c->myconf->name);
const char *workdir = data_dir[0] ? data_dir : NULL;
/* Update ha->term */
atomic_store_explicit(&ha->term, term, memory_order_release);