feat(scheduler-allocation): implement the shared host-candidate iterator

Adds host_iter.c: the one shared xce_host_iter_t implementation,
lazily filtering sched->core.workers by select expression
(sched_meet_host_selection, unchanged) and resource availability
(sched_check_host_satisfy, unchanged), with a real cancellation
point per candidate visited. xce_alloc_plan_t gains a ctx field
(xce_sched_ctx_t*) so the iterator can reach the scheduler/select
expression/staged resource-want -- additive to task 1.1's approved
interface, NULL-guarded at init(). Test proves the core design
property this spec exists to establish: a host too small for one
search remains a valid candidate for a later, smaller search via a
fresh iterator instance over the same worker set.

Task 2.1 (scheduler-allocation spec). Requirements 3.1-3.6.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XYdtrEWWZfKRRGED7raEYg
This commit is contained in:
Rongsong Shen 2026-09-04 16:46:03 +00:00
parent d0024eb7e8
commit d9831b0bc8
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
5 changed files with 872 additions and 2 deletions

View file

@ -1492,6 +1492,24 @@ sched_alloc_plan_iter_test = executable(
dependencies: [scheduler_test_deps],
install: false)
# Contract + behavioral test for the one shared xce_host_iter_t
# implementation (scheduler-allocation spec, task 2.1, Req 3 AC 1-6). Unlike
# sched_alloc_plan_iter_test's own trivial no-op stubs, this drives the REAL
# ../src/host_iter.c against real fixture state -- select-expression
# filtering, availability filtering, exhaustion, the fresh-per-bucket
# adversarial case (a host too small for one search remains a valid
# candidate for a later, smaller search over a freshly-initialized
# instance), and a behavioral proof of the required pthread_testcancel()
# cancellation point. Same white-box #include pattern as
# test_resource_accounting.c (../src/core.c, ../src/resource.c,
# ../src/schedobj.c) PLUS the new ../src/host_iter.c under test.
sched_host_iter_test = executable(
'sched_host_iter_test',
['test_host_iter.c'],
include_directories:[incdir],
dependencies: [scheduler_test_deps],
install: false)
# Register as meson tests so `meson test --suite scheduler` runs them all.
# detect_leaks=0 matches the suite convention (fixtures are not torn down).
test('scheduler test', scheduler_test, suite: 'scheduler',
@ -1677,3 +1695,6 @@ test('scheduler builtin fcfs cursor uaf test',
test('scheduler alloc plan iter test',
sched_alloc_plan_iter_test, suite: 'scheduler',
env: ['ASAN_OPTIONS=detect_leaks=0'])
test('scheduler host iter test',
sched_host_iter_test, suite: 'scheduler',
env: ['ASAN_OPTIONS=detect_leaks=0'])