save works

This commit is contained in:
Rongsong Shen 2026-03-04 18:18:53 +08:00
parent acfbec875b
commit 3f74f14687
38 changed files with 751 additions and 448 deletions

View file

@ -101,7 +101,10 @@ static int update_resval(cluster_t* c, worker_t* w, xce_resval_t* val)
xce_val_t* v = NULL;
int rc;
lock(c->resmgr, RTTI_LOCK_READ);
rc = key_find(c->resmgr, (void*)val->name, (void**)&r);
unlock(c->resmgr);
if (rc < 0) {
return rc;
}
@ -161,7 +164,10 @@ static int mark_host_res(cluster_t* c, worker_t* w, xce_config_t* config)
xce_val_t val;
/* clang-format-on */
lock(c->resmgr, RTTI_LOCK_READ);
rc = key_find(c->resmgr, (void*)n, (void**)&r);
unlock(c->resmgr);
if (rc < 0) {
return rc;
}
@ -298,6 +304,9 @@ int add_worker(void* cls, endpoint_t* ep, const char* host, hostattrs_t* attrs)
/* we should hold the update lock */
/* If admin makes the host in locked or closed, we need keep this */
lock(w, RTTI_LOCK_WRITE);
w->host.status &= ~XCE_WORKER_UNAVAIL; /* status OK */
w->ep = ep;
@ -350,6 +359,8 @@ int add_worker(void* cls, endpoint_t* ep, const char* host, hostattrs_t* attrs)
mark_host_res(c, w, hconfig->resources[i]);
}
unlock(w);
return idx;
}
@ -367,10 +378,15 @@ int restore_worker(void* cls, xce_worker_t host)
if (w == NULL) {
return -errno;
}
lock(w, RTTI_LOCK_WRITE);
add_hostattrs_resvals(c, w);
idx = w->idx;
w->host.status |= XCE_WORKER_UNAVAIL;
unlock(w);
return idx;
}
@ -440,7 +456,10 @@ int get_resval(cluster_t* c, char* resname, char* host, xce_val_t* val)
worker_t* w = NULL;
int rc = 0;
lock(c->resmgr, RTTI_LOCK_READ);
rc = key_find(c->resmgr, (void*)resname, (void**)&r);
unlock(c->resmgr);
if (rc < 0) {
return rc;
}
@ -455,7 +474,12 @@ int get_resval(cluster_t* c, char* resname, char* host, xce_val_t* val)
return -EINVAL;
}
lock(c->workermgr, RTTI_LOCK_READ);
rc = key_find(c->workermgr, (void*)host, (void**)&w);
if (w != NULL) {
reference(w);
}
unlock(c->workermgr);
if (rc < 0) {
return rc;
}
@ -473,10 +497,19 @@ int get_resval(cluster_t* c, char* resname, char* host, xce_val_t* val)
}
if (v == NULL) {
if (w != NULL) {
dereference(w);
}
return -ENOENT;
}
memcpy(val, v, sizeof(*val));
if (w != NULL) {
dereference(w);
}
return 1;
}
@ -484,6 +517,7 @@ int mark_worker_unavail(cluster_t* c, worker_t* w)
{
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_BEFORE_EVENT,
HOOK_DETAIL_WORKER_DEAD, c, w);
w->host.status |= XCE_WORKER_UNAVAIL;
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_AFTER_EVENT,
@ -495,6 +529,7 @@ int mark_worker_back(cluster_t* c, worker_t* w)
{
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_BEFORE_EVENT,
HOOK_DETAIL_WORKER_UPDATE, c, w);
w->host.status &= ~XCE_WORKER_UNAVAIL;
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_AFTER_EVENT,
@ -530,10 +565,14 @@ int handle_worker_leave(cluster_t* c, int idx)
return -errno;
}
lock(w, RTTI_LOCK_WRITE);
w->ep = NULL;
mark_worker_unavail(c, w);
unlock(w);
return 0;
}
@ -548,7 +587,13 @@ int worker_ctrl(cluster_t* c, xce_hostctrl_t* ctrl)
}
TRACE("%s worker_ctrl worker %s", __func__, ctrl->hostname);
lock(c->workermgr, RTTI_LOCK_READ);
rc = key_find(c->workermgr, (void*)ctrl->hostname, (void**)&w);
if (w != NULL) {
reference(w);
}
unlock(c->workermgr);
if (rc < 0) {
return rc;
}
@ -558,6 +603,7 @@ int worker_ctrl(cluster_t* c, xce_hostctrl_t* ctrl)
return -ENOENT;
}
lock(w, RTTI_LOCK_WRITE);
switch (ctrl->action) {
case HOST_OPEN:
if (!(w->host.status & XCE_WORKER_CLOSED)) {
@ -579,6 +625,11 @@ int worker_ctrl(cluster_t* c, xce_hostctrl_t* ctrl)
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER,
HOOK_AFTER_EVENT, HOOK_DETAIL_WORKER_UPDATE, c, w);
}
unlock(w);
dereference(w);
clean:
return rc;
}