save works

This commit is contained in:
Rongsong Shen 2026-03-03 16:49:26 +08:00
parent f4b1ba4cd7
commit acfbec875b
51 changed files with 622 additions and 1175 deletions

View file

@ -3,7 +3,6 @@
#include "cluster.h"
#include "controller.capnp.h"
#include "objmgr.h"
#include "request.h"
#include "xce/types.h"
#include "xstring.h"
@ -27,16 +26,19 @@ static int xce_apiserver_push_workers(cluster_t* c, endpoint_t* ep)
xce_data_t data;
xce_workers_data_t workers
= { .n_total = 0, .pos = 0, .count = 0, .workers = NULL };
int i, rc = 0;
int i, rc = 0;
xlist_t wlist;
memset(&data, 0x0, sizeof(data));
xlist_init(&wlist, 8192);
data.table = Data_data_workers;
data.data.workers = &workers;
collect_workers(c, (collect_check_fn_t)check_worker_, &(workers.n_total),
&(workers.workers));
workers.count = workers.n_total;
collect_workers(c, (collect_check_fn_t)check_worker_, &wlist);
workers.n_total = wlist.count;
workers.workers = (xce_worker_t**)wlist.data;
workers.count = workers.n_total;
rc = xce_push_data_req(ep, c->myhost, &data, check_controller, c, 100);
@ -49,7 +51,8 @@ static int xce_apiserver_push_workers(cluster_t* c, endpoint_t* ep)
free_resval_with_idx_list(&(w->resvals_to_sched), w->nresvals_to_sched);
}
deref_objs(workers.n_total, (void**)workers.workers);
unlock_collect_workers(&wlist);
FREEUP(workers.workers);
return rc;
@ -69,18 +72,23 @@ static int xce_apiserver_push_jobs(cluster_t* c, endpoint_t* ep)
xce_data_t data;
xce_jobs_data_t jobs = { .n_total = 0, .pos = 0, .count = 0, .jobs = NULL };
int rc = 0;
xlist_t jlist;
memset(&data, 0x0, sizeof(data));
xlist_init(&jlist, 1024 * 1024);
data.table = Data_data_jobs;
data.data.jobs = &jobs;
collect_jobs(c, (collect_check_fn_t)check_job_, &(jobs.n_total),
&(jobs.jobs));
jobs.count = jobs.n_total;
collect_jobs(c, (collect_check_fn_t)check_job_, &jlist);
jobs.n_total = jlist.count;
jobs.jobs = (xce_job_t**)jlist.data;
jobs.count = jobs.n_total;
rc = xce_push_data_req(ep, c->myhost, &data, check_controller, c, 100);
deref_objs(jobs.n_total, (void**)jobs.jobs);
unlock_collect_jobs(&jlist);
FREEUP(jobs.jobs);
return rc;
@ -256,7 +264,7 @@ static int apiserver_job_update_fun(int type, int situation, void* data,
int rc;
xce_notify_data_t xdata
= { .event = NotifyData_data_updateJob,
.data = { .update_job = &(job->job) } };
.data = { .update_job = &(job->job) } };
rc = notify(c, c->apiservers[i].ep, &xdata);
if (rc < 0) {
@ -349,13 +357,16 @@ static int apiserver_push_workerlist(cluster_t* c, endpoint_t* ep, xlist_t* l)
static int apiserver_worker_change(int type, int situation, void* data,
cluster_t* c, worker_t* w)
{
int i;
int i;
xlist_t resvalist;
TRACE("%s worker %s idx %d situation %d", __func__, w->host.name, w->idx,
situation);
collect_resval_with_idx(&(w->host.resvals), &(w->host.nresvals_to_sched),
&(w->host.resvals_to_sched));
xlist_init(&resvalist, 256);
collect_resval_with_idx(&(w->host.resvals), &resvalist);
w->host.nresvals_to_sched = resvalist.count;
w->host.resvals_to_sched = (xce_val_with_idx_t**)resvalist.data;
switch (situation) {
case HOOK_AFTER_EVENT:
@ -383,8 +394,11 @@ static int apiserver_worker_change(int type, int situation, void* data,
break;
}
#if 0
free_resval_with_idx_list(&(w->host.resvals_to_sched),
w->host.nresvals_to_sched);
#endif
xlist_fini(&resvalist);
return 0;
}
@ -514,7 +528,7 @@ static int apiserver_queue_hook_fun(int type, int situation, int detail,
int rc;
xce_notify_data_t xdata
= { .event = NotifyData_data_schedUpdateQueue,
.data = { .sched_update_queue = &(q->queue) } };
.data = { .sched_update_queue = &(q->queue) } };
rc = notify(c, c->apiservers[i].ep, &xdata);
if (rc < 0) {
@ -585,7 +599,6 @@ int handle_apiserver_leave(cluster_t* c, endpoint_t* ep)
}
if (c->apiservers[i].name != NULL) {
obj_deref(c->apiservers[i].name);
c->apiservers[i].ep = NULL;
}

View file

@ -22,6 +22,7 @@
#include "worker.h"
#include "xce/errnox.h"
#include "xstring.h"
#include "jobj.h"
static xce_peerinfo_t from_controller
= { .name = "controller", .key = "keepSecret" };
@ -371,7 +372,7 @@ int cluster_build_resources(cluster_t* c)
for (i = 0; i < c->myconf->cluster_config->nres; i++) {
xce_resource_t* res;
res = makeResource(c->myconf->cluster_config->resources[i]);
res = makeResource(c->resmgr, c->myconf->cluster_config->resources[i]);
if (res == NULL) {
return -errno;
}
@ -568,7 +569,6 @@ int cluster_init(cluster_t* c)
c->configmgr = makeInstance(&xkvmgr_type, &config_mgr_params);
objmgr_init(&(c->objmgr));
c->jobmgr = makeInstance(&xkvmgr_type, &jobmgr_params);
c->resmgr = makeInstance(&xkvmgr_type, &resmgr_params);
zarray_init(&(c->sharedinst), c->myconf->cluster_config->resmgr->inst_delta,
@ -580,6 +580,7 @@ int cluster_init(cluster_t* c)
iomgr_set_ssl_ctx(&(c->iomgr), ssl_ctx);
xstring_table_init(c->myconf->cluster_config->xstrings->nhash_slots);
job_obj_init(5381, 5381);
zarray_init(&(c->endpoints), 16, endpoint_killer);
@ -775,12 +776,12 @@ void cluster_fini(cluster_t* c)
zarray_fini(&(c->endpoints));
zarray_fini(&(c->configs));
objmgr_fini(&(c->objmgr));
xce_hook_fini(&(c->hooksys));
cleanup_openssl();
job_obj_fini();
xstring_table_fini();
return;

View file

@ -4,6 +4,7 @@
#include "request.h"
#include "xce/cluster_def.h"
#include "xce/types.h"
#include "xlist.h"
typedef int (*check_fn_t)(void*);
@ -18,35 +19,9 @@ int check_controller(void* arg)
return 1;
}
static int collect_resval_with_idx_(zarray_t* array, int* nres,
xce_val_with_idx_t*** resvals)
static int collect_resval_with_idx_(zarray_t* array, xlist_t* l)
{
int nc;
int i, j;
xce_val_with_idx_t** vals;
nc = 0;
for (i = 0; i < array->caps; i++) {
if (array->data[i] == NULL) {
continue;
}
nc++;
}
if (nc == 0) {
*nres = 0;
*resvals = NULL;
return 0;
}
vals = (xce_val_with_idx_t**)calloc(nc, sizeof(xce_val_with_idx_t*));
if (vals == NULL) {
return -ENOMEM;
}
j = 0;
int i;
for (i = 0; i < array->caps; i++) {
xce_val_with_idx_t* val;
@ -58,17 +33,12 @@ static int collect_resval_with_idx_(zarray_t* array, int* nres,
val = (xce_val_with_idx_t*)calloc(1, sizeof(*val));
if (val == NULL) {
free_resval_with_idx_list(&vals, j);
return -ENOMEM;
}
vals[j] = val;
j++;
val->idx = i;
val->val = (xce_val_t*)calloc(1, sizeof(xce_val_t));
if (val->val == NULL) {
free_resval_with_idx_list(&vals, j);
return -ENOMEM;
}
@ -82,43 +52,36 @@ static int collect_resval_with_idx_(zarray_t* array, int* nres,
} else {
memcpy(val->val, array->data[i], sizeof(xce_val_t));
}
xlist_store(l, val);
}
*nres = j;
*resvals = vals;
return j;
return l->count;
}
int collect_resval_with_idx(zarray_t* array, int* nres,
xce_val_with_idx_t*** resvals)
int collect_resval_with_idx(zarray_t* array, xlist_t* l)
{
int rc = 0;
mylock_lock(&(array->lock));
rc = collect_resval_with_idx_(array, nres, resvals);
rc = collect_resval_with_idx_(array, l);
mylock_unlock(&(array->lock));
return rc;
}
void collect_confvars(cluster_t* c, collect_check_fn_t fn, int* nconfig,
xce_config_t*** configs)
void collect_confvars(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
{
iterator_t it;
int nc = 0, idx;
int rc;
*nconfig = 0;
*configs = NULL;
rc = iter_make(&it, c->configmgr);
if (rc < 0) {
return;
}
nc = 0;
for (;;) {
xce_config_t* config = NULL;
@ -127,124 +90,60 @@ void collect_confvars(cluster_t* c, collect_check_fn_t fn, int* nconfig,
break;
}
if (config != NULL) {
nc++;
}
}
if (rc < 0) {
iter_destroy(&it);
return;
}
if (nc == 0) {
iter_destroy(&it);
return;
}
iter_reset(&it);
*configs = (xce_config_t**)calloc(nc, sizeof(xce_config_t*));
if ((*configs) == NULL) {
return;
}
idx = 0;
for (;;) {
xce_config_t* config = NULL;
rc = iter_next(&it, (void**)&config);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
if (config == NULL) {
continue;
}
if (config != NULL) {
(*configs)[idx] = config;
idx++;
if ((fn == NULL) || (fn(config))) {
xlist_store(l, config);
}
}
iter_destroy(&it);
return;
}
void collect_queues(cluster_t* c, collect_check_fn_t fn, int* nqueues,
xce_queue_t*** queues)
void collect_queues(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
{
iterator_t it;
int count;
int rc;
int nc;
*nqueues = 0;
*queues = NULL;
rc = iter_make(&it, c->qmgr);
if (rc < 0) {
return;
}
count = 0;
for (;;) {
xce_queue_t* q = NULL;
queue_t* q = NULL;
rc = iter_next(&it, (void**)&q);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
}
if (q != NULL) {
count++;
if (q == NULL) {
continue;
}
if ((fn != NULL) || fn(q)) {
lock(q, RTTI_LOCK_READ);
xlist_store(l, &(q->queue));
}
}
if (rc < 0) {
return;
}
*queues = (xce_queue_t**)calloc(count, sizeof(xce_queue_t*));
if ((*queues) == NULL) {
iter_destroy(&it);
return;
}
iter_reset(&it);
nc = 0;
for (;;) {
xce_queue_t* q = NULL;
rc = iter_next(&it, (void**)&q);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
}
if (q != NULL) {
(*queues)[nc] = q;
nc++;
}
}
*nqueues = nc;
iter_destroy(&it);
}
void collect_resources(cluster_t* c, collect_check_fn_t fn, int* nresources,
xce_resource_t*** resources)
void collect_resources(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
{
iterator_t it;
int rc;
int i, nc;
*nresources = 0;
*resources = NULL;
rc = iter_make(&it, c->resmgr);
if (rc < 0) {
return;
}
nc = 0;
for (;;) {
xce_resource_t* r = NULL;
@ -253,186 +152,145 @@ void collect_resources(cluster_t* c, collect_check_fn_t fn, int* nresources,
break;
}
if (r != NULL) {
nc++;
}
}
if ((rc < 0) || (nc == 0)) {
iter_destroy(&it);
return;
}
*resources = calloc(nc, sizeof(xce_resource_t));
if ((*resources) == NULL) {
iter_destroy(&it);
return;
}
iter_reset(&it);
i = 0;
for (;;) {
xce_resource_t* r = NULL;
rc = iter_next(&it, (void**)&r);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
if (r == NULL) {
continue;
}
if (r != NULL) {
(*resources)[i] = r;
i++;
if ((fn == NULL) || (fn(r))) {
xlist_store(l, r);
}
}
*nresources = i;
iter_destroy(&it);
return;
}
void collect_jobs(cluster_t* c, collect_check_fn_t fn, int* njobs,
xce_job_t*** jobs)
void collect_jobs(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
{
iterator_t it;
int nc, i;
int rc = 0;
*njobs = 0;
*jobs = NULL;
rc = iter_make(&it, c->jobmgr);
if (rc < 0) {
return;
}
nc = 0;
for (;;) {
xce_job_t* j = NULL;
job_t* j = NULL;
rc = iter_next(&it, (void**)&j);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
}
if (j != NULL) {
nc++;
}
}
if ((rc < 0) || (nc == 0)) {
iter_destroy(&it);
return;
}
iter_reset(&it);
i = 0;
for (;;) {
xce_job_t* j = NULL;
rc = iter_next(&it, (void**)&j);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
if (j == NULL) {
continue;
}
if (j != NULL) {
(*jobs)[i] = j;
i++;
if ((fn == NULL) || (fn(j))) {
lock(j, RTTI_LOCK_READ);
xlist_store(l, &(j->job));
}
}
*njobs = i;
iter_destroy(&it);
return;
}
void collect_workers(cluster_t* c, collect_check_fn_t fn, int* nworkers,
xce_worker_t*** workers)
void collect_workers(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
{
iterator_t it;
int i, nc;
int rc = 0;
*nworkers = 0;
*workers = NULL;
rc = iter_make(&it, c->workermgr);
if (rc < 0) {
return;
}
nc = 0;
for (;;) {
xce_worker_t* w = NULL;
worker_t* w = NULL;
rc = iter_next(&it, (void**)&w);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
}
if (w != NULL) {
nc++;
}
}
if ((rc < 0) || (nc == 0)) {
iter_destroy(&it);
return;
}
iter_reset(&it);
i = 0;
for (;;) {
xce_worker_t* w = NULL;
rc = iter_next(&it, (void**)&w);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
if (w == NULL) {
continue;
}
if (w != NULL) {
(*workers)[i] = w;
i++;
if ((fn == NULL) || (fn(w))) {
lock(w, RTTI_LOCK_READ);
xlist_store(l, &(w->host));
}
}
*nworkers = i;
iter_destroy(&it);
return;
}
void collect_shared_resvals(cluster_t* c, collect_check_fn_t fn, int* nres,
xce_val_with_idx_t*** resvals)
void collect_shared_resvals(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
{
collect_resval_with_idx(&(c->sharedinst), nres, resvals);
collect_resval_with_idx(&(c->sharedinst), l);
return;
}
void deref_objs(int count, void** objs)
{
int i;
for (i = 0; i < count; i++) {
void* obj = objs[i];
if (obj == NULL) {
continue;
}
DEREF_OBJ(obj);
}
}
int notify(cluster_t* c, endpoint_t* ep, xce_notify_data_t* data)
{
return xce_notify_req(ep, data);
}
void unlock_collect_queues(xlist_t* l)
{
int i;
for (i = 0; i < l->count; i++) {
xce_queue_t* q = (xce_queue_t*)xlist_get(l, i);
queue_t* q1;
if (q == NULL) {
continue;
}
q1 = CONTAINER_OF(q, queue_t, queue);
unlock(q1);
}
}
void unlock_collect_workers(xlist_t* l)
{
int i;
for (i = 0; i < l->count; i++) {
xce_worker_t* w = (xce_worker_t*)xlist_get(l, i);
worker_t* w1;
if (w == NULL) {
continue;
}
w1 = CONTAINER_OF(w, worker_t, host);
unlock(w1);
}
}
void unlock_collect_jobs(xlist_t* l)
{
int i;
for (i = 0; i < l->count; i++) {
xce_job_t* j = (xce_job_t*)xlist_get(l, i);
job_t* j1;
if (j == NULL) {
continue;
}
j1 = CONTAINER_OF(j, job_t, job);
unlock(j1);
}
}

View file

@ -12,7 +12,6 @@
#include "myconf.h"
#include "mylock.h"
#include "netio.h"
#include "objmgr.h"
#include "vtaskmgr.h"
#include "worker.h"
#include "xce/cluster_def.h"
@ -47,24 +46,20 @@ extern queue_t* create_queue(cluster_t*, xce_queue_t*);
extern int build_queues(void*);
extern void queue_fini(queue_t*);
extern int queue_ctrl(cluster_t*, xce_queuectrl_t*);
extern queue_t* qmgr_lockq(qmgr_t*, char*, int);
extern int xce_update_data(endpoint_t*, cluster_t*, int, int, int*, int,
xce_kv_t*);
extern int on_scheduler_join(cluster_t*);
extern int on_apiserver_join(cluster_t*, endpoint_t*);
extern int xce_push_reslist(endpoint_t*, cluster_t*, int, xce_resource_t**);
extern int xce_push_confvars(endpoint_t*, cluster_t*, int, xce_config_t**);
extern int xce_push_workerlist(endpoint_t*, cluster_t*, int, xce_worker_t**);
extern int xce_push_joblist(endpoint_t*, cluster_t*, int, xce_job_t**);
extern int xce_push_queuelist(endpoint_t*, cluster_t*, int, xce_queue_t**);
extern int xcesched_push_job(cluster_t*, uint64_t);
extern int on_worker_join(void*, endpoint_t*);
extern int get_resval(cluster_t*, char*, char*, xce_val_t*);
extern job_t* jobmgr_lockjob(jobmgr_t*, uint64_t, int);
extern int32_t jobmgr_add_job(jobmgr_t*, job_t*);
extern void jobmgr_del_job(jobmgr_t*, job_t*);
extern int xce_push_reslist(endpoint_t*, cluster_t*, int, xce_resource_t**);
extern int xce_push_confvars(endpoint_t*, cluster_t*, int, xce_config_t**);
extern int xce_push_workerlist(endpoint_t*, cluster_t*, int, xce_worker_t**);
extern int xce_push_joblist(endpoint_t*, cluster_t*, int, xce_job_t**);
extern int xce_push_queuelist(endpoint_t*, cluster_t*, int, xce_queue_t**);
extern int xcesched_push_job(cluster_t*, uint64_t);
extern int on_worker_join(void*, endpoint_t*);
extern int get_resval(cluster_t*, char*, char*, xce_val_t*);
extern int handle_push(struct capn*, cluster_t*, endpoint_t*, struct Request*);
extern int do_get_op(cluster_t*, endpoint_t*, xce_request_t*);
extern int do_update_op(cluster_t*, endpoint_t*, xce_request_t*);
@ -78,19 +73,15 @@ extern int mark_worker_back(cluster_t*, worker_t*);
extern int handle_scheduler_leave(cluster_t*);
extern int handle_clusterconf(cluster_t*, endpoint_t*, xce_request_t*);
extern void collect_confvars(cluster_t*, collect_check_fn_t, int*,
xce_config_t***);
extern void collect_queues(cluster_t*, collect_check_fn_t, int*,
xce_queue_t***);
extern void collect_resources(cluster_t*, collect_check_fn_t, int*,
xce_resource_t***);
extern void collect_jobs(cluster_t*, collect_check_fn_t, int*, xce_job_t***);
extern void collect_workers(cluster_t*, collect_check_fn_t, int*,
xce_worker_t***);
extern void deref_objs(int, void**);
extern void collect_confvars(cluster_t*, collect_check_fn_t, xlist_t*);
extern void collect_queues(cluster_t*, collect_check_fn_t, xlist_t*);
extern void collect_resources(cluster_t*, collect_check_fn_t, xlist_t*);
extern void collect_jobs(cluster_t*, collect_check_fn_t, xlist_t*);
extern void collect_workers(cluster_t*, collect_check_fn_t, xlist_t*);
extern int get_queue_exec(cluster_t*, char*, char**, char**);
extern int jobmgr_iter(jobmgr_t*, xlist_t*, void*);
extern int workermgr_iter(workermgr_t*, xlist_t*, void*);
extern void unlock_collect_queues(xlist_t*);
extern void unlock_collect_jobs(xlist_t*);
extern void unlock_collect_workers(xlist_t*);
extern int on_job_start(cluster_t*, job_pidinfo_t*);
extern int on_job_finish(cluster_t*, xce_jobfinish_t*);
@ -125,7 +116,7 @@ extern int on_task_finish(cluster_t*, xce_task_finish_t*);
extern int xce_controller_res_init(cluster_t*);
extern int map_resource_to_host(char*, cluster_t*);
extern int release_resource_from_worker(char*, cluster_t*);
extern int collect_resval_with_idx(zarray_t*, int*, xce_val_with_idx_t***);
extern int collect_resval_with_idx(zarray_t*, xlist_t*);
extern int do_set_preason(cluster_t*, endpoint_t*, xce_request_t*);
extern int do_clr_preason(cluster_t*, endpoint_t*, xce_request_t*);
extern int handle_apiserver_leave(cluster_t*, endpoint_t*);

View file

@ -170,7 +170,6 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
nc = alloc->nhosts;
if (nc <= 0) {
obj_deref(j);
return -EINVAL;
}
@ -188,7 +187,6 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
if (w == NULL) {
free_launchinfo(&launchinfo);
obj_deref(j);
return -errno;
}
@ -197,9 +195,6 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
w->host.name, w->host.status, w->ep);
free_launchinfo(&launchinfo);
obj_deref(w);
obj_deref(j);
SET_ERROR(E_XCE_BAD_WORKER);
return -errno;
}
@ -211,17 +206,13 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
rc = get_queue_exec(c, j->job.submit->queue, &q_pre_exec, &q_post_exec);
if (rc < 0) {
obj_deref(j);
obj_deref(w);
return rc;
}
if (j->job.submit->start_info->q_pre_exec != NULL) {
obj_deref(j->job.submit->start_info->q_pre_exec);
}
if (j->job.submit->start_info->q_post_exec != NULL) {
obj_deref(j->job.submit->start_info->q_post_exec);
}
j->job.submit->start_info->q_pre_exec = q_pre_exec;
@ -245,8 +236,6 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
MOVE_PTR(j->job.allocs->allocs, allocs);
alloc->allocs = NULL;
DEREF_OBJ(w);
DEREF_OBJ(j);
if (rc < 0) {
SET_ERROR(-rc);
@ -299,7 +288,6 @@ int job_ctrl(cluster_t* c, xce_jobctrl_t* ctrinfo)
w->host.name, w->host.status, w->ep);
rc = -errno;
}
obj_deref(w);
} else {
rc = -errno;
}
@ -365,7 +353,6 @@ int job_ctrl(cluster_t* c, xce_jobctrl_t* ctrinfo)
}
}
obj_deref(j);
return rc;
}
@ -424,8 +411,6 @@ int handle_jobdispatch(cluster_t* c, endpoint_t* ep, xce_request_t* request)
static int xlist_deref_job_item_(job_t* j, void* arg)
{
obj_deref(j);
return 0;
}
@ -481,7 +466,6 @@ int handle_jobsubmit(cluster_t* c, endpoint_t* ep, xce_request_t* request)
} else {
if (xlist_store(&jlist, j) < 0) {
PERROR("xlist_store");
obj_deref(j);
}
}
}
@ -748,7 +732,6 @@ int on_job_ckpt(cluster_t* c, endpoint_t* ep, xce_ckptinfo_t* ckptinfo)
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT,
HOOK_DETAIL_JOB_CKPT, c, j);
if (j->job.ckptinfo != NULL) {
obj_deref(j->job.ckptinfo);
}
j->job.ckptinfo = makeString(info);
@ -756,8 +739,6 @@ int on_job_ckpt(cluster_t* c, endpoint_t* ep, xce_ckptinfo_t* ckptinfo)
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT,
HOOK_DETAIL_JOB_CKPT, c, j);
obj_deref(j);
return 0;
}
@ -796,13 +777,10 @@ int update_job_rusages(cluster_t* c, endpoint_t* ep, xce_request_t* request)
w = get_ep_worker(c, ep);
if (w == NULL) {
obj_deref(j);
return errno;
}
host = makeString(w->host.name);
obj_deref(w);
if (host == NULL) {
return -ENOMEM;
}
@ -825,7 +803,6 @@ int update_job_rusages(cluster_t* c, endpoint_t* ep, xce_request_t* request)
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT,
HOOK_DETAIL_JOB_UPDATE, c, j);
obj_deref(j);
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT,
HOOK_DETAIL_JOB_RUSAGE_UPDATE, c, rusages);
@ -923,7 +900,6 @@ int do_clr_preason(cluster_t* c, endpoint_t* ep, xce_request_t* request)
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT,
HOOK_DETAIL_CLRPREASON, c, j);
obj_deref(j);
}
return 0;

