9.5 KiB
Implementation Tasks: resval-id-decoupling
Generated: 2026-05-12T07:45:00-07:00 Feature: resval-id-decoupling Status: Tasks Generated
Task Overview
7 major tasks, 19 sub-tasks. All 6 requirements covered.
Dependencies: Task 1 must complete first (headers + schema unblock everything). Tasks 2 and 3 can proceed in parallel after Task 1. Tasks 4, 5, 6 can proceed in parallel after Tasks 2 and 3. Task 7 last.
Tasks
1. Update shared headers and capnp schema
Change the wire type and C struct types that carry resource values across subsystem boundaries. This is the structural foundation — all downstream tasks depend on these types compiling correctly.
-
1.1 In
src/schema/controller.capnp, changeWorker.resvals @5andConf4Sched.resvals @6fromList(ValueWithIdx)toList(NameValue). Preserve field ordinal numbers; only the element type changes. Requirements: 1, 2, 3, 4 -
1.2 In
src/include/xce/types.h, changexce_worker_t.resvals_to_schedfromxce_val_with_idx_t**toxce_name_val_t**. Requirements: 2, 3 -
1.3 In
src/include/typemap.h, changexce_conf4sched_t.resvalsfromxce_val_with_idx_t**toxce_name_val_t**. Requirements: 1, 4 -
1.4 Run
nix develop --command ninja -C src/buildto regeneratecontroller.capnp.[ch]. Confirm the generatedencode_Conf4Schedanddecode_Conf4Schednow callencode_NameValue_list/decode_NameValue_listinstead of theirValueWithIdxcounterparts. Expect compiler errors at this stage from old call sites — that is expected and resolved in subsequent tasks.
2. (P) Replace free_resval_with_idx_list with free_name_val_list
Swap the heap-cleanup utility function to match the new element type. Old callers in the controller will be updated in Task 4.
-
2.1 In
src/lib/utils.c, addfree_name_val_list(xce_name_val_t*** vals, int count): iterate the array, free each entry'sname, freeval->u.svalueif string-typed, freeval, free the entry, then null and free the array pointer. Mirror the structure of the existingfree_resval_with_idx_list. -
2.2 In
src/include/utils.h, remove thefree_resval_with_idx_listdeclaration and addextern void free_name_val_list(xce_name_val_t***, int);. -
2.3 In
src/lib/utils.c, delete thefree_resval_with_idx_listimplementation. Requirements: 5
3. (P) Add collect_resval and remove collect_resval_with_idx
Replace the index-keyed collector in the controller with a name-keyed one. The key
design inversion: iterate resmgr (names) rather than the zarray_t (slots), using
r->idx to look up values. This guarantees every emitted record carries a valid name.
-
3.1 In
src/controller/dataex.c, addcollect_resval(var resmgr, zarray_t* array, xlist_t* l): acquire a read lock onresmgr, iterate withiter_make/iter_next/iter_destroy, for eachxce_resource_t* rcallzarray_get(array, r->idx)to get the value (skip if NULL), allocate anxce_name_val_t, copy name (strdup) and value (strdup svalue or memcpy), store in the list. Release the resmgr lock. Returnl->count. The array lock is the caller's responsibility (consistent with old pattern). Requirements: 1, 2, 5 -
3.2 In
src/controller/dataex.c, rewritecollect_shared_resvalsto lockc->sharedinst.lock, callcollect_resval(c->resmgr, &c->sharedinst, l), then unlock. The unusedfnparameter is retained for signature consistency. Requirements: 1 -
3.3 In
src/controller/dataex.c, updatecollect_resvals_workersto acceptvar resmgras a new first parameter. Replace thecollect_resval_with_idxcall withmylock_lock(&w->resvals.lock)/collect_resval(resmgr, &w->resvals, &lst)/mylock_unlock. Update the call site incollect_workersto passc->resmgr. Requirements: 2 -
3.4 In
src/controller/dataex.c, delete bothcollect_resval_with_idx_(static) andcollect_resval_with_idx. Insrc/controller/include/cluster.h, remove thecollect_resval_with_idxdeclaration. Requirements: 5
4. (P) Update controller call sites
Update all controller sites that populate or clean up resvals_to_sched /
conf4sched->resvals to use the new type and free function. Tasks 2 and 3 must be
complete before this task.
-
4.1 In
src/controller/sched.c—xcesched_push_configs: change the cast from(xce_val_with_idx_t**)to(xce_name_val_t**)when assigningxreslist.datatoconf4sched->resvals, and replacefree_resval_with_idx_listwithfree_name_val_list. Requirements: 1 -
4.2 In
src/controller/sched.c—xcesched_push_workerlistand its worker-loop cleanup: addmylock_lock/mylock_unlockaroundcollect_resval, change cast to(xce_name_val_t**), replace allfree_resval_with_idx_listcalls withfree_name_val_list. Requirements: 2 -
4.3 In
src/controller/sched.c:226,src/controller/reply.c:66, andsrc/controller/opget.c:128, replace eachfree_resval_with_idx_listcall withfree_name_val_list. Requirements: 5 -
4.4 In
src/controller/apiserver.c—apiserver_worker_change: addmylock_lock/mylock_unlockaroundcollect_resval, change cast to(xce_name_val_t**), replacefree_resval_with_idx_listwithfree_name_val_listat both cleanup sites (lines 51 and 397–399). Requirements: 3
5. (P) Update scheduler — shared resource value initialisation
Change sched_init_sharedInst to resolve resource values by name via the scheduler's
own resmgr instead of using the raw index received from the controller. Task 1 must be
complete before this task.
- 5.1 In
src/scheduler/src/scheduler.c—sched_init_sharedInst: replace theidx-direct loop with a name-lookup loop. For eachxce_name_val_t* nvinsched->config->resvals: skip ifnvornv->nameis NULL; callkey_find(sched->resmgr, nv->name, &r); if not found emitWARNand continue; thenMOVE_PTR(val, nv->val)andzarray_put(&sched->sharedInst, r->idx, val). Do not change the call order insched_init_config—sched_init_resourcesmust remain beforesched_init_sharedInst. Requirements: 1, 6
6. (P) Update scheduler — per-worker resource value initialisation
Change make_sched_worker to resolve worker resource values by name. Task 1 must be
complete before this task.
- 6.1 In
src/scheduler/src/schedobj.c—make_sched_worker: replace theidx-direct loop with a name-lookup loop. For eachxce_name_val_t* nvinw->resvals_to_sched: skip ifnvornv->nameis NULL; callkey_find(sched->resmgr, nv->name, &r); if not found emitWARNand continue; thenMOVE_PTR(val, nv->val)andzarray_put(&worker->resvals, r->idx, val). The existingschedpointer (cast fromvoid* arg) is already available at the top of the function. Requirements: 2, 6
7. Update Go API server to consume worker resource values
Update the Go API server frontend to read resvals_to_sched (now xce_name_val_t**)
from received worker data and expose resource values in the HostInfo model. Previously
the Go layer ignored this field entirely.
-
7.1 In
src/frontend/apiserver/models/hosts.go, addResourceValues []models.ResourceDistributionInfo(orResourceValues []ResourceDistributionInfoif within the same package) toHostInfo. Requirements: 3 -
7.2 In
src/frontend/apiserver/backend/convert_pure.go, add aresvalsfield ([]models.ResourceDistributionInfo) torawWorkerData, and updaterawWorkerToModelto assigninfo.ResourceValues = r.resvals. Requirements: 3 -
7.3 In
src/frontend/apiserver/backend/convert.go, addcNameValToWorkerResval(workerName string, nv *C.xce_name_val_t) *models.ResourceDistributionInfo: return nil ifnvornv.valis nil (with a WARN log); setResourceNamefromnv.name,LocationfromworkerName,IsDynamic: true; decode the value type using the samexce_val_whichswitch ascResvalToDistribution. Requirements: 3 -
7.4 In
src/frontend/apiserver/backend/convert.go, updatecWorkerToModelto iterateworker.nresvals_to_schedentries inworker.resvals_to_sched, callcNameValToWorkerResvalfor each, collect non-nil results, and store them inrawWorkerData.resvals. Requirements: 3
8. Build, verify, and clean up
Confirm the full system compiles and passes tests with no regressions. All prior tasks must be complete.
-
8.1 Run a full clean build:
nix develop --command bash -c "cd src && ninja -C build". Resolve any remaining compiler errors (expected: none if tasks 1–7 complete). Confirmcontroller.capnp.[ch]usesNameValuecodecs for bothConf4Sched.resvalsandWorker.resvals. -
8.2 Run the scheduler and controller test suites:
nix develop --command bash -c "cd src/frontend && make test"and any C-level tests undersrc/lib/testsuite/. Confirm all tests pass. Note:xcecli/common/outputfailure (undefined: parseJobTime) is pre-existing and unrelated to this feature. -
8.3 Verify no remaining references to
collect_resval_with_idxorfree_resval_with_idx_listinsrc/(excluding comments or git history):grep -r "collect_resval_with_idx\|free_resval_with_idx_list" src/. Expected: zero matches. Requirements: 5
Requirements Coverage
| Requirement | Tasks |
|---|---|
| 1 | 1.1, 1.3, 3.2, 4.1, 5.1 |
| 2 | 1.1, 1.2, 3.3, 4.2, 4.3, 6.1 |
| 3 | 1.1, 1.2, 4.4 |
| 4 | 1.1, 1.3 |
| 5 | 2.1, 2.2, 2.3, 3.4, 4.3, 7.3 |
| 6 | 5.1, 6.1 |