feat(raft-apply-decoupling): extract guarded fact transition logic into reusable cores (task 2.1)

Split mark_job_start/finish/fail/update in job.c into four hook-free
core functions (apply_job_*_transition) containing only the
monotonic-rank guard and mutation. Wrappers now peek the same guard
to decide hook-firing, then delegate to the core, preserving exact
pre-extraction hook-firing timing. Prerequisite for task 2.2's
apply_committed_entry() dispatch and the ordered apply pump (6.1).
This commit is contained in:
Rongsong Shen 2026-07-03 15:26:22 +00:00
parent 2d9f1e947a
commit 41d36204d5
6 changed files with 480 additions and 28 deletions

View file

@ -110,6 +110,32 @@ extern void unlock_collect_queues(xlist_t*);
extern void unlock_collect_jobs(xlist_t*);
extern void unlock_collect_workers(xlist_t*);
/* Outcome of a guarded job state-transition core (raft-apply-decoupling
* task 2.1, Req 3.3/7.1/7.2): APPLIED means the mutation happened;
* REJECTED_BACKWARD/NOOP_DUPLICATE mean the monotonic-rank guard held the
* transition back and no mutation occurred. These cores fire no hook
* themselves — hook-firing is the caller's responsibility, so it can be
* relocated (to the apply seam) without touching this guard logic again. */
typedef enum {
JOB_TRANSITION_APPLIED = 0,
JOB_TRANSITION_REJECTED_BACKWARD,
JOB_TRANSITION_NOOP_DUPLICATE,
} job_transition_result_t;
/* Guarded state-transition cores extracted from mark_job_start/finish/fail/
* update (job.c). Each applies exactly one fact's mutation to an
* already-locked job_t, subject to the same monotonic-rank guard the
* receipt-time wrapper used to apply inline. Callable directly — e.g. by a
* test, or later by the shared apply seam — without going through the
* worker-report receipt path. */
extern job_transition_result_t apply_job_start_transition(job_t*,
job_pidinfo_t*);
extern job_transition_result_t apply_job_finish_transition(job_t*,
xce_jobfinish_t*);
extern job_transition_result_t apply_job_fail_transition(job_t*,
job_failinfo_t*);
extern job_transition_result_t apply_job_update_transition(job_t*, int);
extern int on_job_start(cluster_t*, job_pidinfo_t*);
extern int on_job_finish(cluster_t*, xce_jobfinish_t*);
extern int on_job_fail(cluster_t*, job_failinfo_t*);