View file

@ -2,7 +2,6 @@
#include <stdlib.h>
#include "cluster.h"
#include "objmgr.h"
#include "worker.h"
#include "xce/types.h"
#include "xlist.h"

View file

@ -4,10 +4,9 @@
#include <string.h>
#include <tlog.h>
#include "configobj.h"
#include "controller.capnp.h"
#include "myconf.h"
#include "configobj.h"
#include "objmgr.h"
#include "utils.h"
#include "xce/cluster_def.h"
#include "xce/types.h"
@ -18,7 +17,7 @@ int add_config(void* c, char* name, char* value)
xce_config_t cvar = { .name = name, .value = value };
xce_config_t* cv = NULL;
cv = makeConfig(&cvar);
cv = makeConfig(cls->configmgr, &cvar);
if (cv == NULL) {
return -errno;
}

View file

@ -17,9 +17,14 @@ static int do_reply_reslist(cluster_t* c, endpoint_t* ep,
xce_data_t getdata = { .table = request->body.getmsg->table,
.data = { .resources = &resdata } };
int rc = 0;
xlist_t rlist;
init_reply_by_req(&reply, request);
collect_resources(c, NULL, &(resdata.n_total), &(resdata.resources));
xlist_init(&rlist, 512);
collect_resources(c, NULL, &rlist);
resdata.n_total = rlist.count;
resdata.resources = (xce_resource_t**)rlist.data;
reply.status = 0;
reply.data_which = RequestReply_data_getdata;
@ -27,8 +32,7 @@ static int do_reply_reslist(cluster_t* c, endpoint_t* ep,
rc = xce_reply_get(ep, c->myhost, &reply, NULL, NULL, -1);
deref_objs(resdata.n_total, (void**)resdata.resources);
FREEUP(resdata.resources);
xlist_fini(&rlist);
return rc;
}
@ -101,12 +105,16 @@ static int do_reply_workerlist(cluster_t* c, endpoint_t* ep,
.workers = &workerdata }
};
/* clang-format on */
int rc = 0;
int i;
int rc = 0;
int i;
xlist_t wlist;
init_reply_by_req(&reply, request);
collect_workers(c, (collect_check_fn_t)check_worker_, &(workerdata.n_total),
&(workerdata.workers));
xlist_init(&wlist, 1024);
collect_workers(c, (collect_check_fn_t)check_worker_, &wlist);
workerdata.n_total = wlist.count;
workerdata.workers = (xce_worker_t**)wlist.data;
reply.status = 0;
reply.data_which = RequestReply_data_getdata;
@ -120,21 +128,13 @@ static int do_reply_workerlist(cluster_t* c, endpoint_t* ep,
free_resval_with_idx_list(&(w->resvals_to_sched), w->nresvals_to_sched);
}
deref_objs(workerdata.n_total, (void**)workerdata.workers);
FREEUP(workerdata.workers);
unlock_collect_workers(&wlist);
xlist_fini(&wlist);
return rc;
}
static int check_job_(xce_job_t* j)
{
if (j == NULL) {
return 0;
}
return 1;
}
static int do_reply_joblist(cluster_t* c, endpoint_t* ep,
xce_request_t* request)
{
@ -144,9 +144,12 @@ static int do_reply_joblist(cluster_t* c, endpoint_t* ep,
.data = { .jobs = &jobdata } };
int rc = 0;
xce_match_t* match = request->body.getmsg->condition;
xlist_t jlist;
init_reply_by_req(&reply, request);
xlist_init(&jlist, 1024*1024);
if (match->type == MatchCondition_condition_matchjid) {
job_t* j = NULL;
@ -155,24 +158,25 @@ static int do_reply_joblist(cluster_t* c, endpoint_t* ep,
rc = key_find(c->jobmgr, (void*)match->condition.jobid, (void**)&j);
if (rc > 0) {
jobdata.jobs = (xce_job_t**)calloc(1, sizeof(xce_job_t*));
if (jobdata.jobs != NULL) {
jobdata.jobs[0] = &(j->job);
jobdata.n_total = 1;
}
lock(j, RTTI_LOCK_WRITE);
xlist_store(&jlist, &(j->job));
}
} else {
collect_jobs(c, (collect_check_fn_t)check_job_, &(jobdata.n_total),
&(jobdata.jobs));
collect_jobs(c, NULL, &jlist);
}
jobdata.n_total = jlist.count;
jobdata.jobs = (xce_job_t**)jlist.data;
reply.status = 0;
reply.data_which = RequestReply_data_getdata;
reply.data.getdata = &getdata;
rc = xce_reply_get(ep, c->myhost, &reply, check_controller, c, 100);
deref_objs(jobdata.n_total, (void**)jobdata.jobs);
unlock_collect_jobs(&jlist);
FREEUP(jobdata.jobs);
return rc;

View file

@ -39,7 +39,6 @@ static int do_update_resvals(cluster_t* c, endpoint_t* ep,
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_RESOURCE,
HOOK_AFTER_EVENT, HOOK_DETAIL_RESOURCE_UPDATE, c,
resvals);
DEREF_OBJ(w);
}
}
}

