X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/53ce9b61336c5385eb2250267efa69613b5eaec7..0eedf70afa34167275d2135837e866b13fac4178:/services/api/app/models/container.rb diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb index 3765266405..7ec9845bc1 100644 --- a/services/api/app/models/container.rb +++ b/services/api/app/models/container.rb @@ -5,8 +5,10 @@ require 'log_reuse_info' require 'whitelist_update' require 'safe_json' +require 'update_priority' class Container < ArvadosModel + include ArvadosModelUpdates include HasUuid include KindAndEtag include CommonApiTemplate @@ -36,6 +38,7 @@ class Container < ArvadosModel before_save :scrub_secret_mounts after_save :handle_completed after_save :propagate_priority + after_commit { UpdatePriority.run_update_thread } has_many :container_requests, :foreign_key => :container_uuid, :class_name => 'ContainerRequest', :primary_key => :uuid belongs_to :auth, :class_name => 'ApiClientAuthorization', :foreign_key => :auth_uuid, :primary_key => :uuid @@ -314,11 +317,7 @@ class Container < ArvadosModel # (because state might have changed while acquiring the lock). check_lock_fail transaction do - begin - reload(lock: 'FOR UPDATE NOWAIT') - rescue - raise LockFailedError.new("cannot lock: other transaction in progress") - end + reload check_lock_fail update_attributes!(state: Locked) end @@ -560,9 +559,11 @@ class Container < ArvadosModel c = Container.create! c_attrs retryable_requests.each do |cr| cr.with_lock do - # Use row locking because this increments container_count - cr.container_uuid = c.uuid - cr.save! + leave_modified_by_user_alone do + # Use row locking because this increments container_count + cr.container_uuid = c.uuid + cr.save! + end end end end @@ -570,7 +571,9 @@ class Container < ArvadosModel # Notify container requests associated with this container ContainerRequest.where(container_uuid: uuid, state: ContainerRequest::Committed).each do |cr| - cr.finalize! + leave_modified_by_user_alone do + cr.finalize! + end end # Cancel outstanding container requests made by this container. @@ -578,19 +581,20 @@ class Container < ArvadosModel includes(:container). where(requesting_container_uuid: uuid, state: ContainerRequest::Committed).each do |cr| - cr.update_attributes!(priority: 0) - cr.container.reload - if cr.container.state == Container::Queued || cr.container.state == Container::Locked - # If the child container hasn't started yet, finalize the - # child CR now instead of leaving it "on hold", i.e., - # Queued with priority 0. (OTOH, if the child is already - # running, leave it alone so it can get cancelled the - # usual way, get a copy of the log collection, etc.) - cr.update_attributes!(state: ContainerRequest::Final) + leave_modified_by_user_alone do + cr.update_attributes!(priority: 0) + cr.container.reload + if cr.container.state == Container::Queued || cr.container.state == Container::Locked + # If the child container hasn't started yet, finalize the + # child CR now instead of leaving it "on hold", i.e., + # Queued with priority 0. (OTOH, if the child is already + # running, leave it alone so it can get cancelled the + # usual way, get a copy of the log collection, etc.) + cr.update_attributes!(state: ContainerRequest::Final) + end end end end end end - end