fix(scheduler): load shared resource values from the snapshot (bug-1923)

xce_scheduler --sim started with no shared resource pool when the shared
values came only from the recording's SnapshotEntry (license value=(none)),
so jobs needing a shared resource pended instead of dispatching. Two
defects caused it:

- Load side (snapshot_load.c): a resval was treated as shared only when
  rv->host == NULL. The capnp round trip (write_snapshot_entry ->
  decode_SnapshotEntry) reads a NULL host back as "", so every shared
  resval in a .replay file was skipped. A NULL or empty host now means
  the shared pool; only a named host marks per-worker data.
- Save side (snapshot.c, snapshot_wire.c): core->sharedInst and each
  worker's resvals were walked with i < .count. zarray_t.count is the
  number of filled slots, not the highest idx + 1, and both arrays are
  sparse by resource idx, so higher-index values were dropped from the
  snapshot. Both loops are now bounded by .caps, as repl_info.c already is.

New test test_snapshot_sparse_resvals.c covers the in-memory save/load,
the empty-host load, and the real sched_record_start() -> .replay ->
sched_sim_driver_start() round trip.

Regenerated fixtures/repl_trace_baseline/set_output.replay: its mid-run
snapshot now carries license, limit=cluster_slots and each worker's
limit=host_slots, which the old writer dropped (all other fixtures
unchanged).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-10-08 08:09:29 +00:00
parent 4f951f2b52
commit 16616d9688
Signed by untrusted user: rshen
GPG key ID: 80533536B0EB651C
7 changed files with 453 additions and 5 deletions

View file

@ -2531,3 +2531,26 @@ sched_trace_model_test = executable(
test('scheduler trace model test',
sched_trace_model_test, suite: 'scheduler',
env: ['ASAN_OPTIONS=detect_leaks=0'])
# bug-1923: shared (sharedInst) and per-worker resource values at sparse
# resource indices survive snapshot save and load, in memory and through
# the real sched_record_start() -> .replay -> sched_sim_driver_start() seam
# (where a NULL resval host decodes as ""). Same real-scheduler_srcs link
# technique as sched_sim_e2e_limit_visibility_test.
sched_snapshot_sparse_resvals_test_srcs = ['test_snapshot_sparse_resvals.c']
foreach f : scheduler_srcs
if f != 'src/main.c'
sched_snapshot_sparse_resvals_test_srcs += ['../' + f]
endif
endforeach
sched_snapshot_sparse_resvals_test = executable(
'sched_snapshot_sparse_resvals_test',
sched_snapshot_sparse_resvals_test_srcs,
include_directories:[incdir],
dependencies: [scheduler_test_deps],
install: false)
test('scheduler snapshot sparse resvals test',
sched_snapshot_sparse_resvals_test, suite: 'scheduler',
env: ['ASAN_OPTIONS=detect_leaks=0'])