View file

@ -99,7 +99,6 @@ int queue_ctrl(cluster_t* c, xce_queuectrl_t* ctrl)
HOOK_AFTER_EVENT, HOOK_DETAIL_QUEUE_UPDATE, c, q);
}
clean:
obj_deref(q);
return rc;
}
@ -154,7 +153,5 @@ int get_queue_exec(cluster_t* c, char* queue, char** pre_exec, char** post_exec)
*post_exec = NULL;
}
obj_deref(q);
return 0;
}

View file

@ -28,7 +28,8 @@ int handle_clusterconf(cluster_t* c, endpoint_t* ep, xce_request_t* request)
}
};
/* clang-format on */
int i;
int i;
xlist_t clist, qlist, rlist, wlist;
init_reply_by_req(&reply, request);
@ -36,14 +37,26 @@ int handle_clusterconf(cluster_t* c, endpoint_t* ep, xce_request_t* request)
reply.data_which = RequestReply_data_clusterconf;
reply.data.clusterconf = &clusterconf;
collect_confvars(c, NULL, &(clusterconf.cfglist.count),
&(clusterconf.cfglist.configs));
collect_queues(c, NULL, &(clusterconf.qlist.count),
&(clusterconf.qlist.queues));
collect_resources(c, NULL, &(clusterconf.reslist.count),
&(clusterconf.reslist.res));
collect_workers(c, (collect_check_fn_t)check_worker_,
&(clusterconf.wlist.count), &(clusterconf.wlist.workers));
xlist_init(&clist, 256);
xlist_init(&qlist, 64);
xlist_init(&rlist, 1024);
xlist_init(&wlist, 10240);
collect_confvars(c, NULL, &clist);
clusterconf.cfglist.count = clist.count;
clusterconf.cfglist.configs = (xce_config_t**)clist.data;
collect_queues(c, NULL, &qlist);
clusterconf.qlist.count = qlist.count;
clusterconf.qlist.queues = (xce_queue_t**)qlist.data;
collect_resources(c, NULL, &rlist);
clusterconf.reslist.count = rlist.count;
clusterconf.reslist.res = (xce_resource_t**)rlist.data;
collect_workers(c, (collect_check_fn_t)check_worker_, &wlist);
clusterconf.wlist.count = wlist.count;
clusterconf.wlist.workers = (xce_worker_t**)wlist.data;
xce_reply(ep, c->myhost, &reply);
@ -53,15 +66,13 @@ int handle_clusterconf(cluster_t* c, endpoint_t* ep, xce_request_t* request)
free_resval_with_idx_list(&(w->resvals_to_sched), w->nresvals_to_sched);
}
deref_objs(clusterconf.cfglist.count, (void**)clusterconf.cfglist.configs);
deref_objs(clusterconf.qlist.count, (void**)clusterconf.qlist.queues);
deref_objs(clusterconf.reslist.count, (void**)clusterconf.reslist.res);
deref_objs(clusterconf.wlist.count, (void**)clusterconf.wlist.workers);
unlock_collect_queues(&qlist);
unlock_collect_workers(&wlist);
FREEUP(clusterconf.cfglist.configs);
FREEUP(clusterconf.qlist.queues);
FREEUP(clusterconf.reslist.res);
FREEUP(clusterconf.wlist.workers);
xlist_fini(&clist);
xlist_fini(&qlist);
xlist_fini(&rlist);
xlist_fini(&wlist);
return rc;
}

