X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b4f85f65a07e02d710ad32edeb86a1c5ea76d475..29ad3b7333681e4e7b712da3a2c0244b23afa095:/services/api/app/models/container.rb diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb index d897ff7af9..d2e76f74e3 100644 --- a/services/api/app/models/container.rb +++ b/services/api/app/models/container.rb @@ -343,7 +343,7 @@ class Container < ArvadosModel # Check for non-failing Running candidates and return the most likely to finish sooner. log_reuse_info { "checking for state=Running..." } running = candidates.where(state: Running). - where("(runtime_status->'error') is null"). + where("(runtime_status->'error') is null and priority > 0"). order('progress desc, started_at asc'). limit(1).first if running @@ -357,10 +357,15 @@ class Container < ArvadosModel locked_or_queued = candidates. where("state IN (?)", [Locked, Queued]). order('state asc, priority desc, created_at asc'). - limit(1).first - if locked_or_queued - log_reuse_info { "done, reusing container #{locked_or_queued.uuid} with state=#{locked_or_queued.state}" } - return locked_or_queued + limit(1) + if !attrs[:scheduling_parameters]['preemptible'] + locked_or_queued = locked_or_queued. + where("not ((scheduling_parameters::jsonb)->>'preemptible')::boolean") + end + chosen = locked_or_queued.first + if chosen + log_reuse_info { "done, reusing container #{chosen.uuid} with state=#{chosen.state}" } + return chosen else log_reuse_info { "have no containers in Locked or Queued state" } end @@ -730,7 +735,22 @@ class Container < ArvadosModel self.with_lock do act_as_system_user do if self.state == Cancelled - retryable_requests = ContainerRequest.where("container_uuid = ? and priority > 0 and state = 'Committed' and container_count < container_count_max", uuid) + # Cancelled means the container didn't run to completion. + # This happens either because it was cancelled by the user + # or because there was an infrastructure failure. We want + # to retry infrastructure failures automatically. + # + # Seach for live container requests to determine if we + # should retry the container. + retryable_requests = ContainerRequest. + joins('left outer join containers as requesting_container on container_requests.requesting_container_uuid = requesting_container.uuid'). + where("container_requests.container_uuid = ? and "+ + "container_requests.priority > 0 and "+ + "container_requests.owner_uuid not in (select group_uuid from trashed_groups) and "+ + "(requesting_container.priority is null or (requesting_container.state = 'Running' and requesting_container.priority > 0)) and "+ + "container_requests.state = 'Committed' and "+ + "container_requests.container_count < container_requests.container_count_max", uuid). + order('container_requests.uuid asc') else retryable_requests = [] end