@@ -186,6 +186,11 @@ int queue_policy_base_t::insert (std::shared_ptr<job_t> job)
186186 return detail::queue_policy_base_impl_t::insert (job);
187187}
188188
189+ int queue_policy_base_t::remove_pending (job_t *job)
190+ {
191+ return detail::queue_policy_base_impl_t::remove_pending (job);
192+ }
193+
189194int queue_policy_base_t::remove (flux_jobid_t id)
190195{
191196 return detail::queue_policy_base_impl_t::remove (id);
@@ -336,6 +341,45 @@ int queue_policy_base_impl_t::insert (std::shared_ptr<job_t> job)
336341 return rc;
337342}
338343
344+ int queue_policy_base_impl_t::remove_pending (job_t *job) {
345+ int rc = -1 ;
346+
347+ if (!job || job->state != job_state_kind_t ::PENDING) {
348+ errno = EINVAL;
349+ return rc;
350+ }
351+
352+ job->t_stamps .canceled_ts = m_cancel_cnt++;
353+ if (is_sched_loop_active ()) {
354+ // if sched-loop is active, the job's pending state
355+ // cannot be determined. There is "MAYBE pending state" where
356+ // a request has been sent out to the match service.
357+ auto res = m_pending_cancel_provisional.insert (
358+ std::pair<uint64_t , flux_jobid_t > (
359+ job->t_stamps .canceled_ts , job->id ));
360+ if (!res.second ) {
361+ errno = EEXIST;
362+ goto out;
363+ }
364+ } else {
365+ bool found_in_provisional = false ;
366+ if (erase_pending_job (job, found_in_provisional) < 0 )
367+ goto out;
368+ job->state = job_state_kind_t ::CANCELED;
369+ auto res = m_canceled.insert (
370+ std::pair<uint64_t , flux_jobid_t > (
371+ job->t_stamps .canceled_ts , job->id ));
372+ if (!res.second ) {
373+ errno = EEXIST;
374+ goto out;
375+ }
376+ m_schedulable = true ;
377+ }
378+ rc = 0 ;
379+ out:
380+ return rc;
381+ }
382+
339383int queue_policy_base_impl_t::remove (flux_jobid_t id)
340384{
341385 int rc = -1 ;
@@ -349,32 +393,7 @@ int queue_policy_base_impl_t::remove (flux_jobid_t id)
349393 job = m_jobs[id];
350394 switch (job->state ) {
351395 case job_state_kind_t ::PENDING:
352- job->t_stamps .canceled_ts = m_cancel_cnt++;
353- if (is_sched_loop_active ()) {
354- // if sched-loop is active, the job's pending state
355- // cannot be determined. There is "MAYBE pending state" where
356- // a request has been sent out to the match service.
357- auto res = m_pending_cancel_provisional.insert (
358- std::pair<uint64_t , flux_jobid_t > (
359- job->t_stamps .canceled_ts , job->id ));
360- if (!res.second ) {
361- errno = EEXIST;
362- goto out;
363- }
364- } else {
365- bool found_in_provisional = false ;
366- if (erase_pending_job (job, found_in_provisional) < 0 )
367- goto out;
368- job->state = job_state_kind_t ::CANCELED;
369- auto res = m_canceled.insert (
370- std::pair<uint64_t , flux_jobid_t > (
371- job->t_stamps .canceled_ts , job->id ));
372- if (!res.second ) {
373- errno = EEXIST;
374- goto out;
375- }
376- m_schedulable = true ;
377- }
396+ this ->remove_pending (job.get ());
378397 break ;
379398 case job_state_kind_t ::ALLOC_RUNNING:
380399 m_alloced.erase (job->t_stamps .running_ts );
@@ -593,7 +612,7 @@ int queue_policy_base_impl_t::pending_reprioritize (flux_jobid_t id,
593612 }
594613 } else {
595614 bool found_in_prov = false ;
596- if (erase_pending_job (job, found_in_prov) < 0 )
615+ if (erase_pending_job (job. get () , found_in_prov) < 0 )
597616 return -1 ;
598617 job->priority = priority;
599618 if (insert_pending_job (job, found_in_prov) < 0 )
@@ -614,7 +633,7 @@ int queue_policy_base_impl_t::process_provisional_cancel ()
614633 auto job = m_jobs[id];
615634 if (job->state == job_state_kind_t ::PENDING) {
616635 bool found_in_provisional = false ;
617- if (erase_pending_job (job, found_in_provisional) < 0 )
636+ if (erase_pending_job (job. get () , found_in_provisional) < 0 )
618637 return -1 ;
619638 job->state = job_state_kind_t ::CANCELED;
620639 auto res = m_canceled.insert (
@@ -644,7 +663,7 @@ int queue_policy_base_impl_t::process_provisional_reprio ()
644663 auto job = m_jobs[id];
645664 if (job->state == job_state_kind_t ::PENDING) {
646665 bool found_in_provisional = false ;
647- if (erase_pending_job (job, found_in_provisional) < 0 )
666+ if (erase_pending_job (job. get () , found_in_provisional) < 0 )
648667 return -1 ;
649668 job->priority = priority;
650669 if (insert_pending_job (job, found_in_provisional) < 0 )
@@ -685,7 +704,7 @@ int queue_policy_base_impl_t::insert_pending_job (std::shared_ptr<job_t> &job,
685704 return 0 ;
686705}
687706
688- int queue_policy_base_impl_t::erase_pending_job (std::shared_ptr< job_t > & job,
707+ int queue_policy_base_impl_t::erase_pending_job (job_t * job,
689708 bool &found_in_prov)
690709{
691710 size_t s;
0 commit comments