View file

@ -3,15 +3,13 @@
#include "cluster.h"
#include "controller.capnp.h"
#include "objmgr.h"
#include "request.h"
#include "worker.h"
#include "xce/cluster_def.h"
#include "xce/types.h"
#include "xcelimit.h"
extern void collect_shared_resvals(cluster_t*, collect_check_fn_t, int*,
xce_val_with_idx_t***);
extern void collect_shared_resvals(cluster_t*, collect_check_fn_t, xlist_t*);
static int xcesched_push_joblist(cluster_t* c, xlist_t* l)
{
@ -91,6 +89,10 @@ static int xcesched_push_configs(cluster_t* c)
};
xce_limit_config_t* limits[] = { &limit1_config, &limit2_config };
int nlimits = 2;
xlist_t clist;
xlist_t qlist;
xlist_t rlist;
xlist_t xreslist;
memset(&configdata, 0x0, sizeof(configdata));
@ -100,14 +102,22 @@ static int xcesched_push_configs(cluster_t* c)
return -ENOMEM;
}
collect_confvars(c, NULL, &(configdata.data.conf4sched->n_confvars),
&(configdata.data.conf4sched->confvars));
collect_queues(c, NULL, &(configdata.data.conf4sched->n_queues),
&(configdata.data.conf4sched->queues));
collect_resources(c, NULL, &(configdata.data.conf4sched->n_resources),
&(configdata.data.conf4sched->resources));
collect_shared_resvals(c, NULL, &(configdata.data.conf4sched->nresvals),
&(configdata.data.conf4sched->resvals));
xlist_init(&clist, 64);
xlist_init(&qlist, 64);
xlist_init(&rlist, 256);
xlist_init(&xreslist, 256);
collect_confvars(c, NULL, &clist);
configdata.data.conf4sched->n_confvars = clist.count;
configdata.data.conf4sched->confvars = (xce_config_t**)clist.data;
collect_queues(c, NULL, &qlist);
configdata.data.conf4sched->n_queues = qlist.count;
configdata.data.conf4sched->queues = (xce_queue_t**)qlist.data;
collect_resources(c, NULL, &rlist);
configdata.data.conf4sched->n_resources = rlist.count;
configdata.data.conf4sched->resources = (xce_resource_t**)rlist.data;
collect_shared_resvals(c, NULL, &xreslist);
configdata.data.conf4sched->nresvals = xreslist.count;
configdata.data.conf4sched->resvals = (xce_val_with_idx_t**)xreslist.data;
configdata.data.conf4sched->n_ugroups = c->myconf->cluster_config->nugroups;
configdata.data.conf4sched->ugroups = c->myconf->cluster_config->ugroups;
@ -135,19 +145,15 @@ static int xcesched_push_configs(cluster_t* c)
free_resval_with_idx_list(&(configdata.data.conf4sched->resvals),
configdata.data.conf4sched->nresvals);
deref_objs(configdata.data.conf4sched->n_confvars,
(void**)configdata.data.conf4sched->confvars);
deref_objs(configdata.data.conf4sched->n_queues,
(void**)configdata.data.conf4sched->queues);
deref_objs(configdata.data.conf4sched->n_resources,
(void**)configdata.data.conf4sched->resources);
FREEUP(configdata.data.conf4sched->confvars);
FREEUP(configdata.data.conf4sched->queues);
FREEUP(configdata.data.conf4sched->resources);
FREEUP(configdata.data.conf4sched);
unlock_collect_queues(&qlist);
xlist_fini(&clist);
xlist_fini(&qlist);
xlist_fini(&rlist);
xlist_fini(&xreslist);
return rc;
}
@ -165,19 +171,22 @@ static int xcesched_push_jobs(cluster_t* c)
xce_data_t data;
xce_jobs_data_t jobs = { .n_total = 0, .pos = 0, .count = 0, .jobs = NULL };
int rc = 0;
xlist_t jlist;
memset(&data, 0x0, sizeof(data));
xlist_init(&jlist, 1024 * 1024);
data.table = Data_data_schedjobs;
data.data.jobs = &jobs;
collect_jobs(c, (collect_check_fn_t)check_job_, &(jobs.n_total),
&(jobs.jobs));
jobs.count = jobs.n_total;
collect_jobs(c, (collect_check_fn_t)check_job_, &jlist);
jobs.n_total = jlist.count;
jobs.jobs = (xce_job_t**)jlist.data;
jobs.count = jobs.n_total;
rc = xce_push_data_req(c->sched.ep, c->myhost, &data, check_controller, c,
100);
deref_objs(jobs.n_total, (void**)jobs.jobs);
FREEUP(jobs.jobs);
return rc;
@ -188,17 +197,20 @@ static int xcesched_push_workers(cluster_t* c)
xce_data_t data;
xce_workers_data_t workers
= { .n_total = 0, .pos = 0, .count = 0, .workers = NULL };
int rc = 0;
int i;
int rc = 0;
int i;
xlist_t wlist;
memset(&data, 0x0, sizeof(data));
xlist_init(&wlist, 8192);
data.table = Data_data_schedworkers;
data.data.workers = &workers;
collect_workers(c, (collect_check_fn_t)check_worker_, &(workers.n_total),
&(workers.workers));
workers.count = workers.n_total;
collect_workers(c, (collect_check_fn_t)check_worker_, &wlist);
workers.n_total = wlist.count;
workers.workers = (xce_worker_t**)wlist.data;
workers.count = workers.n_total;
rc = xce_push_data_req(c->sched.ep, c->myhost, &data, check_controller, c,
100);
@ -212,7 +224,6 @@ static int xcesched_push_workers(cluster_t* c)
free_resval_with_idx_list(&(w->resvals_to_sched), w->nresvals_to_sched);
}
deref_objs(workers.n_total, (void**)workers.workers);
FREEUP(workers.workers);
return rc;
@ -418,12 +429,15 @@ static int sched_worker_change(int type, int situation, void* data,
{
int rc = 0;
xlist_t wlist;
xlist_t resvalist;
TRACE("%s worker %s idx %d situation %d", __func__, w->host.name, w->idx,
situation);
collect_resval_with_idx(&(w->host.resvals), &(w->host.nresvals_to_sched),
&(w->host.resvals_to_sched));
xlist_init(&resvalist, 256);
collect_resval_with_idx(&(w->host.resvals), &resvalist);
w->host.nresvals_to_sched = resvalist.count;
w->host.resvals_to_sched = (xce_val_with_idx_t**)resvalist.data;
mylock_lock(&(c->sched.lock));
if (c->sched.ep != NULL) {
@ -440,8 +454,12 @@ static int sched_worker_change(int type, int situation, void* data,
}
mylock_unlock(&(c->sched.lock));
#if 0
/*FIXME*/
free_resval_with_idx_list(&(w->host.resvals_to_sched),
w->host.nresvals_to_sched);
#endif
xlist_fini(&resvalist);
return rc;
}
@ -469,9 +487,6 @@ static int sched_worker_join(int type, int situation, void* data, va_list ap)
rc = sched_worker_change(type, situation, data, c, w);
/* FIXME: need to mark the jobs in this worker */
obj_deref(w);
return rc;
}

View file

@ -27,14 +27,11 @@ static int run_tasks_on_host(cluster_t* c, endpoint_t* ep, uint64_t jobid,
}
if ((w->ep == NULL) || (IS_WORKER_UNAVAIL(w->host.status))) {
obj_deref(w);
return -EINVAL;
}
rc = xce_runtask_req(w->ep, &runmsg);
obj_deref(w);
return rc;
}

