working on scheduler and fix issue #17

This commit is contained in:
Rongsong Shen 2025-12-25 16:24:56 +08:00
parent 4034fd7556
commit a46ea822c1
10 changed files with 159 additions and 40 deletions

View file

@ -418,6 +418,13 @@ int handle_jobdispatch(cluster_t* c, endpoint_t* ep, xce_request_t* request)
return rc;
}
static int xlist_deref_job_item_(job_t* j, void* arg)
{
obj_deref(j);
return 0;
}
int handle_jobsubmit(cluster_t* c, endpoint_t* ep, xce_request_t* request)
{
uint64_t jobid;
@ -425,6 +432,7 @@ int handle_jobsubmit(cluster_t* c, endpoint_t* ep, xce_request_t* request)
xce_reply_t reply;
xlist_t jlist;
job_t* j = NULL;
int i;
submit = request->body.jobsubmsg;
@ -455,26 +463,31 @@ int handle_jobsubmit(cluster_t* c, endpoint_t* ep, xce_request_t* request)
xce_reply(ep, c->myhost, &reply);
/* Run hooks to tell scheduler */
j = jobmgr_lockjob(&(c->jobmgr), jobid, OBJREF_READ);
if (j == NULL) {
char idstring[128];
xlist_init(&jlist, submit->array_size);
fmt_jobid(idstring, sizeof(idstring) - 1, jobid);
ERROR("%s fail to lock job %s (%lu)", __func__, idstring, jobid);
} else {
xlist_init(&jlist, 2);
if (xlist_store(&jlist, j) >= 0) {
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB,
HOOK_AFTER_EVENT, HOOK_DETAIL_JOB_NEW, c, &jlist);
for (i = 0; i < submit->array_size; i++) {
/* Run hooks to tell scheduler */
j = jobmgr_lockjob(&(c->jobmgr), jobid + i, OBJREF_READ);
if (j == NULL) {
char idstring[128];
fmt_jobid(idstring, sizeof(idstring) - 1, jobid);
ERROR("%s fail to lock job %s (%lu)", __func__, idstring, jobid);
} else {
PERROR("xlist_store");
if (xlist_store(&jlist, j) < 0) {
PERROR("xlist_store");
obj_deref(j);
}
}
obj_deref(j);
xlist_fini(&jlist);
}
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT,
HOOK_DETAIL_JOB_NEW, c, &jlist);
xlist_iter(&jlist, (xlist_iter_fn_t)xlist_deref_job_item_, NULL);
xlist_fini(&jlist);
return 0;
}