View file

@ -350,8 +350,6 @@ int add_worker(void* cls, endpoint_t* ep, const char* host, hostattrs_t* attrs)
mark_host_res(c, w, hconfig->resources[i]);
}
DEREF_OBJ(w); /* release update lock */
return idx;
}
@ -373,8 +371,6 @@ int restore_worker(void* cls, xce_worker_t host)
idx = w->idx;
w->host.status |= XCE_WORKER_UNAVAIL;
DEREF_OBJ(w);
return idx;
}
@ -396,30 +392,32 @@ static int worker_push_config(cluster_t* c, endpoint_t* ep)
{
xce_configdata_t configdata;
int rc = 0;
xlist_t clist;
memset(&configdata, 0x0, sizeof(configdata));
configdata.data.conf4worker
= (xce_conf4worker_t*)calloc(1, sizeof(xce_conf4worker_t));
configdata.data.conf4worker = calloc(1, sizeof(xce_conf4worker_t));
if (configdata.data.conf4worker == NULL) {
return -ENOMEM;
}
collect_confvars(c, (collect_check_fn_t)check_conf4worker_,
&(configdata.data.conf4worker->n_confvars),
&(configdata.data.conf4worker->confvars));
configdata.data_which = ConfigData_data_workerconfig;
xlist_init(&clist, 256);
collect_confvars(c, (collect_check_fn_t)check_conf4worker_, &clist);
configdata.data.conf4worker->n_confvars = clist.count;
configdata.data.conf4worker->confvars = (xce_config_t**)clist.data;
configdata.data_which = ConfigData_data_workerconfig;
configdata.data.conf4worker->clustername
= c->myconf->cluster_config->clustername;
rc = xce_pushconfig_req(ep, c->myhost, &configdata);
deref_objs(configdata.data.conf4worker->n_confvars,
(void**)configdata.data.conf4worker->confvars);
FREEUP(configdata.data.conf4worker->confvars);
FREEUP(configdata.data.conf4worker);
xlist_fini(&clist);
return rc;
}
@ -453,7 +451,6 @@ int get_resval(cluster_t* c, char* resname, char* host, xce_val_t* val)
if ((r->flags & XCE_RESF_SHARED) == 0) {
if ((host == NULL) || (strlen(host) == 0)) {
obj_deref(r);
return -EINVAL;
}
@ -537,7 +534,6 @@ int handle_worker_leave(cluster_t* c, int idx)
mark_worker_unavail(c, w);
obj_deref(w);
return 0;
}
@ -584,6 +580,5 @@ int worker_ctrl(cluster_t* c, xce_hostctrl_t* ctrl)
HOOK_AFTER_EVENT, HOOK_DETAIL_WORKER_UPDATE, c, w);
}
clean:
obj_deref(w);
return rc;
}